mirror of
https://github.com/Jguer/yay
synced 2024-10-31 04:12:51 +00:00
Merge pull request #524 from AlexWayfer/support_commas_in_parse_number_menu
Support commas in parserNumberMenu
This commit is contained in:
commit
a97034fc8b
2 changed files with 7 additions and 2 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// A basic set implementation for strings.
|
||||
|
@ -616,7 +617,7 @@ func (parser *arguments) parseCommandLine() (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
//parses input for number menus
|
||||
//parses input for number menus splitted by spaces or commas
|
||||
//supports individual selection: 1 2 3 4
|
||||
//supports range selections: 1-4 10-20
|
||||
//supports negation: ^1 ^1-4
|
||||
|
@ -632,7 +633,9 @@ func parseNumberMenu(input string) (intRanges, intRanges, stringSet, stringSet)
|
|||
otherInclude := make(stringSet)
|
||||
otherExclude := make(stringSet)
|
||||
|
||||
words := strings.Fields(input)
|
||||
words := strings.FieldsFunc(input, func(c rune) bool {
|
||||
return unicode.IsSpace(c) || c == ','
|
||||
})
|
||||
|
||||
for _, word := range words {
|
||||
var num1 int
|
||||
|
|
|
@ -65,6 +65,7 @@ func TestParseNumberMenu(t *testing.T) {
|
|||
"abort all none",
|
||||
"a-b ^a-b ^abort",
|
||||
"1\t2 3 4\t\t \t 5",
|
||||
"1 2,3, 4, 5,6 ,7 ,8",
|
||||
"",
|
||||
" \t ",
|
||||
"A B C D E",
|
||||
|
@ -78,6 +79,7 @@ func TestParseNumberMenu(t *testing.T) {
|
|||
{intRanges{}, intRanges{}, makeStringSet("abort", "all", "none"), make(stringSet)},
|
||||
{intRanges{}, intRanges{}, makeStringSet("a-b"), makeStringSet("abort", "a-b")},
|
||||
{intRanges{makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), makeIntRange(5, 5)}, intRanges{}, make(stringSet), make(stringSet)},
|
||||
{intRanges{makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), makeIntRange(5, 5), makeIntRange(6, 6), makeIntRange(7, 7), makeIntRange(8, 8)}, intRanges{}, make(stringSet), make(stringSet)},
|
||||
{intRanges{}, intRanges{}, make(stringSet), make(stringSet)},
|
||||
{intRanges{}, intRanges{}, make(stringSet), make(stringSet)},
|
||||
{intRanges{}, intRanges{}, makeStringSet("a", "b", "c", "d", "e"), make(stringSet)},
|
||||
|
|
Loading…
Reference in a new issue