From 1abd3aadf0c999c6e26ba4e7910b5abe3510c6c2 Mon Sep 17 00:00:00 2001 From: bptato Date: Mon, 11 Jul 2022 22:02:15 +0200 Subject: Fix and clean up some dom-based features --- src/utils/twtstr.nim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/utils') 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(): -- cgit 1.4.1-2-gfad0