Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

Side by Side Diff: src/pkg/bytes/bytes.go

Issue 160200044: [dev.power64] code review 160200044: build: merge default into dev.power64 (Closed)
Patch Set: diff -r be0c14f62257b42485019e9e1db23cf40d2e249f https://code.google.com/p/go Created 10 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/archive/zip/writer_test.go ('k') | src/pkg/compress/bzip2/bzip2_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Package bytes implements functions for the manipulation of byte slices. 5 // Package bytes implements functions for the manipulation of byte slices.
6 // It is analogous to the facilities of the strings package. 6 // It is 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 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 r, l := utf8.DecodeRune(s) 598 r, l := utf8.DecodeRune(s)
599 t[i] = r 599 t[i] = r
600 i++ 600 i++
601 s = s[l:] 601 s = s[l:]
602 } 602 }
603 return t 603 return t
604 } 604 }
605 605
606 // Replace returns a copy of the slice s with the first n 606 // Replace returns a copy of the slice s with the first n
607 // non-overlapping instances of old replaced by new. 607 // non-overlapping instances of old replaced by new.
608 // If old is empty, it matches at the beginning of the slice
609 // and after each UTF-8 sequence, yielding up to k+1 replacements
610 // for a k-rune slice.
608 // If n < 0, there is no limit on the number of replacements. 611 // If n < 0, there is no limit on the number of replacements.
609 func Replace(s, old, new []byte, n int) []byte { 612 func Replace(s, old, new []byte, n int) []byte {
610 m := 0 613 m := 0
611 if n != 0 { 614 if n != 0 {
612 // Compute number of replacements. 615 // Compute number of replacements.
613 m = Count(s, old) 616 m = Count(s, old)
614 } 617 }
615 if m == 0 { 618 if m == 0 {
616 // Just return a copy. 619 // Just return a copy.
617 return append([]byte(nil), s...) 620 return append([]byte(nil), s...)
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 } 692 }
690 if r == tr { 693 if r == tr {
691 continue 694 continue
692 } 695 }
693 return false 696 return false
694 } 697 }
695 698
696 // One string is empty. Are both? 699 // One string is empty. Are both?
697 return len(s) == len(t) 700 return len(s) == len(t)
698 } 701 }
OLDNEW
« no previous file with comments | « src/pkg/archive/zip/writer_test.go ('k') | src/pkg/compress/bzip2/bzip2_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b