utils_letter.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Package mhayaUtils file from https://github.com/gogf/gf
  2. package mhayaUtils
  3. // IsLetterUpper checks whether the given byte b is in upper case.
  4. func IsLetterUpper(b byte) bool {
  5. if b >= byte('A') && b <= byte('Z') {
  6. return true
  7. }
  8. return false
  9. }
  10. // IsLetterLower checks whether the given byte b is in lower case.
  11. func IsLetterLower(b byte) bool {
  12. if b >= byte('a') && b <= byte('z') {
  13. return true
  14. }
  15. return false
  16. }
  17. // IsLetter checks whether the given byte b is a letter.
  18. func IsLetter(b byte) bool {
  19. return IsLetterUpper(b) || IsLetterLower(b)
  20. }
  21. // IsNumeric checks whether the given string s is numeric.
  22. // Note that float string like "123.456" is also numeric.
  23. func IsNumeric(s string) bool {
  24. length := len(s)
  25. if length == 0 {
  26. return false
  27. }
  28. for i := 0; i < len(s); i++ {
  29. if s[i] == '-' && i == 0 {
  30. continue
  31. }
  32. if s[i] == '.' {
  33. if i > 0 && i < len(s)-1 {
  34. continue
  35. } else {
  36. return false
  37. }
  38. }
  39. if s[i] < '0' || s[i] > '9' {
  40. return false
  41. }
  42. }
  43. return true
  44. }
  45. // UcFirst returns a copy of the string s with the first letter mapped to its upper case.
  46. func UcFirst(s string) string {
  47. if len(s) == 0 {
  48. return s
  49. }
  50. if IsLetterLower(s[0]) {
  51. return string(s[0]-32) + s[1:]
  52. }
  53. return s
  54. }