#include <iostream>
#include <string>
using namespace std;
%%{
# See RFC 3986: http://www.ietf.org/rfc/rfc3986.txt
machine uri_parser;
gen_delims = ":" | "/" | "?" | "#" | "[" | "]" | "@";
sub_delims = "!" | "$" | "&" | "'" | "(" | ")" | "*" | "+" | "," | ";" | "=";
reserved = gen_delims | sub_delims;
unreserved = alpha | digit | "-" | "." | "_" | "~";
pct_encoded = "%" xdigit xdigit;
action marku {
mark = fpc; }
action markh {
mark = fpc; }
action save_scheme
{
uri->setScheme(std::string(mark, fpc - mark));
mark = NULL;
}
scheme = (alpha (alpha | digit | "+" | "-" | ".")*) >marku %save_scheme;
action save_port
{
if (fpc != mark) {
uri->setPort(atoi(mark));
}
mark = NULL;
}
action save_userinfo
{
if(mark) {
//std::cout << std::string(mark, fpc - mark) << std::endl;
uri->setUserinfo(std::string(mark, fpc - mark));
}
mark = NULL;
}
action save_host
{
if (mark != NULL) {
//std::cout << std::string(mark, fpc - mark) << std::endl;
uri->setHost(std::string(mark
ragel解析http url
于 2022-01-28 08:34:38 首次发布
本文介绍了一个基于RFC3986标准的通用URI解析器实现细节。该解析器使用C++编写,通过状态机的方式解析URI,并将各部分信息如scheme、authority、path等分离出来。通过对URI结构的深入分析,该解析器能够有效处理各种复杂的URI格式。

最低0.47元/天 解锁文章
1473

被折叠的 条评论
为什么被折叠?



