LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // The bytes package implements functions for the manipulation of byte slices. | 5 // The bytes package implements functions for the manipulation of byte slices. |
6 // Analogous to the facilities of the strings package. | 6 // Analogous to the facilities of the strings package. |
7 package bytes | 7 package bytes |
8 | 8 |
9 import ( | 9 import ( |
10 "unicode" | 10 "unicode" |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 func TrimRight(s []byte, cutset string) []byte { | 545 func TrimRight(s []byte, cutset string) []byte { |
546 return TrimRightFunc(s, makeCutsetFunc(cutset)) | 546 return TrimRightFunc(s, makeCutsetFunc(cutset)) |
547 } | 547 } |
548 | 548 |
549 // TrimSpace returns a subslice of s by slicing off all leading and | 549 // TrimSpace returns a subslice of s by slicing off all leading and |
550 // trailing white space, as as defined by Unicode. | 550 // trailing white space, as as defined by Unicode. |
551 func TrimSpace(s []byte) []byte { | 551 func TrimSpace(s []byte) []byte { |
552 return TrimFunc(s, unicode.IsSpace) | 552 return TrimFunc(s, unicode.IsSpace) |
553 } | 553 } |
554 | 554 |
555 // Add appends the contents of t to the end of s and returns the result. | |
556 // If s has enough capacity, it is extended in place; otherwise a | |
557 // new array is allocated and returned. | |
558 func Add(s, t []byte) []byte { // TODO | |
559 return append(s, t...) | |
560 } | |
561 | |
562 // AddByte appends byte t to the end of s and returns the result. | |
563 // If s has enough capacity, it is extended in place; otherwise a | |
564 // new array is allocated and returned. | |
565 func AddByte(s []byte, t byte) []byte { // TODO | |
566 return append(s, t) | |
567 } | |
568 | |
569 // Runes returns a slice of runes (Unicode code points) equivalent to s. | 555 // Runes returns a slice of runes (Unicode code points) equivalent to s. |
570 func Runes(s []byte) []int { | 556 func Runes(s []byte) []int { |
571 t := make([]int, utf8.RuneCount(s)) | 557 t := make([]int, utf8.RuneCount(s)) |
572 i := 0 | 558 i := 0 |
573 for len(s) > 0 { | 559 for len(s) > 0 { |
574 r, l := utf8.DecodeRune(s) | 560 r, l := utf8.DecodeRune(s) |
575 t[i] = r | 561 t[i] = r |
576 i++ | 562 i++ |
577 s = s[l:] | 563 s = s[l:] |
578 } | 564 } |
(...skipping 28 matching lines...) Expand all Loading... |
607 } else { | 593 } else { |
608 j += Index(s[start:], old) | 594 j += Index(s[start:], old) |
609 } | 595 } |
610 w += copy(t[w:], s[start:j]) | 596 w += copy(t[w:], s[start:j]) |
611 w += copy(t[w:], new) | 597 w += copy(t[w:], new) |
612 start = j + len(old) | 598 start = j + len(old) |
613 } | 599 } |
614 w += copy(t[w:], s[start:]) | 600 w += copy(t[w:], s[start:]) |
615 return t[0:w] | 601 return t[0:w] |
616 } | 602 } |
LEFT | RIGHT |