MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / formatLimitLength

Method formatLimitLength

pkg/sql/sem/tree/format.go:691–717  ·  view source on GitHub ↗

formatLimitLength recurses into a node for pretty-printing, but limits the number of characters to be printed.

(n NodeFormatter, maxLength int)

Source from the content-addressed store, hash-verified

689// formatLimitLength recurses into a node for pretty-printing, but limits the
690// number of characters to be printed.
691func (ctx *FmtCtx) formatLimitLength(n NodeFormatter, maxLength int) {
692 temp := NewFmtCtx(ctx.flags)
693 temp.formatNodeSummary(n)
694 s := temp.CloseAndGetString()
695 if len(s) > maxLength {
696 truncated := s[:maxLength] + "..."
697 // close all open parentheses.
698 if strings.Count(truncated, "(") > strings.Count(truncated, ")") {
699 remaining := s[maxLength:]
700 for i, c := range remaining {
701 if c == ')' {
702 truncated += ")"
703 // add ellipses if there was more text after the parenthesis in
704 // the original string.
705 if i < len(remaining)-1 && string(remaining[i+1]) != ")" {
706 truncated += "..."
707 }
708 if strings.Count(truncated, "(") <= strings.Count(truncated, ")") {
709 break
710 }
711 }
712 }
713 }
714 s = truncated
715 }
716 ctx.WriteString(s)
717}
718
719// formatSummarySelect pretty-prints a summarized select statement.
720// See FmtSummary for supported formats.

Callers 3

formatSummarySelectMethod · 0.95
formatSummaryInsertMethod · 0.95
formatSummaryUpdateMethod · 0.95

Calls 3

formatNodeSummaryMethod · 0.95
CloseAndGetStringMethod · 0.95
NewFmtCtxFunction · 0.85

Tested by

no test coverage detected