用于解析查询字符串的 C 库?
我正在编写一个 C/CGI Web 应用程序。是否有一个库可以将查询字符串解析为 GHashTable 之类的内容?我可以自己编写,但似乎不值得重新发明轮子。
I'm writing a C/CGI web application. Is there a library to parse a query string into something like a GHashTable
? I could write my own but it certainly doesn't seem to be worth the effort to reinvent the wheel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
uriparser
库可以解析 查询字符串 转换为键值对。The
uriparser
library can parse query strings into key-value pairs.如果您确实正在编写 C 并且键集是已知的,那么您最好将值存储在
struct
中,而不是存储在一些臃肿的哈希表中。有一个static const
表:offsetof
宏)并使用它来解析查询字符串并填充在结构中。
If you're really writing C and the set of keys is known, you'd do much better to store the values in a
struct
instead of some bloated hash table. Have astatic const
table of:offsetof
macro)and use that to parse the query string and fill in the struct.
您可能会发现 Apache Portable Runtime (apr) 库中的 ap_getword 函数系列很有用。
你可以在google上搜索
"ap_getword(r->pool" "httpd.h"
,找到一些相关的源代码来学习。You may find usefull the ap_getword functions family from the Apache Portable Runtime (apr) library.
You may search google for
"ap_getword(r->pool" "httpd.h"
and find some relevant source code to learn from.