Skip to content

Commit

Permalink
B: get integer value from XPath
Browse files Browse the repository at this point in the history
  • Loading branch information
pgundlach committed Nov 22, 2023
1 parent c8afab0 commit 49cc5ee
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
3 changes: 1 addition & 2 deletions core/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1316,8 +1316,7 @@ func cmdPlaceObject(xd *xtsDocument, layoutelt *goxml.Element) (xpath.Sequence,
vl.List = node.InsertBefore(vl.List, vl.List, r)
}

if rowFloat, err := strconv.ParseFloat(attValues.Row, 32); err == nil {
rowInt = int(rowFloat)
if rowInt, ok = getInt(attValues.Row); ok {
rowSet = true
pos = positioningGrid
row = coord(rowInt)
Expand Down
19 changes: 16 additions & 3 deletions core/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ func (xd *xtsDocument) getTextvalues(tagname string, seq xpath.Sequence, attribu
cd.Type = html.TextNode
cd.Data = strconv.FormatFloat(t, 'f', -1, 64)
n.AppendChild(cd)
case int:
cd := &html.Node{}
cd.Type = html.TextNode
cd.Data = fmt.Sprintf("%d", t)
n.AppendChild(cd)
default:
slog.Error(fmt.Sprintf("%s (line %d): unknown type %T (getTextvalues)", cmdname, line, t))
}
Expand Down Expand Up @@ -312,9 +317,9 @@ func getXMLAttributes(xd *xtsDocument, layoutelt *goxml.Element, v any) error {
if hasAttribute {
switch field.Type() {
case intType:
attInt, err := strconv.Atoi(attValue)
if err != nil {
return err
attInt, ok := getInt(attValue)
if !ok {
return fmt.Errorf("Could not get int from %s", attValue)
}
field.SetInt(int64(attInt))
case intPtrType:
Expand Down Expand Up @@ -485,6 +490,14 @@ func evaluateXPath(xd *xtsDocument, namespaces map[string]string, xpath string)
return seq, err
}

func getInt(in string) (int, bool) {
f, err := strconv.ParseFloat(in, 64)
if err != nil {
return 0, false
}
return int(f), true
}

func getFourValues(str string) map[string]string {
fields := strings.Fields(str)
fourvalues := make(map[string]string)
Expand Down
1 change: 1 addition & 0 deletions core/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func clearPage(xd *xtsDocument) {
}
cp := xd.currentPage
if cp.atPageShipout != nil {
slog.Debug("Call AtPageShipout")
cp.atPageShipout()
}
xd.currentPage.bagPage.Shipout()
Expand Down
1 change: 1 addition & 0 deletions xts/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func setupLog(protocol string) error {
enc = xml.NewEncoder(protocolFile)
if err = enc.EncodeToken(xml.StartElement{
Name: xml.Name{Local: "log"},
Attr: []xml.Attr{{Name: xml.Name{Local: "loglevel"}, Value: loglevel.Level().String()}},
}); err != nil {
return err
}
Expand Down

0 comments on commit 49cc5ee

Please sign in to comment.