Minor refactorings

This commit is contained in:
Junegunn Choi 2017-08-26 03:24:42 +09:00
parent 329de8f416
commit af809c9661
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
4 changed files with 4 additions and 4 deletions

View File

@ -79,7 +79,7 @@ func extractColor(str string, state *ansiState, proc func(string, *ansiState) bo
// Make sure that we found an ANSI code // Make sure that we found an ANSI code
offset := ansiRegex.FindStringIndex(str[idx:]) offset := ansiRegex.FindStringIndex(str[idx:])
if offset == nil { if len(offset) < 2 {
idx++ idx++
continue continue
} }

View File

@ -76,7 +76,7 @@ func (r *Reader) feed(src io.Reader) {
// end in delim. // end in delim.
bytea, err := reader.ReadBytes(delim) bytea, err := reader.ReadBytes(delim)
byteaLen := len(bytea) byteaLen := len(bytea)
if len(bytea) > 0 { if byteaLen > 0 {
if err == nil { if err == nil {
// get rid of carriage return if under Windows: // get rid of carriage return if under Windows:
if util.IsWindows() && byteaLen >= 2 && bytea[byteaLen-2] == byte('\r') { if util.IsWindows() && byteaLen >= 2 && bytea[byteaLen-2] == byte('\r') {

View File

@ -147,7 +147,7 @@ func Tokenize(text string, delimiter Delimiter) []Token {
if delimiter.regex != nil { if delimiter.regex != nil {
for len(text) > 0 { for len(text) > 0 {
loc := delimiter.regex.FindStringIndex(text) loc := delimiter.regex.FindStringIndex(text)
if loc == nil { if len(loc) < 2 {
loc = []int{0, len(text)} loc = []int{0, len(text)}
} }
last := util.Max(loc[1], 1) last := util.Max(loc[1], 1)

View File

@ -160,7 +160,7 @@ func (chars *Chars) CopyRunes(dest []rune) {
copy(dest, runes) copy(dest, runes)
return return
} }
for idx, b := range chars.slice { for idx, b := range chars.slice[:len(dest)] {
dest[idx] = rune(b) dest[idx] = rune(b)
} }
return return