我在该文档中有一个基本 URL 和一些相对 URI,我想获得其绝对路径。
例如基础 = https://example.com/some/path.html?query=string以及该文档中的相对 URI:
- index.html → https://example.com/some/index.html
- .. → https://example.com/
- ../../../../abc → https://example.com/abc
- abc/.. → https://example.com/some/
- //example.org/→ https://example.org/
- ftp://example.net/ → ftp://example.net/
在 Java 中你有 class URL实现这一目标:
URL abs = new URL(new URL(basePath), relPath);
但奇怪的是,我找不到一个普通的 C 库或函数来实现这一点。
是否有库证明该功能?或者更好的是一些可以使用的小型独立文件?
最佳答案
您可以打赌,这已经用 C 语言编写了一千遍了。例如,对于 apache。
这里有一些提示:
libSoup,GNOME 使用的 http 库:http://developer.gnome.org/libsoup/unstable/SoupURI.html#soup-uri-new-with-base
建议用于 Boost 库:http://cpp-netlib.github.com/
Google 自己(Chrome 的一部分?):http://code.google.com/p/google-url/
还有一个:http://uriparser.sourceforge.net/
W3C:http://www.w3.org/Library/src/HTParse
libcamel 中的 URL 解析:http://www.google.com/codesearch#KhbZeNk3OGk/camel/camel-url.c
一些更多的 URI 解析 API,似乎都没有有相对 URI:
GLib,我最喜欢的 C 库:http://developer.gnome.org/glib/unstable/glib-URI-Functions.html
libdataserver(来自 Evolution) http://developer.gnome.org/libedataserver/stable/libedataserver-e-url.html
GNet,一个能说会道的插件:http://developer.gnome.org/gnet/stable/gnet-uri.html
关于c - 来自相对路径的绝对 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8749814/