diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-15 19:08:58 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-15 19:08:58 +0100 |
commit | a03e810d61bb165dc7f9434fc42484e61620c4c5 (patch) | |
tree | 1c95bbfcfa5706039c23e3d0b1db405bbbca9fa0 /src/utils | |
parent | 981353831d81ae7c91e67ebce1f39b144a1f9f0f (diff) | |
download | chawan-a03e810d61bb165dc7f9434fc42484e61620c4c5.tar.gz |
makeCRLF: move to twtstr, write last char
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/twtstr.nim | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index 1afe54d9..9a70539a 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -902,3 +902,26 @@ func padToWidth*(str: string, size: int, schar = '$'): string = result &= r w += r.width result &= schar + +#https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart/form-data-encoding-algorithm +proc makeCRLF*(s: string): string = + result = newStringOfCap(s.len) + var i = 0 + while i < s.len - 1: + if s[i] == '\r' and s[i + 1] != '\n': + result &= '\r' + result &= '\n' + elif s[i] != '\r' and s[i + 1] == '\n': + result &= s[i] + result &= '\r' + result &= '\n' + inc i + else: + result &= s[i] + inc i + if i < s.len: + if s[i] == '\r': + result &= '\r' + result &= '\n' + else: + result &= s[i] |