summary refs log tree commit diff stats
path: root/lib/pure/cookies.nim
blob: 8e5de008c0fd3616619bdf809a357270fcf8a9f9 (plain) (blame)
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
#
#
#            Nimrod's Runtime Library
#        (c) Copyright 2011 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

## This module implements helper procs for parsing Cookies.

import strtabs

proc parseCookies*(s: string): PStringTable = 
  ## parses cookies into a string table.
  result = newStringTable(modeCaseInsensitive)
  var i = 0
  while true:
    while s[i] == ' ' or s[i] == '\t': inc(i)
    var keystart = i
    while s[i] != '=' and s[i] != '\0': inc(i)
    var keyend = i-1
    if s[i] == '\0': break
    inc(i) # skip '='
    var valstart = i
    while s[i] != ';' and s[i] != '\0': inc(i)
    result[substr(s, keystart, keyend)] = substr(s, valstart, i-1)
    if s[i] == '\0': break
    inc(i) # skip ';'