about summary refs log tree commit diff stats
path: root/src/utils/twtstr.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-07-18 18:22:15 +0200
committerbptato <nincsnevem662@gmail.com>2024-07-18 18:22:56 +0200
commitf94b84bde340739647ffe7dd92cfcefb6686eca2 (patch)
tree6e4af17196945d39ff8a1f9ab5e3516f9c0a2514 /src/utils/twtstr.nim
parent01cb95c89fb53a936172412e6dd69b943bf73b4b (diff)
downloadchawan-f94b84bde340739647ffe7dd92cfcefb6686eca2.tar.gz
html: event cleanup, XHR progress
Diffstat (limited to 'src/utils/twtstr.nim')
-rw-r--r--src/utils/twtstr.nim27
1 files changed, 27 insertions, 0 deletions
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..<j] = value
+
 func atob(c: char): uint8 {.inline.} =
   # see RFC 4648 table
   if c in AsciiUpperAlpha: