MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / parseStart

Method parseStart

framework/fs/physfs_archiver_cue.cpp:74–153  ·  view source on GitHub ↗

Parse command while not being in a specific context

Source from the content-addressed store, hash-verified

72
73 // Parse command while not being in a specific context
74 bool parseStart(std::string command, std::string arg)
75 {
76 // Waiting for "FILE" command
77 UString cmd(command);
78 if (to_upper(cmd) != "FILE")
79 {
80 LogInfo("Encountered unexpected command: \"%s\", ignoring", cmd);
81 return false;
82 }
83 // auto matchIter = std::sregex_iterator(arg.begin(), arg.end(), fileArgRegex);
84 // FILE argument might be in quotation marks - better handle that
85
86 size_t first_char = 0, last_char = arg.size() - 1;
87 if (arg[first_char] == '"')
88 {
89 while ((last_char > 0) && (arg[last_char] != '"'))
90 {
91 last_char--;
92 }
93 // Trim quotation marks
94 last_char -= 1;
95 first_char += 1;
96 }
97 else
98 {
99 // Just find the last non-whitespace character
100 last_char = first_char + 1;
101 while ((last_char < arg.size()) && !isspace(arg[last_char]))
102 {
103 last_char++;
104 }
105 if (last_char == arg.size())
106 {
107 LogError("Malformed argument for FILE command (arguments are: \"%s\")",
108 arg.c_str());
109 return false;
110 }
111 last_char -= 1;
112 }
113 if (last_char >= first_char)
114 {
115 dataFileName = arg.substr(first_char, last_char - first_char + 1);
116 LogInfo("Reading from \"%s\"", dataFileName);
117 }
118 else
119 {
120 LogError("Bad file name for FILE command (arguments are: \"%s\")", arg.c_str());
121 return false;
122 }
123
124 // Find the file type string
125 first_char = last_char + 1;
126 while ((first_char < arg.size()) && !isalnum(arg[first_char]))
127 {
128 first_char++;
129 }
130 if (first_char == arg.size())
131 {

Callers

nothing calls this directly

Calls 2

to_upperFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected