aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-07-11 22:02:15 +0200
committerbptato <nincsnevem662@gmail.com>2022-07-11 22:31:43 +0200
commit1abd3aadf0c999c6e26ba4e7910b5abe3510c6c2 (patch)
tree537e938a4a5a12a69d148c83c5e279e46a73b8b4 /src/utils
parent62cba694e47a7a1f4bedc7fd48ceac9c26aa3aa1 (diff)
downloadchawan-1abd3aadf0c999c6e26ba4e7910b5abe3510c6c2.tar.gz
Fix and clean up some dom-based features
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/twtstr.nim17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index a484d3dd..3081183b 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -203,6 +203,23 @@ func substr*(s: seq[Rune], i: int): seq[Rune] =
return @[]
return s[min(high(s), i)..high(s)]
+func stripAndCollapse*(s: string): string =
+ var i = 0
+ while i < s.len and s[i] in AsciiWhitespace:
+ inc i
+ var space = false
+ while i < s.len:
+ if s[i] notin AsciiWhitespace:
+ if space:
+ result &= ' '
+ space = false
+ result &= s[i]
+ elif not space:
+ space = true
+ else:
+ result &= ' '
+ inc i
+
func skipBlanks*(buf: string, at: int): int =
result = at
while result < buf.len and buf[result].isWhitespace():