extract uri key and value

/*************************************************************************
    > File Name: test.cpp
    > Author: wangzhicheng
    > Mail: [email protected] 
    > 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;
}


猜你喜欢

转载自blog.csdn.net/wangzhicheng2013/article/details/76599803