mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-15 09:20:52 +08:00
86 lines
2.8 KiB
C++
86 lines
2.8 KiB
C++
// url_coder.cpp : 定义控制台应用程序的入口点。
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "acl_cpp/stdlib/string.hpp"
|
|
#include "acl_cpp/stdlib/url_coder.hpp"
|
|
|
|
using namespace acl;
|
|
|
|
int main(void)
|
|
{
|
|
url_coder coder1;
|
|
|
|
coder1.set("name1", "value1");
|
|
coder1.set("name2", 2);
|
|
coder1.set("name3", true, "value%d", 3);
|
|
coder1.set("name4", "中国人");
|
|
printf("coder1 >> %s, name1: %s, name2: %s, name3: %s, name4: %s\r\n",
|
|
coder1.to_string().c_str(),
|
|
coder1["name1"], coder1["name2"], coder1["name3"], coder1["name4"]);
|
|
coder1.del("name1");
|
|
const char* ptr = coder1["name1"];
|
|
printf("coder1 >> %s, name1: %s, name2: %s, name3: %s, name4: %s\r\n",
|
|
coder1.to_string().c_str(), ptr ? ptr : "null",
|
|
coder1["name2"], coder1["name3"], coder1["name4"]);
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
url_coder coder2;
|
|
|
|
coder2 = coder1;
|
|
coder2.set("name5", "&=value5=&");
|
|
ptr = coder2["name1"];
|
|
printf("--------------------------------------------------------\r\n");
|
|
printf("coder2 >> %s, name1: %s, name2: %s, name3: %s, name4: %s, name5: %s\r\n",
|
|
coder2.to_string().c_str(), ptr ? ptr : "null",
|
|
coder2["name2"], coder2["name3"], coder2["name4"], coder2["name5"]);
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
url_coder coder3(coder2);
|
|
|
|
coder3.set("name5", 5);
|
|
coder3.set("name6", "=&外国人&=");
|
|
ptr = coder3["name1"];
|
|
printf("--------------------------------------------------------\r\n");
|
|
printf("coder3 >> %s, name1: %s, name2: %s, name3: %s, name4: %s, name5: %s, name6: %s\r\n",
|
|
coder3.to_string().c_str(), ptr ? ptr : "null",
|
|
coder3["name2"], coder3["name3"], coder3["name4"],
|
|
coder3["name5"], coder3["name6"]);
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
url_coder coder4;
|
|
const char* s = "name1=value1&name2=2&name3=value3&name4=%D6%D0%B9%FA%C8%CB";
|
|
coder4.decode(s);
|
|
printf("--------------------------------------------------------\r\n");
|
|
printf("coder4 >> %s, name1: %s, name2: %s, name3: %s, name4: %s\r\n",
|
|
coder4.to_string().c_str(),
|
|
coder4["name1"], coder4["name2"], coder4["name3"], coder4["name4"]);
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
printf("--------------------------------------------------------\r\n");
|
|
acl::url_coder coder5;
|
|
coder5.set("n0", "").set("n1", "v1").set("n2", "");
|
|
acl::string s5 = coder5.to_string();
|
|
coder5.reset();
|
|
|
|
coder5.decode(s5);
|
|
bool found0, found3;
|
|
const char* v0 = coder5.get("n0", &found0);
|
|
const char* v3 = coder5.get("n3", &found3);
|
|
printf(">>>url=%s, n0=%s, %s, n1=%s, n3=%s, %s\r\n", s5.c_str(),
|
|
v0, found0 ? "found it" : "not found", coder5.get("n1"),
|
|
v3, found3 ? "found it" : "not found");
|
|
|
|
#ifdef WIN32
|
|
printf("enter any key to exit ...\r\n");
|
|
getchar();
|
|
#endif
|
|
|
|
return 0;
|
|
}
|
|
|