MCPcopy
hub / github.com/pelletier/go-toml / rawValue

Method rawValue

unmarshaler.go:1594–1621  ·  view source on GitHub ↗

rawValue returns the raw bytes of the value of a key-value expression.

(expr *unstable.Node, value *unstable.Node)

Source from the content-addressed store, hash-verified

1592
1593// rawValue returns the raw bytes of the value of a key-value expression.
1594func (d *decoder) rawValue(expr *unstable.Node, value *unstable.Node) []byte {
1595 if value.Kind != unstable.InlineTable && value.Kind != unstable.Array {
1596 return d.p.Raw(value.Raw)
1597 }
1598 if expr == nil || expr.Kind != unstable.KeyValue {
1599 // Inline container nested in another container: best effort.
1600 return d.p.Raw(value.Raw)
1601 }
1602 // Reconstruct the span of the value: it starts after the equal sign
1603 // following the last part of the key, and stops at the end of the
1604 // expression.
1605 var last unstable.Range
1606 it := expr.Key()
1607 for it.Next() {
1608 last = it.Node().Raw
1609 }
1610 doc := d.p.Data()
1611 i := int(last.Offset + last.Length)
1612 for i < len(doc) && (doc[i] == ' ' || doc[i] == '\t') {
1613 i++
1614 }
1615 i++ // equal sign
1616 for i < len(doc) && (doc[i] == ' ' || doc[i] == '\t') {
1617 i++
1618 }
1619 end := int(expr.Raw.Offset + expr.Raw.Length)
1620 return doc[i:end]
1621}
1622
1623// unmarshalerOf returns the unstable.Unmarshaler implementation of v, if
1624// any. It allocates intermediate pointers as needed.

Callers 4

descendMethod · 0.95
assignValueMethod · 0.95
assignArrayMethod · 0.95
assignInlineTableMethod · 0.95

Calls 5

RawMethod · 0.80
NodeMethod · 0.80
DataMethod · 0.80
KeyMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected