2012-01-05 140 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