mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
An asked-for-in #go-nuts extension to quickly create a repeated
copy of a string or a byte array.
strings.Repeat("-", 50)
bytes.Repeat(b, 99)
R=rsc
https://golang.org/cl/155063
This commit is contained in:
parent
11c1aa9f6d
commit
37f71e8ad6
4 changed files with 79 additions and 0 deletions
|
|
@ -239,6 +239,19 @@ func Map(mapping func(rune int) int, s []byte) []byte {
|
|||
return b[0:nbytes];
|
||||
}
|
||||
|
||||
// Repeat returns a new byte array consisting of count copies of b.
|
||||
func Repeat(b []byte, count int) []byte {
|
||||
nb := make([]byte, len(b)*count);
|
||||
bp := 0;
|
||||
for i := 0; i < count; i++ {
|
||||
for j := 0; j < len(b); j++ {
|
||||
nb[bp] = b[j];
|
||||
bp++;
|
||||
}
|
||||
}
|
||||
return nb;
|
||||
}
|
||||
|
||||
// ToUpper returns a copy of the byte array s with all Unicode letters mapped to their upper case.
|
||||
func ToUpper(s []byte) []byte { return Map(unicode.ToUpper, s) }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue