MCPcopy Index your code
hub / github.com/google/mangle / DisplayString

Method DisplayString

ast/ast.go:652–728  ·  view source on GitHub ↗

DisplayString returns a string representation of the constant without escaping Unicode characters. Note: If the string contains quote characters ("), the display string won't look like a source string anymore.

()

Source from the content-addressed store, hash-verified

650// DisplayString returns a string representation of the constant without escaping Unicode characters.
651// Note: If the string contains quote characters ("), the display string won't look like a source string anymore.
652func (c Constant) DisplayString() string {
653 switch c.Type {
654 case NameType:
655 return string(c.Symbol)
656 case StringType:
657 return fmt.Sprintf("\"%s\"", c.Symbol)
658 case BytesType:
659 return fmt.Sprintf("b\"%s\"", c.Symbol)
660 case NumberType:
661 return FormatNumber(c.NumValue)
662 case Float64Type:
663 return FormatFloat64(math.Float64frombits(uint64(c.NumValue)))
664 case TimeType:
665 return FormatTime(c.NumValue)
666 case DurationType:
667 return FormatDuration(c.NumValue)
668 case PairShape:
669 fst := *c.fst
670 snd := *c.snd
671 return fmt.Sprintf("fn:pair(%s, %s)", fst.DisplayString(), snd.DisplayString())
672 case ListShape:
673 if c.IsListNil() {
674 return "[]"
675 }
676 var s strings.Builder
677 s.WriteRune('[')
678 s.WriteString((*c.fst).DisplayString())
679 c2 := *c.snd
680 for !c2.IsListNil() {
681 s.WriteString(", ")
682 s.WriteString((*c2.fst).DisplayString())
683 c2 = *c2.snd
684 }
685 s.WriteRune(']')
686 return s.String()
687 case MapShape:
688 if c.IsMapNil() {
689 return "fn:map()"
690 }
691 var s strings.Builder
692 s.WriteRune('[')
693 s.WriteString((*c.fst.fst).DisplayString())
694 s.WriteString(" : ")
695 s.WriteString((*c.fst.snd).DisplayString())
696 c2 := *c.snd
697 for !c2.IsMapNil() {
698 s.WriteString(", ")
699 s.WriteString((*c2.fst.fst).DisplayString())
700 s.WriteString(" : ")
701 s.WriteString((*c2.fst.snd).DisplayString())
702 c2 = *c2.snd
703 }
704 s.WriteRune(']')
705 return s.String()
706 case StructShape:
707 if c.IsStructNil() {
708 return "{}"
709 }

Callers

nothing calls this directly

Calls 9

IsListNilMethod · 0.95
StringMethod · 0.95
IsMapNilMethod · 0.95
IsStructNilMethod · 0.95
FormatNumberFunction · 0.85
FormatFloat64Function · 0.85
FormatTimeFunction · 0.85
FormatDurationFunction · 0.85
DisplayStringMethod · 0.45

Tested by

no test coverage detected