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

Function extractArgs

Extension/src/common.ts:1009–1097  ·  view source on GitHub ↗
(argsString: string)

Source from the content-addressed store, hash-verified

1007}
1008
1009function extractArgs(argsString: string): string[] {
1010 argsString = argsString.trim();
1011 if (os.platform() === 'win32') {
1012 argsString = resolveWindowsEnvironmentVariables(argsString);
1013 const result: string[] = [];
1014 let currentArg: string = "";
1015 let isInQuote: boolean = false;
1016 let wasInQuote: boolean = false;
1017 let i: number = 0;
1018 while (i < argsString.length) {
1019 let c: string = argsString[i];
1020 if (c === '\"') {
1021 if (!isInQuote) {
1022 isInQuote = true;
1023 wasInQuote = true;
1024 ++i;
1025 continue;
1026 }
1027 // Need to peek at next character.
1028 if (++i === argsString.length) {
1029 break;
1030 }
1031 c = argsString[i];
1032 if (c !== '\"') {
1033 isInQuote = false;
1034 }
1035 // Fall through. If c was a quote character, it will be added as a literal.
1036 }
1037 if (c === '\\') {
1038 let backslashCount: number = 1;
1039 let reachedEnd: boolean = true;
1040 while (++i !== argsString.length) {
1041 c = argsString[i];
1042 if (c !== '\\') {
1043 reachedEnd = false;
1044 break;
1045 }
1046 ++backslashCount;
1047 }
1048 const still_escaping: boolean = (backslashCount % 2) !== 0;
1049 if (!reachedEnd && c === '\"') {
1050 backslashCount = Math.floor(backslashCount / 2);
1051 }
1052 while (backslashCount--) {
1053 currentArg += '\\';
1054 }
1055 if (reachedEnd) {
1056 break;
1057 }
1058 // If not still escaping and a quote was found, it needs to be handled above.
1059 if (!still_escaping && c === '\"') {
1060 continue;
1061 }
1062 // Otherwise, fall through to handle c as a literal.
1063 }
1064 if (c === ' ' || c === '\t' || c === '\r' || c === '\n') {
1065 if (!isInQuote) {
1066 if (currentArg !== "" || wasInQuote) {

Callers 2

trimLegacyQuotesFunction · 0.70

Calls 5

getExtensionFilePathFunction · 0.85
trimMethod · 0.80
pushMethod · 0.80
toStringMethod · 0.80

Tested by

no test coverage detected