123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package xvdoc
- import (
- "encoding/json"
- "fmt"
- )
- type ObjConstructor func(JSONMap) (Cell, error)
- var (
- objConstructors = map[string]ObjConstructor{
- "formula": constructorFormula,
- }
- )
- func constructorObject(dec *json.Decoder, t json.Token) (res Cell, err error) {
- m := make(JSONMap)
- if _, check := t.(json.Delim); check && t == json.Delim('{') {
- for err == nil {
- if t, err = dec.Token(); err == nil {
- if _, check := t.(json.Delim); check {
- if t == json.Delim('}') {
- if constructor, check := objConstructors[m.StringVal("type", "")]; check {
- res, err = constructor(m)
- } else {
- res = &CellObj{
- value: m.Interface("value"),
- styles: m.StringArray("styles"),
- }
- }
- return
- }
- } else {
- var i interface{}
- if err = dec.Decode(&i); err == nil {
- m[t.(string)] = i
- }
- }
- }
- }
- }
- return
- }
- ////////////////////////////////////////////
- type CellObj struct {
- value interface{}
- styles []string
- }
- func (s *CellObj) Val() interface{} {
- return s.value
- }
- func (s *CellObj) Type() string {
- return ""
- }
- func (s *CellObj) String() string {
- return fmt.Sprintf("{ value :: %v }", s.value)
- }
- func (s *CellObj) Styles() (res []string) {
- return s.styles
- }
|