github.com/gogf/gf/v2@v2.7.4/text/gstr/gstr_upper_lower.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package gstr 8 9 import ( 10 "strings" 11 12 "github.com/gogf/gf/v2/internal/utils" 13 ) 14 15 // ToLower returns a copy of the string s with all Unicode letters mapped to their lower case. 16 func ToLower(s string) string { 17 return strings.ToLower(s) 18 } 19 20 // ToUpper returns a copy of the string s with all Unicode letters mapped to their upper case. 21 func ToUpper(s string) string { 22 return strings.ToUpper(s) 23 } 24 25 // UcFirst returns a copy of the string s with the first letter mapped to its upper case. 26 func UcFirst(s string) string { 27 return utils.UcFirst(s) 28 } 29 30 // LcFirst returns a copy of the string s with the first letter mapped to its lower case. 31 func LcFirst(s string) string { 32 if len(s) == 0 { 33 return s 34 } 35 if IsLetterUpper(s[0]) { 36 return string(s[0]+32) + s[1:] 37 } 38 return s 39 } 40 41 // UcWords uppercase the first character of each word in a string. 42 func UcWords(str string) string { 43 return strings.Title(str) 44 } 45 46 // IsLetterLower tests whether the given byte b is in lower case. 47 func IsLetterLower(b byte) bool { 48 return utils.IsLetterLower(b) 49 } 50 51 // IsLetterUpper tests whether the given byte b is in upper case. 52 func IsLetterUpper(b byte) bool { 53 return utils.IsLetterUpper(b) 54 }