validIdentifier checks if an identifier is valid without using regexp or unicode. Rules: - Components separated by '/' - Each component is non-empty - Only characters A-Z, a-z, 0-9, '.', '_', '-' or ':' - No leading, trailing, or double slashes
(s string)
| 34 | // - Only characters A-Z, a-z, 0-9, '.', '_', '-' or ':' |
| 35 | // - No leading, trailing, or double slashes |
| 36 | func validIdentifier(s string) bool { |
| 37 | if len(s) == 0 { |
| 38 | return false |
| 39 | } |
| 40 | |
| 41 | componentLen := 0 |
| 42 | |
| 43 | for _, r := range s { |
| 44 | switch { |
| 45 | case r == '/': |
| 46 | if componentLen == 0 { |
| 47 | // Empty component (leading, trailing, or double slash) |
| 48 | return false |
| 49 | } |
| 50 | componentLen = 0 |
| 51 | case isValidRune(r): |
| 52 | componentLen++ |
| 53 | default: |
| 54 | return false |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | // Final component must not be empty |
| 59 | return componentLen > 0 |
| 60 | } |
| 61 | |
| 62 | func isValidRune(c rune) bool { |
| 63 | return (c >= 'A' && c <= 'Z') || |