MCPcopy Create free account
hub / github.com/Singular/Singular / NormalizePath

Function NormalizePath

ppcc/adlib/os.cc:399–420  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

397}
398
399Str *NormalizePath(Str *path) {
400 bool abs = path->starts_with(PathSeparator);
401 StrArr *parts = path->split(PathSeparator);
402 StrArr *result = new StrArr();
403 for (Int i = 0; i < parts->len(); i++) {
404 Str *part = parts->at(i);
405 if (part->eq("") || part->eq(".")) {
406 // do nothing
407 } else if (part->eq("..")) {
408 if (result->len() > 0)
409 result->pop();
410 else if (!abs)
411 result->add(part);
412 } else {
413 result->add(part);
414 }
415 }
416 if (abs)
417 return S(PathSeparator)->add(StrJoin(result, PathSeparator));
418 else
419 return StrJoin(result, PathSeparator);
420}
421
422Str *GetEnv(const char *name) {
423 char *result = getenv(name);

Callers 3

MainFunction · 0.85
ProgramPathFunction · 0.85
TestOutputExecutableFunction · 0.85

Calls 9

StrJoinFunction · 0.85
starts_withMethod · 0.80
splitMethod · 0.80
SFunction · 0.70
lenMethod · 0.45
atMethod · 0.45
eqMethod · 0.45
popMethod · 0.45
addMethod · 0.45

Tested by 2

MainFunction · 0.68
TestOutputExecutableFunction · 0.68