about summary refs log tree commit diff stats
path: root/src/utils
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-11-15 23:42:20 +0100
committerbptato <nincsnevem662@gmail.com>2022-11-19 14:32:54 +0100
commita6bbcd0dd3f77b0e98527c1fa9e510a40acd954e (patch)
treeca55cc9079afbe788a61986e42d1a8d9d0bc7c2f /src/utils
parente75f62b34f7c7f3127bcde0c4a12cbb785342dd9 (diff)
downloadchawan-a6bbcd0dd3f77b0e98527c1fa9e510a40acd954e.tar.gz
Rewrite buffer/pager for multi-processing
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/twtstr.nim20
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())