Skip to content

Commit

Permalink
Merge branch 'develop' into fix/2298
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jul 24, 2021
2 parents 54f1a5e + e8a7253 commit a296b8c
Show file tree
Hide file tree
Showing 232 changed files with 3,705 additions and 1,505 deletions.
33 changes: 20 additions & 13 deletions cmd/fyne/internal/mobile/binres/binres.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ func UnmarshalXML(r io.Reader, withIcon bool) (*XML, error) {
return buildXML(q)
}

// buildXML encodes a queue of tokens into a binary XML resource
func buildXML(q []ltoken) (*XML, error) {
// temporary pool to resolve real poolref later
pool := new(Pool)
Expand All @@ -322,9 +323,9 @@ func buildXML(q []ltoken) (*XML, error) {
for _, ltkn := range q {
tkn, line := ltkn.Token, ltkn.line

i, err := handleTokens(tkn, line, pool, bx, tbl)
err := handleTokens(tkn, line, pool, bx, tbl)
if err != nil {
return i, err
return nil, err
}
}

Expand Down Expand Up @@ -475,7 +476,8 @@ func resolveElements(elms []*Element, pool, bxPool *Pool) {
}
}

func handleTokens(tkn xml.Token, line int, pool *Pool, bx *XML, tbl *Table) (*XML, error) {
// handleTokens encodes tkn, attaching it to the binary xml
func handleTokens(tkn xml.Token, line int, pool *Pool, bx *XML, tbl *Table) error {
switch tkn := tkn.(type) {
case xml.StartElement:
el := &Element{
Expand All @@ -497,9 +499,9 @@ func handleTokens(tkn xml.Token, line int, pool *Pool, bx *XML, tbl *Table) (*XM
}
bx.stack = append(bx.stack, el)

i, err := addAttributes(tkn, bx, line, pool, el, tbl)
err := addAttributes(tkn, bx, line, pool, el, tbl)
if err != nil {
return i, err
return err
}
case xml.CharData:
if s := poolTrim(string(tkn)); s != "" {
Expand All @@ -516,7 +518,7 @@ func handleTokens(tkn xml.Token, line int, pool *Pool, bx *XML, tbl *Table) (*XM
} else if el.tail == nil {
el.tail = cdt
} else {
return nil, fmt.Errorf("element head and tail already contain chardata")
return fmt.Errorf("element head and tail already contain chardata")
}
}
case xml.EndElement:
Expand All @@ -534,7 +536,7 @@ func handleTokens(tkn xml.Token, line int, pool *Pool, bx *XML, tbl *Table) (*XM
var el *Element
el, bx.stack = bx.stack[n-1], bx.stack[:n-1]
if el.end != nil {
return nil, fmt.Errorf("element end already exists")
return fmt.Errorf("element end already exists")
}
el.end = &ElementEnd{
NodeHeader: NodeHeader{
Expand All @@ -549,18 +551,20 @@ func handleTokens(tkn xml.Token, line int, pool *Pool, bx *XML, tbl *Table) (*XM
default:
panic(fmt.Errorf("unhandled token type: %T %+v", tkn, tkn))
}
return nil, nil
return nil
}

func addAttributes(tkn xml.StartElement, bx *XML, line int, pool *Pool, el *Element, tbl *Table) (*XML, error) {
// addAttributes encodes the attributes of tkn and adds them to el.
// Any attributes which were not already present in Pool are added to it.
func addAttributes(tkn xml.StartElement, bx *XML, line int, pool *Pool, el *Element, tbl *Table) error {
for _, attr := range tkn.Attr {
if (attr.Name.Space == "xmlns" && attr.Name.Local == "tools") || attr.Name.Space == toolsSchema {
continue // TODO can tbl be queried for schemas to determine validity instead?
}

if attr.Name.Space == "xmlns" && attr.Name.Local == "android" {
if bx.Namespace != nil {
return nil, fmt.Errorf("multiple declarations of xmlns:android encountered")
return fmt.Errorf("multiple declarations of xmlns:android encountered")
}
bx.Namespace = &Namespace{
NodeHeader: NodeHeader{
Expand Down Expand Up @@ -588,7 +592,7 @@ func addAttributes(tkn xml.StartElement, bx *XML, line int, pool *Pool, el *Elem
nattr.TypedValue.Type = DataIntDec
i, err := strconv.Atoi(attr.Value)
if err != nil {
return nil, err
return err
}
nattr.TypedValue.Value = uint32(i)
default: // "package", "platformBuildVersionName", and any invalid
Expand All @@ -598,13 +602,16 @@ func addAttributes(tkn xml.StartElement, bx *XML, line int, pool *Pool, el *Elem
} else {
err := addAttributeNamespace(attr, nattr, tbl, pool)
if err != nil {
return nil, err
return err
}
}
}
return nil, nil
return nil
}

// addAttributeNamespace encodes attr based on its namespace
// The encoded value is stored in nattr.
// If the value was not already present in pool, it is added.
func addAttributeNamespace(attr xml.Attr, nattr *Attribute, tbl *Table, pool *Pool) error {
// get type spec and value data type
ref, err := tbl.RefByName("attr/" + attr.Name.Local)
Expand Down

0 comments on commit a296b8c

Please sign in to comment.