/*************************************************************************
> File Name: test.cpp
> Author: wangzhicheng
> Mail: 2363702560@qq.com
> Created Time: Wed 02 Aug 2017 10:49:18 PM AWST
************************************************************************/
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
using namespace std;
void GetUrlKeyVal(const char *uri, vector<string>&keys, vector<string>values)
{
const char *p = uri;
while(*p)
{
if('?' == *p) break;
p++;
}
if(0 == *p) return;
char tmp[1024] = "";
int loop = 0;
bool Get = false;
while(*p)
{
if(*(p + 1) && !Get)
{
sscanf(p + 1, "%[^= | &]", tmp);
if(strcmp(tmp, ""))
{
Get = true;
if(!loop) keys.emplace_back(tmp);
else values.emplace_back(tmp);
loop = (loop + 1) & 1;
}
}
p++;
if(0 == *p) break;
if(('=' == *p) || ('&' == *p)) Get = false;
}
}
int main()
{
return 0;
}
extract uri key and value
最新推荐文章于 2025-08-10 23:15:18 发布
本文介绍了一个C++函数,用于从URI中解析出键值对,并将其分别存入两个字符串向量中。该函数能够处理URL中的参数,通过字符'?'定位参数开始的位置,然后逐个解析出键与对应的值。

2794

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



