1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "CommandParser.h"
17
18 #include <algorithm>
19 #include <cstdlib>
20 #include <regex>
21 #include "FileSystem.h"
22 #include "PreviewerEngineLog.h"
23 #include "TraceTool.h"
24
25 using namespace std;
26 CommandParser* CommandParser::example = nullptr;
CommandParser()27 CommandParser::CommandParser()
28 : isSendJSHeap(true),
29 orignalResolutionWidth(0),
30 orignalResolutionHeight(0),
31 compressionResolutionWidth(0),
32 compressionResolutionHeight(0),
33 jsHeapSize(MAX_JSHEAPSIZE),
34 deviceType("liteWearable"),
35 screenShape("circle"),
36 appName("undefined"),
37 configPath(""),
38 isRegionRefresh(false),
39 isCardDisplay(false),
40 projectID(""),
41 screenMode(CommandParser::ScreenMode::DYNAMIC),
42 configChanges(""),
43 appResourcePath(""),
44 projectModel("FA"),
45 pages("main_pages"),
46 containerSdkPath("")
47 {
48 Register("-j", 1, "Launch the js app in <directory>.");
49 Register("-n", 1, "Set the js app name show on <window title>.");
50 Register("-d", 0, "Run in debug mode and start debug server.");
51 Register("-p", 1, "Config debug server to listen <port>.");
52 Register("-s", 1, "Local socket name <socket-name> for command line interface.");
53 Register("-v", 0, "Print the periviewer engine version.");
54 Register("-h", 0, "Print the usage help.");
55 Register("-or", 2, "Original resolution <width> <height>"); // 2 arguments
56 Register("-cr", 2, "Compression resolution <width> <height>"); // 2 arguments
57 Register("-f", 1, "config path <path>");
58 Register("-hs", 1, "JS Heap <size>");
59 Register("-hf", 1, "JS Send Heap <flag>");
60 Register("-shape", 1, "Screen shape <shape>");
61 Register("-device", 1, "Device type <type>");
62 Register("-url", 1, "temp url");
63 Register("-refresh", 1, "Screen <refresh mode>, support region and full");
64 Register("-card", 1, "Controls the display <type> to switch between the app and card.");
65 Register("-projectID", 1, "the ID of current project.");
66 Register("-ts", 1, "Trace socket name");
67 Register("-cm", 1, "Set colormode for the theme.");
68 Register("-o", 1, "Set orientation for the display.");
69 Register("-lws", 1, "Listening port of WebSocket");
70 Register("-av", 1, "Set ace version.");
71 Register("-l", 1, "Set language for startParam.");
72 Register("-sd", 1, "Set screenDensity for Previewer.");
73 Register("-sm", 1, "Set Screen picture transport mode, support dynamic and static");
74 Register("-cc", 1, "Set Resource configChanges.");
75 Register("-arp", 1, "Set App ResourcePath.");
76 Register("-fs", 1, "Select Fonts sources.");
77 Register("-pm", 1, "Set project model type.");
78 Register("-pages", 1, "Set project's router config file path.");
79 Register("-hsp", 1, "Set container sdk path.");
80 }
81
GetInstance()82 CommandParser& CommandParser::GetInstance()
83 {
84 static CommandParser instance;
85 return instance;
86 }
87
88 /*
89 * Parse user input and check parameter validity
90 */
ProcessCommand(std::vector<std::string> strs)91 bool CommandParser::ProcessCommand(std::vector<std::string> strs)
92 {
93 ProcessingCommand(strs);
94
95 if (IsSet("v")) {
96 ELOG("ProcessCommand Set -v!");
97 return false;
98 }
99
100 if (IsSet("h")) {
101 ELOG("ProcessCommand Set -h!");
102 ELOG(HelpText().c_str());
103 return false;
104 }
105
106 return true;
107 }
108
IsCommandValid()109 bool CommandParser::IsCommandValid()
110 {
111 bool partRet = IsDebugPortValid() && IsAppPathValid() && IsAppNameValid() && IsResolutionValid();
112 partRet = partRet && IsConfigPathValid() && IsJsHeapValid() && IsJsHeapFlagValid() && IsScreenShapeValid();
113 partRet = partRet && IsDeviceValid() && IsUrlValid() && IsRefreshValid() && IsCardValid() && IsProjectIDValid();
114 partRet = partRet && IsColorModeValid() && IsOrientationValid() && IsWebSocketPortValid() && IsAceVersionValid();
115 partRet = partRet && IsScreenModeValid() && IsAppResourcePathValid();
116 partRet = partRet && IsProjectModelValid() && IsPagesValid() && IsContainerSdkPathValid();
117 if (partRet) {
118 return true;
119 }
120 ELOG(errorInfo.c_str());
121 ILOG(HelpText().c_str());
122 TraceTool::GetInstance().HandleTrace("Invalid startup parameters");
123 return false;
124 }
125
IsSet(string key)126 bool CommandParser::IsSet(string key)
127 {
128 if (argsMap.find(string("-") + key) == argsMap.end()) {
129 return false;
130 }
131 return true;
132 }
133
Value(string key)134 string CommandParser::Value(string key)
135 {
136 auto args = argsMap[string("-") + key];
137 if (args.size() > 0) {
138 return args[0];
139 }
140 return string();
141 }
142
Values(string key)143 vector<string> CommandParser::Values(string key)
144 {
145 if (argsMap.find(key) == argsMap.end()) {
146 return vector<string>();
147 }
148 vector<string> args = argsMap[key];
149 return args;
150 }
151
Register(string key,uint32_t argc,string help)152 void CommandParser::Register(string key, uint32_t argc, string help)
153 {
154 regsArgsCountMap[key] = argc;
155 regsHelpMap[key] = help;
156 }
157
IsResolutionValid(int32_t resolution) const158 bool CommandParser::IsResolutionValid(int32_t resolution) const
159 {
160 if (resolution >= MIN_RESOLUTION && resolution <= MAX_RESOLUTION) {
161 return true;
162 }
163 return false;
164 }
165
GetDeviceType() const166 string CommandParser::GetDeviceType() const
167 {
168 return deviceType;
169 }
170
IsRegionRefresh() const171 bool CommandParser::IsRegionRefresh() const
172 {
173 return isRegionRefresh;
174 }
175
IsCardDisplay() const176 bool CommandParser::IsCardDisplay() const
177 {
178 return isCardDisplay;
179 }
180
GetConfigPath() const181 string CommandParser::GetConfigPath() const
182 {
183 return configPath;
184 }
185
GetProjectID() const186 string CommandParser::GetProjectID() const
187 {
188 return projectID;
189 }
190
GetAppResourcePath() const191 string CommandParser::GetAppResourcePath() const
192 {
193 return appResourcePath;
194 }
195
GetScreenShape() const196 string CommandParser::GetScreenShape() const
197 {
198 return screenShape;
199 }
200
GetProjectModel() const201 string CommandParser::GetProjectModel() const
202 {
203 return projectModel;
204 }
205
GetPages() const206 string CommandParser::GetPages() const
207 {
208 return pages;
209 }
210
GetContainerSdkPath() const211 string CommandParser::GetContainerSdkPath() const
212 {
213 return containerSdkPath;
214 }
215
GetScreenMode() const216 CommandParser::ScreenMode CommandParser::GetScreenMode() const
217 {
218 return screenMode;
219 }
220
GetConfigChanges() const221 string CommandParser::GetConfigChanges() const
222 {
223 return configChanges;
224 }
225
GetOrignalResolutionWidth() const226 int32_t CommandParser::GetOrignalResolutionWidth() const
227 {
228 return orignalResolutionWidth;
229 }
230
GetOrignalResolutionHeight() const231 int32_t CommandParser::GetOrignalResolutionHeight() const
232 {
233 return orignalResolutionHeight;
234 }
235
GetCompressionResolutionWidth() const236 int32_t CommandParser::GetCompressionResolutionWidth() const
237 {
238 return compressionResolutionWidth;
239 }
240
GetCompressionResolutionHeight() const241 int32_t CommandParser::GetCompressionResolutionHeight() const
242 {
243 return compressionResolutionHeight;
244 }
245
GetJsHeapSize() const246 uint32_t CommandParser::GetJsHeapSize() const
247 {
248 return jsHeapSize;
249 }
250
GetAppName() const251 string CommandParser::GetAppName() const
252 {
253 return appName;
254 }
255
IsSendJSHeap() const256 bool CommandParser::IsSendJSHeap() const
257 {
258 return isSendJSHeap;
259 }
260
IsDebugPortValid()261 bool CommandParser::IsDebugPortValid()
262 {
263 if (IsSet("p")) {
264 if (CheckParamInvalidity(Value("p"), true)) {
265 errorInfo = "Launch -p parameters is not match regex.";
266 return false;
267 }
268 int port = atoi(Value("p").c_str());
269 if (port < MIN_PORT || port > MAX_PORT) {
270 errorInfo =
271 string("Debug server port out of range: " + to_string(MIN_PORT) + "-" + to_string(MAX_PORT) + ".");
272 ELOG("Launch -p parameters abnormal!");
273 return false;
274 }
275 }
276 ILOG("CommandParser debug port: %s", Value("p").c_str());
277 return true;
278 }
279
IsAppPathValid()280 bool CommandParser::IsAppPathValid()
281 {
282 if (!IsSet("j")) {
283 errorInfo = string("No app path specified.");
284 ELOG("Launch -j parameters abnormal!");
285 return false;
286 }
287 string path = Value("j");
288 if (!FileSystem::IsDirectoryExists(path)) {
289 errorInfo = string("Js app path not exist.");
290 ELOG("Launch -j parameters abnormal!");
291 return false;
292 }
293
294 return true;
295 }
296
IsAppNameValid()297 bool CommandParser::IsAppNameValid()
298 {
299 if (IsSet("n")) {
300 if (CheckParamInvalidity(Value("n"), false)) {
301 errorInfo = "Launch -n parameters is not match regex.";
302 return false;
303 }
304 size_t size = Value("n").size();
305 if (size > MAX_NAME_LENGTH) {
306 errorInfo = string("Js app name it too long, max: " + to_string(MAX_NAME_LENGTH) + ".");
307 return false;
308 }
309 appName = Value("n");
310 }
311 ILOG("CommandParser app name: %s", appName.c_str());
312 return true;
313 }
314
IsResolutionValid()315 bool CommandParser::IsResolutionValid()
316 {
317 if (IsSet("or") && IsSet("cr")) {
318 if (IsResolutionArgValid(string("-or")) && IsResolutionArgValid(string("-cr"))) {
319 orignalResolutionWidth = atoi(Values("-or")[0].c_str());
320 orignalResolutionHeight = atoi(Values("-or")[1].c_str());
321 compressionResolutionWidth = atoi(Values("-cr")[0].c_str());
322 compressionResolutionHeight = atoi(Values("-cr")[1].c_str());
323 ILOG("CommandParser resolution: %d %d %d %d", orignalResolutionWidth, orignalResolutionHeight,
324 compressionResolutionWidth, compressionResolutionHeight);
325 return true;
326 }
327 ELOG("Launch -cr/-or parameters abnormal!");
328 return false;
329 }
330 ELOG("Launch -cr/-or parameters abnormal!");
331 errorInfo = string("Origin resolution and compress resolution must be setted.");
332 return false;
333 }
334
IsJsHeapValid()335 bool CommandParser::IsJsHeapValid()
336 {
337 if (IsSet("hs")) {
338 if (CheckParamInvalidity(Value("hs"), true)) {
339 errorInfo = "Launch -hs parameters is not match regex.";
340 return false;
341 }
342 int size = atoi(Value("hs").c_str());
343 if (size < MIN_JSHEAPSIZE || size > MAX_JSHEAPSIZE) {
344 errorInfo = string("JS heap size out of range: " + to_string(MIN_JSHEAPSIZE) + "-" +
345 to_string(MAX_JSHEAPSIZE) + ".");
346 ELOG("Launch -hs parameters abnormal!");
347 return false;
348 }
349 jsHeapSize = static_cast<uint32_t>(size);
350 }
351 ILOG("CommandParser js heap: %d", jsHeapSize);
352 return true;
353 }
354
IsJsHeapFlagValid()355 bool CommandParser::IsJsHeapFlagValid()
356 {
357 if (IsSet("hf")) {
358 string flag = Value("hf");
359 if (flag != "true" && flag != "false") {
360 errorInfo = string("JS heap flag suported: true or false");
361 ELOG("Launch -hs parameters abnormal!");
362 return false;
363 }
364 isSendJSHeap = (flag == "true");
365 }
366 ILOG("CommandParser is send JS heap: %d", isSendJSHeap);
367 return true;
368 }
369
IsScreenShapeValid()370 bool CommandParser::IsScreenShapeValid()
371 {
372 if (IsSet("shape")) {
373 string shape = Value("shape");
374 if (shape != "rect" && shape != "circle") {
375 errorInfo = string("Screen shape suported: rect or circle");
376 ELOG("The current device does not support, please upgrade the SDK!");
377 return false;
378 }
379 screenShape = shape;
380 }
381 ILOG("CommandParser screen shape: %s", screenShape.c_str());
382 return true;
383 }
384
IsDeviceValid()385 bool CommandParser::IsDeviceValid()
386 {
387 if (IsSet("device")) {
388 auto iter = find(supportedDevices.begin(), supportedDevices.end(), Value("device"));
389 if (iter == supportedDevices.end()) {
390 errorInfo += string("Device type unsupport, please upgrade the Previewer SDK!");
391 ELOG("Device type unsupport!");
392 return false;
393 }
394 }
395 deviceType = Value("device");
396 ILOG("CommandParser device: %s", deviceType.c_str());
397 return true;
398 }
399
IsUrlValid()400 bool CommandParser::IsUrlValid()
401 {
402 urlPath = Value("url");
403 if (urlPath.empty()) {
404 errorInfo = "Launch -url parameters is empty.";
405 return false;
406 }
407 ILOG("CommandParser url: %s", urlPath.c_str());
408 return true;
409 }
410
IsConfigPathValid()411 bool CommandParser::IsConfigPathValid()
412 {
413 if (!IsSet("f")) {
414 return true;
415 }
416
417 string path = Value("f");
418 if (!FileSystem::IsFileExists(path)) {
419 errorInfo = string("The configuration file path does not exist.");
420 ELOG("Launch -f parameters abnormal!");
421 return false;
422 }
423 configPath = path;
424 return true;
425 }
426
IsAppResourcePathValid()427 bool CommandParser::IsAppResourcePathValid()
428 {
429 if (!IsSet("arp")) {
430 return true;
431 }
432
433 string path = Value("arp");
434 if (!FileSystem::IsDirectoryExists(path)) {
435 errorInfo = string("The configuration appResource path does not exist.");
436 ELOG("Launch -arp parameters abnormal!");
437 return false;
438 }
439 appResourcePath = path;
440 return true;
441 }
442
IsProjectModelValid()443 bool CommandParser::IsProjectModelValid()
444 {
445 if (!IsSet("pm")) {
446 return true;
447 }
448
449 string projectModelStr = Value("pm");
450 auto iter = find(projectModels.begin(), projectModels.end(), projectModelStr);
451 if (iter == projectModels.end()) {
452 errorInfo = string("The project model does not exist.");
453 ELOG("Launch -pm parameters abnormal!");
454 return false;
455 }
456
457 projectModel = projectModelStr;
458 ILOG("CommandParser projectModel: %s", projectModelStr.c_str());
459 return true;
460 }
461
IsPagesValid()462 bool CommandParser::IsPagesValid()
463 {
464 if (!IsSet("pages")) {
465 return true;
466 }
467 pages = Value("pages");
468 if (CheckParamInvalidity(pages, false)) {
469 errorInfo = "Launch -pages parameters is not match regex.";
470 return false;
471 }
472 ILOG("CommandParser pages: %s", pages.c_str());
473 return true;
474 }
475
IsResolutionArgValid(string command)476 bool CommandParser::IsResolutionArgValid(string command)
477 {
478 vector<string> value = Values(command);
479 uint32_t size = regsArgsCountMap[command];
480 if (value.size() != size) {
481 errorInfo = string("Invalid argument's count.");
482 return false;
483 }
484 if (IsResolutionRangeValid(value[0]) && IsResolutionRangeValid(value[1])) {
485 return true;
486 }
487 return false;
488 }
489
IsResolutionRangeValid(string value)490 bool CommandParser::IsResolutionRangeValid(string value)
491 {
492 if (CheckParamInvalidity(value, true)) {
493 errorInfo = "Launch -or/-cr parameters is not match regex.";
494 return false;
495 }
496 int32_t temp = atoi(value.c_str());
497 if (!IsResolutionValid(temp)) {
498 errorInfo = string("Resolution range " + to_string(MIN_RESOLUTION) + "-" + to_string(MAX_RESOLUTION) + ".");
499 return false;
500 }
501 return true;
502 }
503
IsRefreshValid()504 bool CommandParser::IsRefreshValid()
505 {
506 if (!IsSet("refresh")) {
507 return true;
508 }
509
510 string refresh = Value("refresh");
511 if (refresh != "region" && refresh != "full") {
512 errorInfo = string("The refresh argument unsupported.");
513 ELOG("Launch -refresh parameters abnormal!");
514 return false;
515 }
516 if (refresh == "region") {
517 isRegionRefresh = true;
518 }
519 return true;
520 }
521
IsCardValid()522 bool CommandParser::IsCardValid()
523 {
524 if (!IsSet("card")) {
525 return true;
526 }
527
528 string card = Value("card");
529 if (card != "true" && card != "false") {
530 errorInfo = string("The card argument unsupported.");
531 ELOG("Launch -card parameters abnormal!");
532 return false;
533 }
534
535 std::string devicetype = GetDeviceType();
536 auto iter = find(cardDisplayDevices.begin(), cardDisplayDevices.end(), devicetype);
537 if (iter != cardDisplayDevices.end() && card == "true") {
538 isCardDisplay = true;
539 }
540 return true;
541 }
542
IsProjectIDValid()543 bool CommandParser::IsProjectIDValid()
544 {
545 if (IsSet("projectID")) {
546 projectID = Value("projectID");
547 if (CheckParamInvalidity(projectID, true)) {
548 errorInfo = "Launch -projectID parameters is not match regex.";
549 return false;
550 }
551 }
552 return true;
553 }
554
IsColorModeValid()555 bool CommandParser::IsColorModeValid()
556 {
557 if (!IsSet("cm")) {
558 return true;
559 }
560
561 string colorMode = Value("cm");
562 if (colorMode != "dark" && colorMode != "light") {
563 errorInfo = string("The colormode argument unsupported.");
564 ELOG("Launch -cm parameters abnormal!");
565 return false;
566 }
567 return true;
568 }
569
IsAceVersionValid()570 bool CommandParser::IsAceVersionValid()
571 {
572 if (!IsSet("av")) {
573 return true;
574 }
575
576 string aceVersion = Value("av");
577 if (aceVersion != "ACE_1_0" && aceVersion != "ACE_2_0") {
578 errorInfo = string("The aceVersion argument unsupported.");
579 ELOG("Launch -av parameters abnormal!");
580 return false;
581 }
582 return true;
583 }
584
IsOrientationValid()585 bool CommandParser::IsOrientationValid()
586 {
587 if (!IsSet("o")) {
588 return true;
589 }
590
591 string orientation = Value("o");
592 if (orientation != "portrait" && orientation != "landscape") {
593 errorInfo = string("The orientation argument unsupported.");
594 ELOG("Launch -o parameters abnormal!");
595 return false;
596 }
597 return true;
598 }
599
IsWebSocketPortValid()600 bool CommandParser::IsWebSocketPortValid()
601 {
602 if (IsSet("lws")) {
603 if (CheckParamInvalidity(Value("lws"), true)) {
604 errorInfo = "Launch -lws parameters is not match regex.";
605 return false;
606 }
607 int port = atoi(Value("lws").c_str());
608 if (port < MIN_PORT || port > MAX_PORT) {
609 errorInfo = string("WebSocket listening port out of range: " + to_string(MIN_PORT) + "-" +
610 to_string(MAX_PORT) + ".");
611 ELOG("Launch -lws parameters abnormal!");
612 return false;
613 }
614 }
615 ILOG("CommandParser WebSocket listening port: %s", Value("lws").c_str());
616 return true;
617 }
618
IsScreenModeValid()619 bool CommandParser::IsScreenModeValid()
620 {
621 string mode("dynamic");
622 if (IsSet("sm")) {
623 mode = Value("sm");
624 if (mode != "dynamic" && mode != "static") {
625 errorInfo = string("Screen picture transport mode suported: dynamic or static");
626 ELOG("Launch -sm parameters abnormal!");
627 return false;
628 }
629 screenMode = (mode == "static" ? CommandParser::ScreenMode::STATIC :
630 CommandParser::ScreenMode::DYNAMIC);
631 }
632 ILOG("CommandParser screen mode: %s", mode.c_str());
633 return true;
634 }
635
IsLanguageValid()636 bool CommandParser::IsLanguageValid()
637 {
638 if (!IsSet("l")) {
639 return true;
640 }
641 string lan = Value("pages");
642 if (CheckParamInvalidity(lan, false)) {
643 errorInfo = "Launch -l parameters is not match regex.";
644 return false;
645 }
646 ILOG("CommandParser l: %s", lan.c_str());
647 return true;
648 }
649
IsTracePipeNameValid()650 bool CommandParser::IsTracePipeNameValid()
651 {
652 if (!IsSet("ts")) {
653 return true;
654 }
655 string tsName = Value("ts");
656 if (CheckParamInvalidity(tsName, false)) {
657 errorInfo = "Launch -ts parameters is not match regex.";
658 return false;
659 }
660 ILOG("CommandParser ts: %s", tsName.c_str());
661 return true;
662 }
663
IsLocalSocketNameValid()664 bool CommandParser::IsLocalSocketNameValid()
665 {
666 if (!IsSet("s")) {
667 return true;
668 }
669 string socketName = Value("s");
670 if (CheckParamInvalidity(socketName, false)) {
671 errorInfo = "Launch -s parameters is not match regex.";
672 return false;
673 }
674 ILOG("CommandParser s: %s", socketName.c_str());
675 return true;
676 }
677
IsConfigChangesValid()678 bool CommandParser::IsConfigChangesValid()
679 {
680 if (!IsSet("cc")) {
681 return true;
682 }
683 string configChange = Value("cc");
684 if (CheckParamInvalidity(configChange, false)) {
685 ELOG("Launch -cc parameters is not match regex.");
686 return false;
687 }
688 ILOG("CommandParser cc: %s", configChange.c_str());
689 return true;
690 }
691
IsScreenDensityValid()692 bool CommandParser::IsScreenDensityValid()
693 {
694 if (!IsSet("sd")) {
695 return true;
696 }
697 string density = Value("sd");
698 if (CheckParamInvalidity(density, true)) {
699 errorInfo = "Launch -sd parameters is not match regex.";
700 return false;
701 }
702 ILOG("CommandParser sd: %s", density.c_str());
703 return true;
704 }
705
IsContainerSdkPathValid()706 bool CommandParser::IsContainerSdkPathValid()
707 {
708 if (!IsSet("hsp")) {
709 return true;
710 }
711
712 string path = Value("hsp");
713 if (!FileSystem::IsDirectoryExists(path)) {
714 errorInfo = string("The container sdk path does not exist.");
715 ELOG("Launch -hsp parameters abnormal!");
716 return false;
717 }
718 containerSdkPath = path;
719 return true;
720 }
721
HelpText()722 string CommandParser::HelpText()
723 {
724 string helpText = "Usage:\n";
725 for (auto index = regsHelpMap.begin(); index != regsHelpMap.end(); index++) {
726 helpText += "-" + index->first + " ";
727 helpText += index->second + "\n";
728 }
729 return helpText;
730 }
731
ProcessingCommand(const std::vector<string> & strs)732 void CommandParser::ProcessingCommand(const std::vector<string>& strs)
733 {
734 for (unsigned int i = 0; i < strs.size(); ++i) {
735 string index = strs[i];
736 auto regInfo = regsArgsCountMap.find(strs[i]);
737 if (regInfo == regsArgsCountMap.end()) {
738 continue;
739 }
740
741 vector<string> args;
742 for (uint32_t j = 0; j < regInfo->second; ++j) {
743 if (i == strs.size() - 1 || strs[i + 1][0] == '-') {
744 args.push_back("");
745 break;
746 }
747 args.push_back(strs[++i]);
748 }
749 argsMap[index] = args;
750 }
751 }
752
GetProjectModelEnumValue() const753 int CommandParser::GetProjectModelEnumValue() const
754 {
755 auto idxVal = std::distance(projectModels.begin(),
756 find(projectModels.begin(), projectModels.end(), projectModel));
757 idxVal = (idxVal >= projectModels.size()) ? 0 : idxVal;
758 return idxVal;
759 }
760
GetProjectModelEnumName(int enumValue) const761 string CommandParser::GetProjectModelEnumName(int enumValue) const
762 {
763 if (enumValue < 0 || enumValue >= projectModels.size()) {
764 enumValue = 0;
765 }
766 return projectModels[enumValue];
767 }
768
CheckParamInvalidity(string param,bool isNum=false)769 bool CommandParser::CheckParamInvalidity(string param, bool isNum = false)
770 {
771 regex reg(isNum ? regex4Num : regex4Str);
772 return !regex_match(param.cbegin(), param.cend(), reg);
773 }