Parse the input string (commands).
45 {
46 std::vector<CommandToken> tokens;
47 std::string current;
50
51
52
53
54 std::string input = ConstInput;
55 for (SIZE_T i = 0; i < input.length(); ++i)
56 {
58
59 if (c == '/')
60 {
61
62
63
64 if (!InQuotes)
65 {
66 SIZE_T j = i;
68
69 if (c2 == '/')
70 {
71
72
73
74 SIZE_T StrLitEnd = 0;
75 SIZE_T StrLitBeg = input.find("\"", i);
76 if (StrLitBeg != std::string::npos)
77 {
78 if (i)
79 {
80 if (input[i - 1] != '\\')
81 {
82 StrLitEnd = input.find("\"", StrLitBeg + 1);
83 if (StrLitEnd != std::string::npos)
84 {
85 std::string StrLit(input.substr(i, StrLitEnd - i + 1));
86 }
87 }
88 }
89 else
90 {
91 StrLitEnd = input.find("\"", StrLitBeg + 1);
92 if (StrLitEnd != std::string::npos)
93 {
94 std::string StrLit(input.substr(i, StrLitEnd - i + 1));
95 }
96 }
97 }
98
99
100
101
103 SIZE_T CloseBrktPos = 0;
104 if (IdxBracket)
105 {
106
107
108
109 auto pos = (StrLitEnd > i) ? StrLitEnd : i;
110 for (CloseBrktPos = input.find("}", pos); CloseBrktPos != std::string::npos;)
111 {
112 CloseBrktPos = input.find("}", CloseBrktPos);
113 if (input[CloseBrktPos - 1] == '\\')
114 {
115 input.erase(CloseBrktPos - 1, 1);
116 CloseBrktPos += 1;
117 }
118 else
119 {
120 break;
121 }
122 }
123 }
124 else
125 {
126 CloseBrktPos = std::string::npos;
127 }
128
129 SIZE_T NewLineSrtPos = input.find("\\n", i);
130 if (StrLitBeg && StrLitBeg <= NewLineSrtPos && NewLineSrtPos <= StrLitEnd)
131 {
132 NewLineSrtPos = std::string::npos;
133 }
134 SIZE_T NewLineChrPos = input.find('\n', i);
135
136 std::vector<SIZE_T> PosVec = {CloseBrktPos, NewLineSrtPos, NewLineChrPos};
137
138 auto min = *(min_element(PosVec.begin(), PosVec.end()));
139
140 if (min != std::string::npos && input[min - 1] != '\\')
141 {
142
143
144
145 std::string comment(input.substr(i, min - i));
146
147
148
149
150 if (IdxBracket)
151 {
152 current += comment;
153 }
154
155
156
157
158 auto diff = (min > i) ? (min - i) : (i - min);
159 i = i + diff - 1;
160
161 continue;
162 }
163 else
164 {
166 if (NewLineSrtPos != std::string::npos)
167 {
168 IsNewLineEsc = input[NewLineSrtPos - 1] == '\\';
169 }
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220 std::string comment(input.substr(i, input.size()));
221
222
223 if (IsNewLineEsc)
224 {
225 SIZE_T start_pos = 0;
226 while ((start_pos = comment.find("\\\\n", start_pos)) != std::string::npos)
227 {
228 comment.replace(start_pos, 3, "\\n");
229 start_pos += 2;
230 }
231
232 IsNewLineEsc =
FALSE;
233 }
234
235
236
237
238 if (IdxBracket)
239 {
240 current += comment;
241 }
242
243
244
245
246 i = i + (input.size() - i);
247
248 continue;
249 }
250
251 }
252 else if (c2 == '*')
253 {
254 SIZE_T EndPose = input.find("*/", i + 2);
255
256 if (EndPose != std::string::npos)
257 {
258
259
260
261 std::string comment(input.substr(i, EndPose - i + 2));
262
263
264
265
266 if (IdxBracket)
267 {
268 current += comment;
269 }
270
271
272
273
274 i = (i + (EndPose - i)) + 1;
275
276 continue;
277 }
278 else
279 {
280
281 }
282 }
283 }
284 }
285
286 if (InQuotes)
287 {
288 if (c == '"')
289 {
290 if (input[i - 1] != '\\')
291 {
293
294
295
296
297 if (!IdxBracket)
298 {
299 AddStringToken(tokens, current,
TRUE);
300 current.clear();
301 continue;
302 }
303 else
304 {
305 current += c;
306 continue;
307 }
308
309
310
311 }
312 else
313 {
314 input.erase(i - 1, 1);
315 i--;
316
317
318
319
320 if (!IdxBracket)
321 {
322 current.pop_back();
323 }
324 current += c;
325 continue;
326 }
327 }
328 }
329
330 if (c == '}')
331 {
332 if (input[i - 1] != '\\')
333 {
334 if (IdxBracket)
335 {
336 if (!InQuotes)
337 {
338 IdxBracket--;
339 }
340
341 if (!IdxBracket)
342 {
343 AddBracketStringToken(tokens, current);
344 current.clear();
345
346 continue;
347 }
348 }
349 }
350 else if (!InQuotes)
351 {
352 input.erase(i - 1, 1);
353 i--;
354 current.pop_back();
355
356 }
357 }
358
359 if (((c == ' ' && !InQuotes) || c == ' ') && !InQuotes && !IdxBracket)
360 {
361 if (!current.empty() && current != " ")
362 {
363 AddToken(tokens, current);
364 current.clear();
365
366 continue;
367 }
368 continue;
369 }
370 else if (c == '"')
371 {
372 if (i)
373 {
374 if (input[i - 1] != ' ' && !IdxBracket && !current.empty() && !InQuotes)
375 {
376 AddStringToken(tokens, current);
377 current.clear();
378 }
379
380 if (input[i - 1] != '\\')
381 {
383 if (!IdxBracket)
384 {
385 continue;
386 }
387 }
388 }
389 else
390 {
392 if (!IdxBracket)
393 {
394 continue;
395 }
396 }
397 }
398 else if (c == '{' && !InQuotes)
399 {
400 if (i)
401 {
402 if (input[i - 1] != '\\')
403 {
404 if (input[i - 1] != ' ' && !IdxBracket)
405 {
406 AddToken(tokens, current);
407 current.clear();
408 }
409
410 IdxBracket++;
411 if (IdxBracket == 1)
412 continue;
413 }
414 else
415 {
416 input.erase(i - 1, 1);
417 i--;
418 current.pop_back();
419
420 }
421 }
422 else
423 {
424 IdxBracket++;
425 if (IdxBracket == 1)
426 continue;
427 }
428 }
429
430
431
432
433 if (c == '\\' && !InQuotes)
434 {
435 if (current.empty() && input[i + 1] == 'n')
436 {
437 i++;
438 continue;
439 }
440 }
441
442 current += c;
443 }
444
445 if (!current.empty() && current != " ")
446 {
447 AddToken(tokens, current);
448 }
449
450 if (IdxBracket)
451 {
452
453 }
454
455 if (InQuotes)
456 {
457
458 }
459
460 return tokens;
461 }