diff options
Diffstat (limited to 'src/utils/twtstr.nim')
-rw-r--r-- | src/utils/twtstr.nim | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index 3132510e..3636da14 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -125,6 +125,16 @@ func toHeaderCase*(str: string): string = result[i] = result[i].toUpperAscii() flip = result[i] == '-' +func toScreamingSnakeCase*(str: string): string = # input is camel case + if str.len >= 1: result &= str[0].toUpperAscii() + for c in str[1..^1]: + if c in AsciiUpperAlpha: + result &= '_' + result &= c + else: + result &= c.toUpperAscii() + + func startsWithNoCase*(str, prefix: string): bool = if str.len < prefix.len: return false # prefix.len is always lower @@ -899,6 +909,16 @@ func width*(s: seq[Rune], min: int): int = func breaksWord*(r: Rune): bool = return not (r.isDigitAscii() or r.width() == 0 or r.isAlpha()) +type BoundaryFunction* = proc(x: Rune): Option[bool] + +proc breaksWord*(r: Rune, check: Option[BoundaryFunction]): bool = + if check.isSome: + let f = check.get() + let v = f(r) + if v.isSome: #TODO report error? + return v.get() + return r.breaksWord() + func padToWidth*(str: string, size: int, schar = '$'): string = if str.width() < size: return str & ' '.repeat(size - str.width()) |