MCPcopy
hub / github.com/dgraph-io/dgraph / stringHelper

Method stringHelper

dql/math.go:378–415  ·  view source on GitHub ↗

stringHelper does simple DFS to convert MathTree to string. nolint: unused

(buf *bytes.Buffer)

Source from the content-addressed store, hash-verified

376// stringHelper does simple DFS to convert MathTree to string.
377// nolint: unused
378func (t *MathTree) stringHelper(buf *bytes.Buffer) {
379 x.AssertTruef(t != nil, "Nil Math tree")
380 if t.Var != "" {
381 // Leaf node.
382 x.Check2(buf.WriteString(t.Var))
383 return
384 }
385 if t.Const.Value != nil {
386 // Leaf node.
387 var leafStr int
388 var err error
389 switch t.Const.Tid {
390 case types.FloatID:
391 leafStr, err = buf.WriteString(strconv.FormatFloat(
392 t.Const.Value.(float64), 'E', -1, 64))
393 case types.IntID:
394 leafStr, err = buf.WriteString(strconv.FormatInt(t.Const.Value.(int64), 10))
395 }
396 x.Check2(leafStr, err)
397 return
398 }
399 // Non-leaf node.
400 x.Check2(buf.WriteRune('('))
401 switch t.Fn {
402 case "+", "-", "/", "*", "%", "exp", "ln", "cond", "min",
403 "sqrt", "max", "<", ">", "<=", ">=", "==", "!=", "u-",
404 "logbase", "pow", "dot":
405 x.Check2(buf.WriteString(t.Fn))
406 default:
407 x.Fatalf("Unknown operator: %q", t.Fn)
408 }
409
410 for _, c := range t.Child {
411 x.Check2(buf.WriteRune(' '))
412 c.stringHelper(buf)
413 }
414 x.Check2(buf.WriteRune(')'))
415}

Callers 1

debugStringMethod · 0.95

Calls 3

AssertTruefFunction · 0.92
Check2Function · 0.92
FatalfFunction · 0.92

Tested by

no test coverage detected