MCPcopy Create free account
hub / github.com/LibertyOS-Development/kernel / splargs

Function splargs

src/user/shell.rs:308–358  ·  view source on GitHub ↗

Split arguements

(cmd: &str)

Source from the content-addressed store, hash-verified

306
307// Split arguements
308pub fn splargs(cmd: &str) -> Vec<&str>
309{
310 let mut args: Vec<&str> = Vec::new();
311 let mut i = 0;
312 let mut n = cmd.len();
313 let mut quotation = false;
314
315 for (j, c) in cmd.char_indices()
316 {
317 if c == '#' && !quotation
318 {
319 // Throw out comments
320 n = j;
321 break;
322 }
323 else if c == ' ' && !quotation
324 {
325 if i != j
326 {
327 args.push(&cmd[i..j]);
328 }
329
330 i = j + 1;
331 }
332 else if c == '"'
333 {
334 quotation = !quotation;
335 if !quotation
336 {
337 args.push(&cmd[i..j]);
338 }
339 i = j + 1;
340 }
341 }
342
343 if i < n
344 {
345 if quotation
346 {
347 n -= 1;
348 }
349 args.push(&cmd[i..n]);
350 }
351
352 if n == 0 || cmd.ends_with(' ')
353 {
354 args.push("");
355 }
356
357 args
358}

Callers 2

execFunction · 0.85
shcompFunction · 0.85

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected