diff options
author | bptato <nincsnevem662@gmail.com> | 2023-12-01 21:25:09 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-12-01 21:29:29 +0100 |
commit | b7482b23c98ecd9bf60309fe9c06b5539595d492 (patch) | |
tree | 640aeaf8a3a39a9a6fded2a466592134fd839c97 /src/utils/twtstr.nim | |
parent | 90c74ddcab6713f9bb2dfea53a30951cc2e06f88 (diff) | |
download | chawan-b7482b23c98ecd9bf60309fe9c06b5539595d492.tar.gz |
html: add HTMLElement.dataset (+ some twtstr cleanup)
Diffstat (limited to 'src/utils/twtstr.nim')
-rw-r--r-- | src/utils/twtstr.nim | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index 2756f2de..8372e588 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -67,17 +67,13 @@ const controlLetterMap = genControlLetterMap() func getControlLetter*(c: char): char = return controlLetterMap[int(c)] -proc mtoLowerAscii*(str: var string) = - for i in 0 ..< str.len: - str[i] = str[i].toLowerAscii() - func toHeaderCase*(str: string): string = result = str var flip = true - for i in 0..str.high: + for c in result.mitems: if flip: - result[i] = result[i].toUpperAscii() - flip = result[i] == '-' + c = c.toUpperAscii() + flip = c == '-' func toScreamingSnakeCase*(str: string): string = # input is camel case if str.len >= 1: result &= str[0].toUpperAscii() @@ -94,10 +90,22 @@ func snakeToKebabCase*(str: string): string = if c == '_': c = '-' -func normalizeLocale*(s: string): string = - for i in 0 ..< s.len: - if cast[uint8](s[i]) > 0x20 and s[i] != '_' and s[i] != '-': - result &= s[i].toLowerAscii() +func kebabToCamelCase*(s: string): string = + result = s + var flip = false + for c in result.mitems: + if flip: + c = c.toUpperAscii() + flip = c == '-' + +func camelToKebabCase*(s: string): string = + result = "" + for c in s: + if c in AsciiUpperAlpha: + result &= '-' + result &= c.toLowerAscii() + else: + result &= c func isAscii*(r: Rune): bool = return cast[uint32](r) < 128 |