2012-01-05 273 views
5

我已经有了一个基本的URL和一些相关的URI文件,我想拥有绝对路径。绝对URL来自相对路径

E.g.基= https://example.com/some/path.html?query=string和相对URI该文献中:

在Java中你有class URL实现这个目的:

URL abs = new URL(new URL(basePath), relPath); 

但奇怪的是,我不能找到一个纯C库或者功能实现这一点。

是否有图书馆证明该功能?或者更好一些可以使用的小型自包含文件?

+0

检出http://stackoverflow.com/questions/726122/best-ways-of-parsing-a-url-using-c – frankc 2012-01-05 21:51:48

回答

2

你可以打赌,这已经写在C已经上千次。例如,对于Apache。

这里有一些指针:

libSoup,由GNOME使用的HTTP库:http://developer.gnome.org/libsoup/unstable/SoupURI.html#soup-uri-new-with-base

拟议Boost库:

通过谷歌本身(铬的一部分?):http://code.google.com/p/google-url/

另一种:http://uriparser.sourceforge.net/

W3C:http://www.w3.org/Library/src/HTParse

URL解析中libcamel: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

libedataserver( from Evolution) http://developer.gnome.org/libedataserver/stable/libedataserver-e-url.html

GNet,glib插件:http://developer.gnome.org/gnet/stable/gnet-uri.html

+3

3中的2个是错误的语言 – 2012-01-05 21:14:46

+0

尽管他们很难找到图书馆已经“已经在C写过一千次了”,不是吗?HTParse和uriparser看起来不错,其他库或者是C++或者(libcamel)都有一些依赖关系。稍后我会进一步研究。谢谢! – kay 2012-01-06 15:20:18

+0

确实。但重复使用外国C代码往往比自己写这样的代码片段更困难。不幸的是,他们处理记忆的方式可能无法找到你的方式。 C中的代码风格差异比例如Java的。我很惊讶地看到只是基本的URI函数,在glib中,顺便说一句。 – 2012-01-06 16:57:37