IsSentenceCase reports whether s is in Sentence case format. Sentence case: first rune is uppercase; every subsequent letter is lowercase. Digits and punctuation are allowed anywhere. Examples: "My feature", "Add endpoint", "Fix #123".
(s string)
| 108 | // Digits and punctuation are allowed anywhere. |
| 109 | // Examples: "My feature", "Add endpoint", "Fix #123". |
| 110 | func IsSentenceCase(s string) bool { |
| 111 | if s == "" { |
| 112 | return true |
| 113 | } |
| 114 | runes := []rune(s) |
| 115 | if !unicode.IsUpper(runes[0]) { |
| 116 | return false |
| 117 | } |
| 118 | for _, r := range runes[1:] { |
| 119 | if unicode.IsLetter(r) && unicode.IsUpper(r) { |
| 120 | return false |
| 121 | } |
| 122 | } |
| 123 | return true |
| 124 | } |
| 125 | |
| 126 | // IsSnakeCase reports whether s is in snake_case format. |
| 127 | // snake_case: only lowercase letters, digits, and underscores. |
no outgoing calls