diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2015-08-02 23:54:53 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2015-08-02 23:54:53 +0900 |
commit | ae87f6548af27a293e4b00adc8b5c80fc88a4e92 (patch) | |
tree | 3cc376883615b97c594b9f1feae507028e092396 /src | |
parent | 7833fa739667f2f1ad400f02d6ff3767c4cf6fc8 (diff) |
GoLint
Diffstat (limited to 'src')
-rw-r--r-- | src/algo/algo.go | 1 | ||||
-rw-r--r-- | src/item.go | 34 | ||||
-rw-r--r-- | src/util/util.go | 6 |
3 files changed, 19 insertions, 22 deletions
diff --git a/src/algo/algo.go b/src/algo/algo.go index afc12aa8..03266dd9 100644 --- a/src/algo/algo.go +++ b/src/algo/algo.go @@ -161,6 +161,7 @@ func SuffixMatch(caseSensitive bool, input []rune, pattern []rune) (int, int) { return trimmedLen - len(pattern), trimmedLen } +// EqualMatch performs equal-match func EqualMatch(caseSensitive bool, runes []rune, pattern []rune) (int, int) { if len(runes) != len(pattern) { return -1, -1 diff --git a/src/item.go b/src/item.go index 96f3d231..7a0a2441 100644 --- a/src/item.go +++ b/src/item.go @@ -37,14 +37,14 @@ type Rank struct { var rankTiebreak tiebreak // Rank calculates rank of the Item -func (i *Item) Rank(cache bool) Rank { - if cache && (i.rank.matchlen > 0 || i.rank.tiebreak > 0) { - return i.rank +func (item *Item) Rank(cache bool) Rank { + if cache && (item.rank.matchlen > 0 || item.rank.tiebreak > 0) { + return item.rank } matchlen := 0 prevEnd := 0 minBegin := math.MaxUint16 - for _, offset := range i.offsets { + for _, offset := range item.offsets { begin := int(offset[0]) end := int(offset[1]) if prevEnd > begin { @@ -64,21 +64,21 @@ func (i *Item) Rank(cache bool) Rank { switch rankTiebreak { case byLength: // It is guaranteed that .transformed in not null in normal execution - if i.transformed != nil { + if item.transformed != nil { lenSum := 0 - for _, token := range i.transformed { + for _, token := range item.transformed { lenSum += len(token.text) } tiebreak = uint16(lenSum) } else { - tiebreak = uint16(len(i.text)) + tiebreak = uint16(len(item.text)) } case byBegin: - // We can't just look at i.offsets[0][0] because it can be an inverse term + // We can't just look at item.offsets[0][0] because it can be an inverse term tiebreak = uint16(minBegin) case byEnd: if prevEnd > 0 { - tiebreak = uint16(1 + len(i.text) - prevEnd) + tiebreak = uint16(1 + len(item.text) - prevEnd) } else { // Empty offsets due to inverse terms. tiebreak = 1 @@ -86,23 +86,23 @@ func (i *Item) Rank(cache bool) Rank { case byIndex: tiebreak = 1 } - rank := Rank{uint16(matchlen), tiebreak, i.index} + rank := Rank{uint16(matchlen), tiebreak, item.index} if cache { - i.rank = rank + item.rank = rank } return rank } // AsString returns the original string -func (i *Item) AsString() string { - return *i.StringPtr() +func (item *Item) AsString() string { + return *item.StringPtr() } // StringPtr returns the pointer to the original string -func (i *Item) StringPtr() *string { - runes := i.text - if i.origText != nil { - runes = *i.origText +func (item *Item) StringPtr() *string { + runes := item.text + if item.origText != nil { + runes = *item.origText } str := string(runes) return &str diff --git a/src/util/util.go b/src/util/util.go index eeeb75f4..aa5f227c 100644 --- a/src/util/util.go +++ b/src/util/util.go @@ -20,7 +20,7 @@ func Max(first int, items ...int) int { return max } -// Max32 returns the smallest 32-bit integer +// Min32 returns the smallest 32-bit integer func Min32(first int32, second int32) int32 { if first <= second { return first @@ -70,10 +70,6 @@ func DurWithin( return val } -func Between(val int, min int, max int) bool { - return val >= min && val <= max -} - // IsTty returns true is stdin is a terminal func IsTty() bool { return int(C.isatty(C.int(os.Stdin.Fd()))) != 0 |