mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
golint fixes for util
This commit is contained in:
parent
59d1cf249e
commit
ab1afb975a
|
@ -39,14 +39,14 @@ func FindLastSOL(s string) int {
|
|||
}
|
||||
|
||||
var (
|
||||
IndexOutOfRange = errors.New("substring out of range")
|
||||
ErrIndexOutOfRange = errors.New("substring out of range")
|
||||
)
|
||||
|
||||
// SubStringByRune returns the range of the i-th rune (inclusive) through the
|
||||
// SubstringByRune returns the range of the i-th rune (inclusive) through the
|
||||
// j-th rune (exclusive) in s.
|
||||
func SubstringByRune(s string, low, high int) (string, error) {
|
||||
if low > high || low < 0 || high < 0 {
|
||||
return "", IndexOutOfRange
|
||||
return "", ErrIndexOutOfRange
|
||||
}
|
||||
var bLow, bHigh, j int
|
||||
for i := range s {
|
||||
|
@ -59,7 +59,7 @@ func SubstringByRune(s string, low, high int) (string, error) {
|
|||
j++
|
||||
}
|
||||
if j < high {
|
||||
return "", IndexOutOfRange
|
||||
return "", ErrIndexOutOfRange
|
||||
}
|
||||
if low == high {
|
||||
return "", nil
|
||||
|
@ -73,7 +73,7 @@ func SubstringByRune(s string, low, high int) (string, error) {
|
|||
// NthRune returns the n-th rune of s.
|
||||
func NthRune(s string, n int) (rune, error) {
|
||||
if n < 0 {
|
||||
return 0, IndexOutOfRange
|
||||
return 0, ErrIndexOutOfRange
|
||||
}
|
||||
var j int
|
||||
for _, r := range s {
|
||||
|
@ -82,5 +82,5 @@ func NthRune(s string, n int) (rune, error) {
|
|||
}
|
||||
j++
|
||||
}
|
||||
return 0, IndexOutOfRange
|
||||
return 0, ErrIndexOutOfRange
|
||||
}
|
||||
|
|
|
@ -32,9 +32,9 @@ var SubstringByRuneTests = []struct {
|
|||
{"你好世界", 1, 1, "", nil},
|
||||
{"你好世界", 1, 2, "好", nil},
|
||||
{"你好世界", 1, 4, "好世界", nil},
|
||||
{"你好世界", -1, -1, "", IndexOutOfRange},
|
||||
{"你好世界", 0, 5, "", IndexOutOfRange},
|
||||
{"你好世界", 5, 5, "", IndexOutOfRange},
|
||||
{"你好世界", -1, -1, "", ErrIndexOutOfRange},
|
||||
{"你好世界", 0, 5, "", ErrIndexOutOfRange},
|
||||
{"你好世界", 5, 5, "", ErrIndexOutOfRange},
|
||||
}
|
||||
|
||||
func TestSubstringByRune(t *testing.T) {
|
||||
|
@ -53,9 +53,9 @@ var NthRuneTests = []struct {
|
|||
wantedRune rune
|
||||
wantedErr error
|
||||
}{
|
||||
{"你好世界", -1, 0, IndexOutOfRange},
|
||||
{"你好世界", -1, 0, ErrIndexOutOfRange},
|
||||
{"你好世界", 0, '你', nil},
|
||||
{"你好世界", 4, 0, IndexOutOfRange},
|
||||
{"你好世界", 4, 0, ErrIndexOutOfRange},
|
||||
}
|
||||
|
||||
func TestNthRune(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user