Save some alloc on base64 using encodeSize (#16465)
This commit is contained in:
parent
689504081f
commit
0c8ce2dccf
1 changed files with 1 additions and 0 deletions
|
|
@ -193,6 +193,7 @@ proc encodeMime*(s: string, lineLen = 75, newLine = "\r\n"): string =
|
||||||
## * `decode proc<#decode,string>`_ for decoding a string
|
## * `decode proc<#decode,string>`_ for decoding a string
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
assert encodeMime("Hello World", 4, "\n") == "SGVs\nbG8g\nV29y\nbGQ="
|
assert encodeMime("Hello World", 4, "\n") == "SGVs\nbG8g\nV29y\nbGQ="
|
||||||
|
result = newStringOfCap(encodeSize(s.len))
|
||||||
for i, c in encode(s):
|
for i, c in encode(s):
|
||||||
if i != 0 and (i mod lineLen == 0):
|
if i != 0 and (i mod lineLen == 0):
|
||||||
result.add(newLine)
|
result.add(newLine)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue