package state import "fmt" // LineParity indicates whether odd or even lines are indented. type LineParity uint8 const ( // OddLines indicates that odd lines - 1, 3, 5... - are indented by 1/2 cell. OddLines LineParity = 1 // EvenLines indicates that even lines - 0, 2, 4... - are indented by 1/2 cell. EvenLines LineParity = 2 ) // UnmarshalText unmarshals from the equivalent Javascript constant name. func (o *LineParity) UnmarshalText(text []byte) error { switch string(text) { case "ODD": *o = OddLines return nil case "EVEN": *o = EvenLines return nil default: return fmt.Errorf("can't unmarshal unknown LineParity %s", text) } } // MarshalText marshals into the equivalent JavaScript constant name. func (o LineParity) MarshalText() (text []byte, err error) { switch o { case OddLines, EvenLines: return []byte(o.String()), nil default: return nil, fmt.Errorf("can't marshal unknown LineParity %d", o) } } // String returns the equivalent JavaScript constant name. func (o LineParity) String() string { switch o { case OddLines: return "ODD_LINES" case EvenLines: return "EVEN_LINES" default: return fmt.Sprintf("[unknown LineParity %d]", o) } }