formatLimitLength recurses into a node for pretty-printing, but limits the number of characters to be printed.
(n NodeFormatter, maxLength int)
| 689 | // formatLimitLength recurses into a node for pretty-printing, but limits the |
| 690 | // number of characters to be printed. |
| 691 | func (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. |
no test coverage detected