MCPcopy Index your code
hub / github.com/microsoft/vscode-cpptools / windows

Function windows

Extension/src/Utility/Process/commandLine.ts:10–81  ·  view source on GitHub ↗
(argsString: string)

Source from the content-addressed store, hash-verified

8import { resolveEnvironmentVariables } from '../System/environment';
9
10function windows(argsString: string): string[] {
11 argsString = resolveEnvironmentVariables(argsString);
12 const result: string[] = [];
13 let currentArg: string = "";
14 let isInQuote: boolean = false;
15 let wasInQuote: boolean = false;
16 let i: number = 0;
17 while (i < argsString.length) {
18 let c: string = argsString[i];
19 if (c === '\"') {
20 if (!isInQuote) {
21 isInQuote = true;
22 wasInQuote = true;
23 ++i;
24 continue;
25 }
26 // Need to peek at next character.
27 if (++i === argsString.length) {
28 break;
29 }
30 c = argsString[i];
31 if (c !== '\"') {
32 isInQuote = false;
33 }
34 // Fall through. If c was a quote character, it will be added as a literal.
35 }
36 if (c === '\\') {
37 let backslashCount: number = 1;
38 let reachedEnd: boolean = true;
39 while (++i !== argsString.length) {
40 c = argsString[i];
41 if (c !== '\\') {
42 reachedEnd = false;
43 break;
44 }
45 ++backslashCount;
46 }
47 const still_escaping: boolean = (backslashCount % 2) !== 0;
48 if (!reachedEnd && c === '\"') {
49 backslashCount = Math.floor(backslashCount / 2);
50 }
51 while (backslashCount--) {
52 currentArg += '\\';
53 }
54 if (reachedEnd) {
55 break;
56 }
57 // If not still escaping and a quote was found, it needs to be handled above.
58 if (!still_escaping && c === '\"') {
59 continue;
60 }
61 // Otherwise, fall through to handle c as a literal.
62 }
63 if (c === ' ' || c === '\t' || c === '\r' || c === '\n') {
64 if (!isInQuote) {
65 if (currentArg !== "" || wasInQuote) {
66 wasInQuote = false;
67 result.push(currentArg);

Callers 1

extractArgsFunction · 0.85

Calls 2

pushMethod · 0.80

Tested by

no test coverage detected