about summary refs log tree commit diff stats
path: root/archive/0.vm.arc/vimrc.vim
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-08-22 10:15:14 -0700
committerKartik Agaram <vc@akkartik.com>2020-08-22 10:15:14 -0700
commitdb541c3595d52e3ff26d2714b70834219047f256 (patch)
treea5364a23f5694ff42e549a81b365c2bdb6f4b411 /archive/0.vm.arc/vimrc.vim
parent66daf3cc1f479300cf3e58278a1167bd862d855a (diff)
downloadmu-db541c3595d52e3ff26d2714b70834219047f256.tar.gz
6721
Diffstat (limited to 'archive/0.vm.arc/vimrc.vim')
0 files changed, 0 insertions, 0 deletions
'alt'>
fb2f0b91 ^
d526deb9 ^
fb2f0b91 ^
d526deb9 ^
fb2f0b91 ^




d526deb9 ^





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
                  
                 



                   




                                                                          



                                                                

                              



                      
                                            
                        
                 
                       




                                                   





                                                 
import std/streams
import std/tables

import utils/twtstr

# extension -> type
type MimeTypes* = distinct Table[string, string]

proc `[]`*(mimeTypes: MimeTypes; k: string): string {.borrow.}
proc contains*(mimeTypes: MimeTypes; k: string): bool {.borrow.}
proc hasKeyOrPut*(mimeTypes: var MimeTypes; k, v: string): bool {.borrow.}

# Add mime types found in stream to mimeTypes.
# No error handling for now.
proc parseMimeTypes*(mimeTypes: var MimeTypes, stream: Stream) =
  var line: string
  while stream.readLine(line):
    if line.len == 0:
      continue
    if line[0] == '#':
      continue
    let t = line.untilLower(AsciiWhitespace)
    if t == "": continue
    var i = t.len
    while i < line.len:
      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 =
  var mimeTypes: MimeTypes
  mimeTypes.parseMimeTypes(stream)
  return mimeTypes