mirror of
https://github.com/Jguer/yay.git
synced 2025-10-08 00:04:37 -04:00
Merge pull request #524 from AlexWayfer/support_commas_in_parse_number_menu
Support commas in parserNumberMenu
This commit is contained in:
commit
a97034fc8b
@ -8,6 +8,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A basic set implementation for strings.
|
// A basic set implementation for strings.
|
||||||
@ -616,7 +617,7 @@ func (parser *arguments) parseCommandLine() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//parses input for number menus
|
//parses input for number menus splitted by spaces or commas
|
||||||
//supports individual selection: 1 2 3 4
|
//supports individual selection: 1 2 3 4
|
||||||
//supports range selections: 1-4 10-20
|
//supports range selections: 1-4 10-20
|
||||||
//supports negation: ^1 ^1-4
|
//supports negation: ^1 ^1-4
|
||||||
@ -632,7 +633,9 @@ func parseNumberMenu(input string) (intRanges, intRanges, stringSet, stringSet)
|
|||||||
otherInclude := make(stringSet)
|
otherInclude := make(stringSet)
|
||||||
otherExclude := 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 {
|
for _, word := range words {
|
||||||
var num1 int
|
var num1 int
|
||||||
|
@ -65,6 +65,7 @@ func TestParseNumberMenu(t *testing.T) {
|
|||||||
"abort all none",
|
"abort all none",
|
||||||
"a-b ^a-b ^abort",
|
"a-b ^a-b ^abort",
|
||||||
"1\t2 3 4\t\t \t 5",
|
"1\t2 3 4\t\t \t 5",
|
||||||
|
"1 2,3, 4, 5,6 ,7 ,8",
|
||||||
"",
|
"",
|
||||||
" \t ",
|
" \t ",
|
||||||
"A B C D E",
|
"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("abort", "all", "none"), make(stringSet)},
|
||||||
{intRanges{}, intRanges{}, makeStringSet("a-b"), makeStringSet("abort", "a-b")},
|
{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)}, 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{}, make(stringSet), make(stringSet)},
|
{intRanges{}, intRanges{}, make(stringSet), make(stringSet)},
|
||||||
{intRanges{}, intRanges{}, makeStringSet("a", "b", "c", "d", "e"), make(stringSet)},
|
{intRanges{}, intRanges{}, makeStringSet("a", "b", "c", "d", "e"), make(stringSet)},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user