File: iso_date.go

package info (click to toggle)
mongo-tools 3.2.11-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 10,612 kB
  • ctags: 10,571
  • sloc: python: 5,428; ansic: 589; sh: 397; makefile: 62; lisp: 19
file content (45 lines) | stat: -rw-r--r-- 1,156 bytes parent folder | download | duplicates (2)
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
37
38
39
40
41
42
43
44
45
package json

import (
    "fmt"
    "reflect"
)

// Transition functions for recognizing ISODate.
// Adapted from encoding/json/scanner.go.

// stateIS is the state after reading `IS`.
func stateIS(s *scanner, c int) int {
    if c == 'O' {
        s.step = stateISO
        return scanContinue
    }
    return s.error(c, "in literal ISODate (expecting 'O')")
}

// stateISO is the state after reading `ISO`.
func stateISO(s *scanner, c int) int {
    if c == 'D' {
        s.step = stateD
        return scanContinue
    }
    return s.error(c, "in literal ISODate (expecting 'D')")
}

// Decodes a ISODate literal stored in the underlying byte data into v.
func (d *decodeState) storeISODate(v reflect.Value) {
    op := d.scanWhile(scanSkipSpace)
    if op != scanBeginCtor {
        d.error(fmt.Errorf("expected beginning of constructor"))
    }
    args, err := d.ctor("ISODate", []reflect.Type{isoDateType})
    if err != nil {
        d.error(err)
    }
    switch kind := v.Kind(); kind {
    case reflect.Interface:
        v.Set(args[0])
    default:
        d.error(fmt.Errorf("cannot store %v value into %v type", isoDateType, kind))
    }
}