@@ -25,6 +25,17 @@ function isCombinedCommandFlag(token: string): boolean {
|
25 | 25 | return parseCombinedCommandFlag(token) !== null; |
26 | 26 | } |
27 | 27 | |
| 28 | +function countSeparateValueOptionChars(token: string): number { |
| 29 | +let count = 0; |
| 30 | +for (let index = 1; index < token.length; index += 1) { |
| 31 | +const char = token[index]; |
| 32 | +if (char === "o" || char === "O") { |
| 33 | +count += 1; |
| 34 | +} |
| 35 | +} |
| 36 | +return count; |
| 37 | +} |
| 38 | + |
28 | 39 | function parseCombinedCommandFlag( |
29 | 40 | token: string, |
30 | 41 | ): { attachedCommand: string | null; separateValueCount: number } | null { |
@@ -42,7 +53,7 @@ function parseCombinedCommandFlag(
|
42 | 53 | } |
43 | 54 | return { |
44 | 55 | attachedCommand: null, |
45 | | -separateValueCount: [...optionChars].filter((char) => char === "o" || char === "O").length, |
| 56 | +separateValueCount: countSeparateValueOptionChars(token), |
46 | 57 | }; |
47 | 58 | } |
48 | 59 | |
@@ -55,7 +66,7 @@ function combinedSeparateValueOptionCount(token: string): number {
|
55 | 66 | ) { |
56 | 67 | return 0; |
57 | 68 | } |
58 | | -return [...token.slice(1)].filter((char) => char === "o" || char === "O").length; |
| 69 | +return countSeparateValueOptionChars(token); |
59 | 70 | } |
60 | 71 | |
61 | 72 | function consumesSeparateValue(token: string): boolean { |
@@ -70,8 +81,17 @@ function isPosixShortOption(token: string, option: string): boolean {
|
70 | 81 | if (token.length < 2 || token[0] !== "-" || token[1] === "-") { |
71 | 82 | return false; |
72 | 83 | } |
73 | | -const optionChars = token.slice(1); |
74 | | -return !optionChars.includes("-") && optionChars.includes(option); |
| 84 | +let hasOption = false; |
| 85 | +for (let index = 1; index < token.length; index += 1) { |
| 86 | +const char = token[index]; |
| 87 | +if (char === "-") { |
| 88 | +return false; |
| 89 | +} |
| 90 | +if (char === option) { |
| 91 | +hasOption = true; |
| 92 | +} |
| 93 | +} |
| 94 | +return hasOption; |
75 | 95 | } |
76 | 96 | |
77 | 97 | function advancePosixInlineOptionScan(token: string): number { |
|