commonIndent returns the length, in bytes, of the longest run of leading `cutset` characters shared by every non-blank line. Blank lines (those that are empty after trimming) are ignored so they don't force the indent to zero.
(lines []string, cutset string)
| 91 | // `cutset` characters shared by every non-blank line. Blank lines (those that |
| 92 | // are empty after trimming) are ignored so they don't force the indent to zero. |
| 93 | func commonIndent(lines []string, cutset string) int { |
| 94 | common := -1 |
| 95 | for _, line := range lines { |
| 96 | if strings.TrimLeft(line, cutset) == "" { |
| 97 | continue |
| 98 | } |
| 99 | n := len(line) - len(strings.TrimLeft(line, cutset)) |
| 100 | if common == -1 || n < common { |
| 101 | common = n |
| 102 | } |
| 103 | } |
| 104 | if common < 0 { |
| 105 | return 0 |
| 106 | } |
| 107 | return common |
| 108 | } |
| 109 | |
| 110 | // stripIndent removes up to `n` leading `cutset` characters from `line` (a line |
| 111 | // with fewer than `n` leading cutset characters -- e.g. a blank line -- loses |
no outgoing calls
no test coverage detected
searching dependent graphs…