From ab1afb975a129f8d45172415a557a7a2b8bea703 Mon Sep 17 00:00:00 2001 From: Cheer Xiao Date: Tue, 24 Feb 2015 21:46:08 +0100 Subject: [PATCH] golint fixes for util --- util/strings.go | 12 ++++++------ util/strings_test.go | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/util/strings.go b/util/strings.go index de18106f..b730d898 100644 --- a/util/strings.go +++ b/util/strings.go @@ -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 } diff --git a/util/strings_test.go b/util/strings_test.go index 6d360b79..445c9ff2 100644 --- a/util/strings_test.go +++ b/util/strings_test.go @@ -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) {