MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / tokenizeCommandLine

Function tokenizeCommandLine

Source/3rdParty/bx/src/commandline.cpp:14–140  ·  view source on GitHub ↗

Reference(s): - https://web.archive.org/web/20180629044234/https://msdn.microsoft.com/en-us/library/a1y7w461.aspx

Source from the content-addressed store, hash-verified

12 // - https://web.archive.org/web/20180629044234/https://msdn.microsoft.com/en-us/library/a1y7w461.aspx
13 //
14 StringView tokenizeCommandLine(const StringView& _commandLine, char* _buffer, uint32_t& _bufferSize, int32_t& _argc, char* _argv[], int32_t _maxArgvs, char _term)
15 {
16 int32_t argc = 0;
17 const char* curr = _commandLine.getPtr();
18 const char* end = _commandLine.getTerm();
19 char* currOut = _buffer;
20 char term = ' ';
21 bool sub = false;
22
23 enum ParserState
24 {
25 SkipWhitespace,
26 SetTerm,
27 Copy,
28 Escape,
29 End,
30 };
31
32 ParserState state = SkipWhitespace;
33
34 while (end != curr
35 && _term != *curr
36 && argc < _maxArgvs)
37 {
38 switch (state)
39 {
40 case SkipWhitespace:
41 for (; isSpace(*curr) && *curr!=_term; ++curr) {}; // skip whitespace
42 state = SetTerm;
43 break;
44
45 case SetTerm:
46 if ('"' == *curr)
47 {
48 term = '"';
49 ++curr; // skip beginning quote
50 }
51 else
52 {
53 term = ' ';
54 }
55
56 _argv[argc] = currOut;
57 ++argc;
58
59 state = Copy;
60 break;
61
62 case Copy:
63 if ('\\' == *curr)
64 {
65 state = Escape;
66 }
67 else if ('"' == *curr
68 && '"' != term)
69 {
70 sub = !sub;
71 }

Callers

nothing calls this directly

Calls 2

isSpaceFunction · 0.70
StringViewClass · 0.50

Tested by

no test coverage detected