diff options
author | bptato <nincsnevem662@gmail.com> | 2024-10-08 00:59:08 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-10-08 01:10:17 +0200 |
commit | 3a722a4b6f87a8c73992d553a829fb5e5e2af5e4 (patch) | |
tree | 1291d3d1cc3cd4d620ad7fc2b2b9274f966c066a /src/utils | |
parent | 357f13930ca613fa88d8493e52249dc7be586b48 (diff) | |
download | chawan-3a722a4b6f87a8c73992d553a829fb5e5e2af5e4.tar.gz |
twtstr: fix stripAndCollapse
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/twtstr.nim | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index a83dfeef..e5dab87a 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -130,19 +130,17 @@ func skipBlanks*(buf: openArray[char]; at: int): int = while result < buf.len and buf[result] in AsciiWhitespace: inc result -func stripAndCollapse*(s: string): string = +func stripAndCollapse*(s: openArray[char]): string = + var res = newStringOfCap(s.len) var space = false - result = "" - for i in s.skipBlanks(0) ..< s.len: - if s[i] notin AsciiWhitespace: + for c in s.toOpenArray(s.skipBlanks(0), s.high): + let cspace = c in AsciiWhitespace + if not cspace: if space: - result &= ' ' - space = false - result &= s[i] - elif not space: - space = true - else: - result &= ' ' + res &= ' ' + res &= c + space = cspace + return res func until*(s: openArray[char]; c: set[char]; starti = 0): string = result = "" |