From f94b84bde340739647ffe7dd92cfcefb6686eca2 Mon Sep 17 00:00:00 2001 From: bptato Date: Thu, 18 Jul 2024 18:22:15 +0200 Subject: html: event cleanup, XHR progress --- src/utils/twtstr.nim | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/utils/twtstr.nim') diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index 3744d9e2..a4345251 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -612,6 +612,33 @@ proc getContentTypeAttr*(contentType, attrname: string): string = s &= c return s +proc setContentTypeAttr*(contentType: var string; attrname, value: string) = + var i = contentType.find(';') + if i == -1: + contentType &= ';' & attrname & '=' & value + return + i = contentType.find(attrname, i) + if i == -1: + contentType &= ';' & attrname & '=' & value + return + i = contentType.skipBlanks(i + attrname.len) + if i >= contentType.len or contentType[i] != '=': + contentType &= ';' & attrname & '=' & value + return + i = contentType.skipBlanks(i + 1) + var q = false + var j = i + while j < contentType.len: + let c = contentType[j] + if q: + q = false + elif c == '\\': + q = true + elif c in AsciiWhitespace + {';'}: + break + inc j + contentType[i..