package xvdoc import ( "encoding/json" "fmt" "reflect" "strings" ) func constructorNumber(dec *json.Decoder, t json.Token) (res Cell, err error) { if _, check := t.(float64); check { var ( lInt int64 lFloat float64 ) lIntType, lFloatType := reflect.TypeOf(lInt), reflect.TypeOf(lFloat) rVal := reflect.ValueOf(t) if rVal.Type().ConvertibleTo(lIntType) && strings.IndexByte(fmt.Sprint(t), '.') < 0 { res = &CellInteger{rVal.Convert(lIntType).Int()} } else if rVal.Type().ConvertibleTo(lFloatType) { res = &CellFloat{rVal.Convert(lFloatType).Float()} } } return } // CellInteger is cell with integer type value type CellInteger struct { val int64 } // Val method is value getter func (s *CellInteger) Val() interface{} { return s.val } // Type method is value type getter func (s *CellInteger) Type() string { return "number" } func (s *CellInteger) String() string { return fmt.Sprintf("{ int64: %v }", s.val) } func (s *CellInteger) Styles() []string { return nil } ////////////////////////////////// type CellFloat struct { val float64 } func (s *CellFloat) Val() interface{} { return s.val } func (s *CellFloat) Type() string { return "float" } func (s *CellFloat) String() string { return fmt.Sprintf("{ float64: %v }", s.val) } func (s *CellFloat) Styles() []string { return nil }