MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Parse

Method Parse

Source/Tools/Flax.Build/CommandLine.cs:237–352  ·  view source on GitHub ↗

Parses the specified command line. The command line. The options.

(string commandLine)

Source from the content-addressed store, hash-verified

235 /// <param name="commandLine">The command line.</param>
236 /// <returns>The options.</returns>
237 public static Option[] Parse(string commandLine)
238 {
239 var options = new List<Option>();
240 var length = commandLine.Length;
241
242 for (int i = 0; i < length;)
243 {
244 // Skip white space
245 while (i < length && char.IsWhiteSpace(commandLine[i]))
246 i++;
247
248 // Read option prefix
249 if (i == length)
250 break;
251 var wholeQuote = commandLine[i] == '\"';
252 if (wholeQuote)
253 i++;
254 if (i == length)
255 break;
256 if (commandLine[i] == '-')
257 i++;
258 else if (commandLine[i] == '/')
259 i++;
260
261 // Skip white space
262 while (i < length && char.IsWhiteSpace(commandLine[i]))
263 i++;
264
265 // Read option name
266 int nameStart = i;
267 while (i < length && commandLine[i] != '-' && commandLine[i] != '=' && !char.IsWhiteSpace(commandLine[i]))
268 i++;
269 int nameEnd = i;
270 string name = commandLine.Substring(nameStart, nameEnd - nameStart);
271
272 // Skip white space
273 while (i < length && char.IsWhiteSpace(commandLine[i]))
274 i++;
275
276 // Check if has no value
277 if (i >= length - 1 || commandLine[i] != '=')
278 {
279 options.Add(new Option
280 {
281 Name = name,
282 Value = string.Empty
283 });
284 if (wholeQuote)
285 i++;
286 if (i < length && commandLine[i] != '\"')
287 i++;
288 continue;
289 }
290
291 // Read value
292 i++;
293 int valueStart, valueEnd;
294 if (commandLine.Length > i + 1 && commandLine[i] == '\\' && commandLine[i + 1] == '\"')

Callers 7

ParseFieldMethod · 0.45
GDKMethod · 0.45
GetLibFolderMethod · 0.45
TestParseOptionOnlyMethod · 0.45
TestParseOneValueMethod · 0.45
TestParseTwoOptionsMethod · 0.45
TestParsePathOptionMethod · 0.45

Calls 7

IsWhiteSpaceMethod · 0.80
SubstringMethod · 0.80
AddMethod · 0.45
TrimMethod · 0.45
StartsWithMethod · 0.45
EndsWithMethod · 0.45
ToArrayMethod · 0.45

Tested by 4

TestParseOptionOnlyMethod · 0.36
TestParseOneValueMethod · 0.36
TestParseTwoOptionsMethod · 0.36
TestParsePathOptionMethod · 0.36