用于管理路径/URL 的库
C 或 C++ 中是否有任何库可以帮助管理路径或 URL?
或者可能来自这些语言之一的标准库中的函数
示例:
想象一下以下 API:
class Path {
public:
Path(std::string &path);
std::string getPath();
void cd(std::string &path);
}
我需要的是该库将处理以下情况:
示例 1:
Path *p = new Path("/level_one/level_two/level_three");
p->cd("..");
现在 p->getPath() == "/level_one/level_two";
,
示例 2:
p->cd("../level_TWO");
现在 p->getPath() == "/level_one/ level_TWO";
,
示例 3:
p->cd("/level_ONE");
现在 p->getPath() == "/level_one";
。
我希望这些例子能让我的问题更加清楚。基本上我需要库,它将跟踪与 POSIX 系统上的 cd 语法相关的所有更改目录命令。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下 google-url 项目,它在 Chrome 及其 C++ 中使用。
Have a look at google-url project, its used inside Chrome and its C++.
Boost Fileystem< /a> 库有一个路径类,它支持您正在寻找的大部分内容。
它不是
cd
命令,而是重载operator=/
用于降序目录,并具有用于升序的parent_path() 方法。它非常便携且易于学习。然而,它无法处理(据我所知)URL 路径。
The Boost Fileystem library has a path class which supports much of what you're looking for.
Instead of a
cd
command, it overloadsoperator=/
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.