aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorYang Zhang <yang_zhang@iapcm.ac.cn>2019-01-07 21:30:46 +0800
committerYang Zhang <yang_zhang@iapcm.ac.cn>2019-01-07 21:30:46 +0800
commit2feb4ec21b875a9f444033fd81ee9af63e46819b (patch)
tree1f8e4cc207cb89bf288c5d4452aa16a69019762d /util
parent309e6892c3ea19db77ee02acf938ea30f63e82df (diff)
downloadgit-bug-2feb4ec21b875a9f444033fd81ee9af63e46819b.tar.gz
Fix bad names in text.go
Diffstat (limited to 'util')
-rw-r--r--util/text/text.go42
-rw-r--r--util/text/text_test.go8
2 files changed, 25 insertions, 25 deletions
diff --git a/util/text/text.go b/util/text/text.go
index f77fa0e2..f59bdbfb 100644
--- a/util/text/text.go
+++ b/util/text/text.go
@@ -107,7 +107,7 @@ func softwrapLine(line string, textWidth int) string {
// escape command, and 'pos' is the index in the rune array where the 'item'
// shall be inserted back. For example, the escape item in "F\x1b33mox" is
// {"\x1b33m", 1}.
-type EscapeItem struct {
+type escapeItem struct {
item string
pos int
}
@@ -118,8 +118,8 @@ type EscapeItem struct {
//
// Required: The line shall not contain "\n"
//
-func extractTermEscapes(line string) (string, []EscapeItem) {
- var termEscapes []EscapeItem
+func extractTermEscapes(line string) (string, []escapeItem) {
+ var termEscapes []escapeItem
var line1 string
pos := 0
@@ -136,7 +136,7 @@ func extractTermEscapes(line string) (string, []EscapeItem) {
if inEscape {
item += string(r)
if r == 'm' {
- termEscapes = append(termEscapes, EscapeItem{item, pos - occupiedRuneCount})
+ termEscapes = append(termEscapes, escapeItem{item, pos - occupiedRuneCount})
occupiedRuneCount += utf8.RuneCountInString(item)
inEscape = false
}
@@ -151,7 +151,7 @@ func extractTermEscapes(line string) (string, []EscapeItem) {
// Apply the extracted terminal escapes to the edited line. The only edit
// allowed is to insert "\n" like that in softwrapLine. Callers shall ensure
// this since this function is not able to check it.
-func applyTermEscapes(line string, escapes []EscapeItem) string {
+func applyTermEscapes(line string, escapes []escapeItem) string {
if len(escapes) == 0 {
return line
}
@@ -189,18 +189,18 @@ func segmentLine(s string) []string {
var chunks []string
var word string
- wordType := NONE
+ wordType := none
flushWord := func() {
chunks = append(chunks, word)
word = ""
- wordType = NONE
+ wordType = none
}
for _, r := range s {
// A WIDE_CHAR itself constitutes a chunk.
thisType := runeType(r)
- if thisType == WIDE_CHAR {
- if wordType != NONE {
+ if thisType == wideChar {
+ if wordType != none {
flushWord()
}
chunks = append(chunks, string(r))
@@ -209,7 +209,7 @@ func segmentLine(s string) []string {
// Other type of chunks starts with a char of that type, and ends with a
// char with different type or end of string.
if thisType != wordType {
- if wordType != NONE {
+ if wordType != none {
flushWord()
}
word = string(r)
@@ -231,27 +231,27 @@ func segmentLine(s string) []string {
// chunk. It IS NOT the same as unicode code point categories.
//
const (
- NONE = -1
- WIDE_CHAR = iota
- INVISIBLE = iota
- SHORT_UNICODE = iota
- SPACE = iota
- VISIBLE_ASCII = iota
+ none int = iota
+ wideChar
+ invisible
+ shortUnicode
+ space
+ visibleAscii
)
// Determine the category of a rune.
func runeType(r rune) int {
rw := runewidth.RuneWidth(r)
if rw > 1 {
- return WIDE_CHAR
+ return wideChar
} else if rw == 0 {
- return INVISIBLE
+ return invisible
} else if r > 127 {
- return SHORT_UNICODE
+ return shortUnicode
} else if r == ' ' {
- return SPACE
+ return space
} else {
- return VISIBLE_ASCII
+ return visibleAscii
}
}
diff --git a/util/text/text_test.go b/util/text/text_test.go
index ae4887b8..7008589d 100644
--- a/util/text/text_test.go
+++ b/util/text/text_test.go
@@ -291,25 +291,25 @@ func TestExtractApplyTermEscapes(t *testing.T) {
cases := []struct {
Input string
Output string
- TermEscapes []EscapeItem
+ TermEscapes []escapeItem
}{
// A plain ascii line with escapes.
{
"This \x1b[31mis an\x1b[0m example.",
"This is an example.",
- []EscapeItem{{"\x1b[31m", 5}, {"\x1b[0m", 10}},
+ []escapeItem{{"\x1b[31m", 5}, {"\x1b[0m", 10}},
},
// A plain wide line with escapes.
{
"一只敏捷\x1b[31m的狐狸\x1b[0m跳过了一只懒狗。",
"一只敏捷的狐狸跳过了一只懒狗。",
- []EscapeItem{{"\x1b[31m", 4}, {"\x1b[0m", 7}},
+ []escapeItem{{"\x1b[31m", 4}, {"\x1b[0m", 7}},
},
// A normal-wide mixed line with escapes.
{
"一只 A Quick 敏捷\x1b[31m的狐 Fox 狸\x1b[0m跳过了Dog一只懒狗。",
"一只 A Quick 敏捷的狐 Fox 狸跳过了Dog一只懒狗。",
- []EscapeItem{{"\x1b[31m", 13}, {"\x1b[0m", 21}},
+ []escapeItem{{"\x1b[31m", 13}, {"\x1b[0m", 21}},
},
}