-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This makes sorting flags and other sections consistent with how most command line tools function, by placing both flags `-A` and `-a` before a flag `-B`.
- Loading branch information
Showing
5 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cli | ||
|
||
import "unicode" | ||
|
||
// lexicographicLess compares strings alphabetically considering case. | ||
func lexicographicLess(i, j string) bool { | ||
iRunes := []rune(i) | ||
jRunes := []rune(j) | ||
|
||
lenShared := len(iRunes) | ||
if lenShared > len(jRunes) { | ||
lenShared = len(jRunes) | ||
} | ||
|
||
for index := 0; index < lenShared; index++ { | ||
ir := iRunes[index] | ||
jr := jRunes[index] | ||
|
||
if lir, ljr := unicode.ToLower(ir), unicode.ToLower(jr); lir != ljr { | ||
return lir < ljr | ||
} | ||
|
||
if ir != jr { | ||
return ir < jr | ||
} | ||
} | ||
|
||
return i < j | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package cli | ||
|
||
import "testing" | ||
|
||
var lexicographicLessTests = []struct { | ||
i string | ||
j string | ||
expected bool | ||
}{ | ||
{"", "a", true}, | ||
{"a", "", false}, | ||
{"a", "a", false}, | ||
{"a", "A", false}, | ||
{"A", "a", true}, | ||
{"aa", "a", false}, | ||
{"a", "aa", true}, | ||
{"a", "b", true}, | ||
{"a", "B", true}, | ||
{"A", "b", true}, | ||
{"A", "B", true}, | ||
} | ||
|
||
func TestLexicographicLess(t *testing.T) { | ||
for _, test := range lexicographicLessTests { | ||
actual := lexicographicLess(test.i, test.j) | ||
if test.expected != actual { | ||
t.Errorf(`expected string "%s" to come before "%s"`, test.i, test.j) | ||
} | ||
} | ||
} |