NumLineBreaks counts how many line breaks are in the token text.
()
| 349 | |
| 350 | // NumLineBreaks counts how many line breaks are in the token text. |
| 351 | func (t Token) NumLineBreaks() int { |
| 352 | lineBreaks := strings.Count(t.Text, "\n") |
| 353 | if t.wasQuoted == '<' { |
| 354 | // heredocs have an extra linebreak because the opening |
| 355 | // delimiter is on its own line and is not included in the |
| 356 | // token Text itself, and the trailing newline is removed. |
| 357 | lineBreaks += 2 |
| 358 | } |
| 359 | return lineBreaks |
| 360 | } |
| 361 | |
| 362 | // Clone returns a deep copy of the token. |
| 363 | func (t Token) Clone() Token { |