quoteSegmentIfNeeded wraps name in TOML quotes when it would not be a bare key (e.g. contains a hyphen or slash).
(name string)
| 48 | // quoteSegmentIfNeeded wraps name in TOML quotes when it would not be a |
| 49 | // bare key (e.g. contains a hyphen or slash). |
| 50 | func quoteSegmentIfNeeded(name string) string { |
| 51 | for _, ch := range name { |
| 52 | isAlnum := (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || ch == '_' |
| 53 | if !isAlnum { |
| 54 | return `"` + name + `"` |
| 55 | } |
| 56 | } |
| 57 | return name |
| 58 | } |