MCPcopy Create free account
hub / github.com/brimdata/super / formatMap

Method formatMap

sup/formatter.go:521–555  ·  view source on GitHub ↗
(indent int, typ *super.TypeMap, bytes scode.Bytes, known bool)

Source from the content-addressed store, hash-verified

519}
520
521func (f *Formatter) formatMap(indent int, typ *super.TypeMap, bytes scode.Bytes, known bool) bool {
522 empty := true
523 f.build("|{")
524 indent += f.tab
525 sep := f.newline
526 keyElems := newElemBuilder(typ.KeyType)
527 valElems := newElemBuilder(typ.ValType)
528 for it := bytes.Iter(); !it.Done(); {
529 keyBytes := it.Next()
530 empty = false
531 f.build(sep)
532 f.indent(indent, "")
533 var keyType super.Type
534 keyType, keyBytes = keyElems.add(keyBytes)
535 f.formatValue(indent, keyType, keyBytes, known, true)
536 if super.TypeUnder(keyType) == super.TypeIP && len(keyBytes) == 16 {
537 // To avoid ambiguity, whitespace must separate an IPv6
538 // map key from the colon that follows it.
539 f.build(" ")
540 }
541 f.build(":")
542 if f.tab > 0 {
543 f.build(" ")
544 }
545 valType, valBytes := valElems.add(it.Next())
546 f.formatValue(indent, valType, valBytes, known, true)
547 sep = "," + f.newline
548 }
549 f.build(f.newline)
550 f.indent(indent-f.tab, "}|")
551 if keyElems.needsDecoration() || valElems.needsDecoration() {
552 f.decorate(typ, true)
553 }
554 return empty
555}
556
557func (f *Formatter) indent(tab int, s string) {
558 for range tab {

Callers 1

formatValueMethod · 0.95

Calls 11

buildMethod · 0.95
indentMethod · 0.95
formatValueMethod · 0.95
decorateMethod · 0.95
TypeUnderFunction · 0.92
newElemBuilderFunction · 0.85
IterMethod · 0.80
needsDecorationMethod · 0.80
DoneMethod · 0.45
NextMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected