Check returns true when s conforms to the given caseFormat constant. An empty string always returns true (treated as "not present"). Returns false for any unrecognised caseFormat value.
(s, caseFormat string)
| 28 | // An empty string always returns true (treated as "not present"). |
| 29 | // Returns false for any unrecognised caseFormat value. |
| 30 | func Check(s, caseFormat string) bool { |
| 31 | if s == "" { |
| 32 | return true |
| 33 | } |
| 34 | switch caseFormat { |
| 35 | case Lower: |
| 36 | return s == strings.ToLower(s) |
| 37 | case Upper: |
| 38 | return s == strings.ToUpper(s) |
| 39 | case Camel: |
| 40 | return IsCamelCase(s) |
| 41 | case Kebab: |
| 42 | return IsKebabCase(s) |
| 43 | case Pascal: |
| 44 | return IsPascalCase(s) |
| 45 | case Sentence: |
| 46 | return IsSentenceCase(s) |
| 47 | case Snake: |
| 48 | return IsSnakeCase(s) |
| 49 | case Start: |
| 50 | return IsStartCase(s) |
| 51 | default: |
| 52 | return false |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | // IsCamelCase reports whether s is in camelCase format. |
| 57 | // camelCase: starts with a lowercase letter and contains only letters and |