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

Function posix

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

Source from the content-addressed store, hash-verified

81}
82
83function posix(argsString: string): string[] {
84 // inspired by https://github.com/migueldeicaza/mono-wasm-libc/blob/96eaa7afc23cd675358595e1dd6ab4b6c8f9f07f/src/misc/wordexp.c#L32
85 let doubleQuote = false;
86 let singleQuote = false;
87 let paren = 0;
88 let brace = 0;
89
90 let arg = '';
91 let args = ['printf', `%s\\\\n`];
92
93 for (let i = 0; i < argsString.length; ++i) {
94 const char = argsString[i];
95 const next = argsString[i + 1];
96
97 switch (char) {
98
99 case '\\':
100 if (!singleQuote) {
101 if (next === '\\') {
102 arg += '\\\\\\\\';
103 ++i;
104 continue;
105 }
106 arg += `\\${next}`;
107 ++i;
108 continue;
109 }
110 break;
111
112 case '\'':
113 if (!doubleQuote) {
114 singleQuote = !singleQuote;
115 }
116 arg += "'";
117 continue;
118
119 case '"':
120 if (!singleQuote) {
121 doubleQuote = !doubleQuote;
122 }
123 arg += '"';
124 continue;
125 case '(':
126 if (!singleQuote && !doubleQuote) {
127 ++paren;
128 }
129 break;
130 case ')':
131 if (!singleQuote && !doubleQuote) {
132 --paren;
133 }
134 break;
135
136 case '}':
137 if (!singleQuote && !doubleQuote && !brace) {
138 throw new Error(`Unsupported character: ${char}`);
139 }
140 brace--;

Callers 1

extractArgsFunction · 0.85

Calls 2

pushMethod · 0.80
toStringMethod · 0.80

Tested by

no test coverage detected