about summary refs log tree commit diff stats
path: root/src/config/mimetypes.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-01-27 01:38:23 +0100
committerbptato <nincsnevem662@gmail.com>2024-01-27 01:43:39 +0100
commitfb2f0b91ae59612495143982212f3def20d3bf68 (patch)
treeaa9cc8466b008237cad1e1d2d62a3702c93d989c /src/config/mimetypes.nim
parent1c0df44ae9d9ac498ff6335f044ff5294fd62441 (diff)
downloadchawan-fb2f0b91ae59612495143982212f3def20d3bf68.tar.gz
mimetypes: simplify parseMimeTypes
* use functions like until
* do not call atEnd for every line, use boolean readLine instead
Diffstat (limited to 'src/config/mimetypes.nim')
-rw-r--r--src/config/mimetypes.nim25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/config/mimetypes.nim b/src/config/mimetypes.nim
index a7c18a57..542bc267 100644
--- a/src/config/mimetypes.nim
+++ b/src/config/mimetypes.nim
@@ -1,5 +1,4 @@
 import std/streams
-import std/strutils
 import std/tables
 
 import utils/twtstr
@@ -10,27 +9,21 @@ type MimeTypes* = Table[string, string]
 # Add mime types found in stream to mimeTypes.
 # No error handling for now.
 proc parseMimeTypes*(mimeTypes: var MimeTypes, stream: Stream) =
-  while not stream.atEnd():
-    let line = stream.readLine()
+  var line: string
+  while stream.readLine(line):
     if line.len == 0:
       continue
     if line[0] == '#':
       continue
-    var t = ""
-    var i = 0
-    while i < line.len and line[i] notin AsciiWhitespace:
-      t &= line[i].toLowerAscii()
-      inc i
+    let t = line.untilLower(AsciiWhitespace)
     if t == "": continue
+    var i = t.len
     while i < line.len:
-      while i < line.len and line[i] in AsciiWhitespace:
-        inc i
-      var ext = ""
-      while i < line.len and line[i] notin AsciiWhitespace:
-        ext &= line[i].toLowerAscii()
-        inc i
-      if ext == "": continue
-      discard mimeTypes.hasKeyOrPut(ext, t)
+      i = line.skipBlanks(i)
+      let ext = line.untilLower(AsciiWhitespace, i)
+      i += ext.len
+      if ext != "":
+        discard mimeTypes.hasKeyOrPut(ext, t)
   stream.close()
 
 proc parseMimeTypes*(stream: Stream): MimeTypes =