1 parent
d622e74c51
commit
a2cc32c908
4 files changed
+77
-11
No files matched your search
@@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
@@ -49,6 +50,23 @@ func runeSliceWidthRange(rs []rune, beg int, end int) []rune {
|
||||
return nil
|
||||
}
|
||||
|
||||
// This function splits the first word of a string delimited by whitespace from
|
||||
// the rest. This is used to tokenize a string one by one without touching the
|
||||
// rest. Whitespace on the left side of both the word and the rest are trimmed.
|
||||
func splitWord(s string) (word, rest string) {
|
||||
s = strings.TrimLeftFunc(s, unicode.IsSpace)
|
||||
ind := len(s)
|
||||
for i, c := range s {
|
||||
if unicode.IsSpace(c) {
|
||||
ind = i
|
||||
break
|
||||
}
|
||||
}
|
||||
word = s[0:ind]
|
||||
rest = strings.TrimLeftFunc(s[ind:], unicode.IsSpace)
|
||||
return
|
||||
}
|
||||
|
||||
// This function converts a size in bytes to a human readable form. For this
|
||||
// purpose metric suffixes are used (e.g. 1K = 1000). For values less than 10
|
||||
// the first significant digit is shown, otherwise it is hidden. Numbers are
|
||||
|
||||
Reference in new issue
Block a user