Left: | ||
Right: |
OLD | NEW |
---|---|
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 // A package of simple functions to manipulate strings. | 5 // A package of simple functions to manipulate strings. |
6 package strings | 6 package strings |
7 | 7 |
8 import ( | 8 import ( |
9 "unicode" | 9 "unicode" |
10 "utf8" | 10 "utf8" |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 | 284 |
285 // ToUpper returns a copy of the string s with all Unicode letters mapped to the ir upper case. | 285 // ToUpper returns a copy of the string s with all Unicode letters mapped to the ir upper case. |
286 func ToUpper(s string) string { return Map(unicode.ToUpper, s) } | 286 func ToUpper(s string) string { return Map(unicode.ToUpper, s) } |
287 | 287 |
288 // ToLower returns a copy of the string s with all Unicode letters mapped to the ir lower case. | 288 // ToLower returns a copy of the string s with all Unicode letters mapped to the ir lower case. |
289 func ToLower(s string) string { return Map(unicode.ToLower, s) } | 289 func ToLower(s string) string { return Map(unicode.ToLower, s) } |
290 | 290 |
291 // ToTitle returns a copy of the string s with all Unicode letters mapped to the ir title case. | 291 // ToTitle returns a copy of the string s with all Unicode letters mapped to the ir title case. |
292 func ToTitle(s string) string { return Map(unicode.ToTitle, s) } | 292 func ToTitle(s string) string { return Map(unicode.ToTitle, s) } |
293 | 293 |
294 // ToUpperSpecial returns a copy of the string s with all Unicode letters mapped to their | |
295 // upper case, giving priority to the special casing rules. | |
296 func ToUpperSpecial(_case unicode.SpecialCase, s string) string { | |
297 return Map(func(r int) int { return _case.ToUpper(r) }, s) | |
298 } | |
299 | |
300 // ToLowerSpecial returns a copy of the string s with all Unicode letters mapped to their | |
301 // upper case, giving priority to the special casing rules. | |
rsc1
2010/03/31 00:39:31
s/upper/lower/
| |
302 func ToLowerSpecial(_case unicode.SpecialCase, s string) string { | |
303 return Map(func(r int) int { return _case.ToLower(r) }, s) | |
304 } | |
305 | |
306 // ToTitleSpecial returns a copy of the string s with all Unicode letters mapped to their | |
307 // upper case, giving priority to the special casing rules. | |
rsc1
2010/03/31 00:39:31
s/upper/title/
| |
308 func ToTitleSpecial(_case unicode.SpecialCase, s string) string { | |
309 return Map(func(r int) int { return _case.ToTitle(r) }, s) | |
310 } | |
311 | |
294 // Trim returns a slice of the string s, with all leading and trailing white spa ce | 312 // Trim returns a slice of the string s, with all leading and trailing white spa ce |
295 // removed, as defined by Unicode. | 313 // removed, as defined by Unicode. |
296 func TrimSpace(s string) string { | 314 func TrimSpace(s string) string { |
297 start, end := 0, len(s) | 315 start, end := 0, len(s) |
298 for start < end { | 316 for start < end { |
299 wid := 1 | 317 wid := 1 |
300 rune := int(s[start]) | 318 rune := int(s[start]) |
301 if rune >= utf8.RuneSelf { | 319 if rune >= utf8.RuneSelf { |
302 rune, wid = utf8.DecodeRuneInString(s[start:end]) | 320 rune, wid = utf8.DecodeRuneInString(s[start:end]) |
303 } | 321 } |
(...skipping 14 matching lines...) Expand all Loading... | |
318 } | 336 } |
319 rune, wid = utf8.DecodeRuneInString(s[end-wid : end]) | 337 rune, wid = utf8.DecodeRuneInString(s[end-wid : end]) |
320 } | 338 } |
321 if !unicode.IsSpace(rune) { | 339 if !unicode.IsSpace(rune) { |
322 break | 340 break |
323 } | 341 } |
324 end -= wid | 342 end -= wid |
325 } | 343 } |
326 return s[start:end] | 344 return s[start:end] |
327 } | 345 } |
OLD | NEW |