From 00a766412bac1459605664019bca1685171b6ce7 Mon Sep 17 00:00:00 2001 From: n0m1s Date: Wed, 30 Oct 2019 00:03:27 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A1=20some=20function=20documentation?= =?UTF-8?q?=20comments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jdr/sheet.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/jdr/sheet.go b/jdr/sheet.go index 277fcfa..e3bf370 100644 --- a/jdr/sheet.go +++ b/jdr/sheet.go @@ -158,12 +158,18 @@ func (n *xmlNode) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { return d.DecodeElement((*node)(n), &start) } +// The parseVariable function parses a Variable value from a XML node. +// The variable type is inferred from the "type" attribute of the node. +// If this attribute is omitted, the type of the variable must be given through the +// "defaults" parameter to avoid a parsing error. +// If this attribute is specified, the "defaults" parameter will be unused and may be nil func parseVariable(root xmlNode, sheet *CharacterSheet, defaults *Variable) (*Variable, error) { ret := &Variable{} typeOk := false nameOk := false + //parsing default values if defaults != nil { switch defaults.Type.(type) { case *VariableType_badType: @@ -174,6 +180,7 @@ func parseVariable(root xmlNode, sheet *CharacterSheet, defaults *Variable) (*Va } } + //iterating on the attributes for i := 0; i < len(root.Attrs); i++ { attrName := root.Attrs[i].Name.Local attrVal := root.Attrs[i].Value @@ -192,6 +199,7 @@ func parseVariable(root xmlNode, sheet *CharacterSheet, defaults *Variable) (*Va } } + //check if no parse error if !nameOk { return nil, errors.New("Unnamed variable") }