MCPcopy Create free account
hub / github.com/Panzerschrek/Chasm-Reverse / ParseCommad

Method ParseCommad

PanzerChasm/commands_processor.cpp:126–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124}
125
126std::pair< std::string, CommandsArguments > CommandsProcessor::ParseCommad(
127 const char* const command_string )
128{
129 std::pair< std::string, CommandsArguments > result;
130
131 const char* s= command_string;
132
133 // Skip trailing spaces
134 while( *s != '\0' && std::isspace( *s ) ) s++;
135
136 // Process command name
137 while( *s != '\0' && !std::isspace( *s ) )
138 {
139 result.first.push_back( std::tolower( *s ) );
140 s++;
141 }
142
143 while( *s != '\0' )
144 {
145 // Skip trailing spaces
146 while( *s != '\0' && std::isspace( *s ) ) s++;
147
148 // Do not create argument if string is over.
149 if( *s == '\0' ) break;
150
151 result.second.emplace_back();
152
153 // Process argument
154 if( *s == '"' ) // Arg in quotes
155 {
156 s++;
157 while( *s != '\0' && *s != '"' )
158 {
159 if( *s == '\\' && s[1] == '"' ) s++; // Escaped quote
160 result.second.back().push_back( *s );
161 s++;
162 }
163 if( *s == '"' )
164 s++;
165 else
166 break;
167 }
168 else // Space-separated argument
169 {
170 while( *s != '\0' && !std::isspace( *s ) )
171 {
172 result.second.back().push_back( *s );
173 s++;
174 }
175 }
176 }
177
178 return result;
179}
180
181} // namespace PanzerChasm

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected