Question

Is there any library in C or C++ that helps with managing paths or URLs?

Or maybe functions from standard library from one of these languages

Example:

Imagine following API:

class Path {
  public:
    Path(std::string &path);

    std::string getPath();

    void cd(std::string &path);
}  

What I need is that this library will handle following cases:

Example 1:

Path *p = new Path("/level_one/level_two/level_three");

p->cd("..");

and now p->getPath() == "/level_one/level_two";,

Example 2:

p->cd("../level_TWO");

and now p->getPath() == "/level_one/level_TWO";,

Example 3:

p->cd("/level_ONE");

and now p->getPath() == "/level_one";.

I hope that these examples made my problem more clear. Basically I need library, that will keep track all change directory commands with respect to syntax of cd on POSIX systems.

Was it helpful?

Solution

The Boost Fileystem library has a path class which supports much of what you're looking for.

Instead of a cd command, it overloads operator=/ for descending directories and has a parent_path() method for ascending.

It's very portable and easy to learn. It is, however, unable to deal (AFAIK) with URL paths.

OTHER TIPS

Have a look at google-url project, its used inside Chrome and its C++.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top