cellbuf/utils.go
raw| 1 | package cellbuf |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | ) |
| 6 | |
| 7 | // Height returns the height of a string. |
| 8 | func Height(s string) int { |
| 9 | return strings.Count(s, "\n") + 1 |
| 10 | } |
| 11 | |
| 12 | func clamp(v, low, high int) int { |
| 13 | if high < low { |
| 14 | low, high = high, low |
| 15 | } |
| 16 | return min(high, max(low, v)) |
| 17 | } |
| 18 | |
| 19 | func abs(a int) int { |
| 20 | if a < 0 { |
| 21 | return -a |
| 22 | } |
| 23 | return a |
| 24 | } |