diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/twtstr.nim | 17 |
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(): |