diff options
author | bptato <nincsnevem662@gmail.com> | 2023-12-12 19:42:04 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-12-12 19:42:04 +0100 |
commit | 820f0f0f039252533133c3bd1037a73036815a45 (patch) | |
tree | 305dd3cd0416123c27701c199164fa54e822a7fb /src/utils | |
parent | 5efdc54db2d2c766d7ce7c6545207ce2ce805620 (diff) | |
download | chawan-820f0f0f039252533133c3bd1037a73036815a45.tar.gz |
twtstr: import functions from gopher2html
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/twtstr.nim | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index 13a432bf..c5078568 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -222,7 +222,8 @@ func until*(s: string, c: set[char], starti = 0): string = break result.add(s[i]) -func until*(s: string, c: char): string = s.until({c}) +func until*(s: string, c: char, starti = 0): string = + s.until({c}, starti) func after*(s: string, c: set[char]): string = var i = 0 @@ -557,21 +558,15 @@ func percentDecode*(input: string, si = 0): string = inc i func htmlEscape*(s: string): string = - var res = "" + result = "" for c in s: - if c == '<': - res &= "<" - elif c == '>': - res &= ">" - elif c == '&': - res &= "&" - elif c == '"': - res &= """ - elif c == '\'': - res &= "'" - else: - res &= c - return res + case c + of '<': result &= "<" + of '>': result &= ">" + of '&': result &= "&" + of '"': result &= """ + of '\'': result &= "'" + else: result &= c func dqEscape*(s: string): string = result = newStringOfCap(s.len) |