package xvdoc import ( "bytes" "encoding/json" "fmt" ) type Row struct { oy int x int y int offsetY bool offsetX bool cells []Cell style string styles []string height float64 } func (s *Row) UnmarshalJSON(src []byte) (err error) { s.y = -1 dec := json.NewDecoder(bytes.NewReader(src)) var t json.Token for dec.More() && err == nil { if t, err = dec.Token(); err == nil { if _, check := t.(json.Delim); !check { switch t.(string) { case "ox": err = dec.Decode(&s.oy) s.offsetX = true case "oy": err = dec.Decode(&s.oy) s.offsetY = true case "x": err = dec.Decode(&s.x) case "y": err = dec.Decode(&s.y) case "cells": s.cells, err = parseCells(dec) case "height": err = dec.Decode(&s.height) case "style": err = dec.Decode(&s.style) case "styles": err = dec.Decode(&s.styles) default: dec.Decode(new(interface{})) } } } } return } func (s *Row) String() (res string) { res = fmt.Sprintf("{\n x: %v\n y: %v\n oy: %v\n offsetY: %v\n cells: %v\n}", s.x, s.y, s.oy, s.offsetY, s.cells) return } func (s *Row) IsCustomHeight() bool { return s.height > 0 } func (s *Row) Height() float64 { return s.height } func (s *Row) Styles() (res []string) { if len(s.styles) > 0 { res = s.styles } else if len(s.style) > 0 { res = []string{s.style} } return }