bool AnalyzeUri() {
Uri uri;
if (
nlib_is_error(uri.Parse(
"HTTP://www.EXAMPLE.com:8081/app/search?" "q=nintendo&qs=n&form=QBLH&filt=all#fragment")))
return false;
size_t path_strlen;
char path[512];
if (
nlib_is_error(Uri::DecodePath(&path_strlen, path, uri.GetPath()))) {
return false;
}
UriQueryDecoder<> decoder;
while (decoder.HasNext()) {
std::pair<errno_t, const char*> k = decoder.GetKey();
std::pair<errno_t, const char*> v = decoder.GetValue();
if (k.first != 0 || v.first != 0) return false;
decoder.MoveNext();
}
return true;
}
bool ComposeUri() {
Uri uri;
return false;
return false;
return false;
UriQueryEncoder<> encoder;
(void)encoder.Append("q", "nintendo");
(void)encoder.Append("qa", "n");
(void)encoder.Append("form", "QBLH");
(void)encoder.Append("filt", "all");
char uriText[2048];
if (!uri.ComposeString(uriText))
return false;
return true;
}
bool RelativePath() {
const char base[] = "http://example.com/news/index.html?ref=mynews/test";
const char relative[] = "../js/mylib.js";
Uri relative_uri;
Uri base_uri, result_uri;
if (
nlib_is_error(result_uri.AddBaseUri(relative_uri, base_uri)))
return false;
char uriText[2048];
return false;
return true;
}
bool UseUriTemplate() {
UriTemplate templ;
char str[1024];
nlib_printf(
"Template: 'http://example.com/map?{x,y}#{x,hello,y,undef,empty}'\n");
e = templ.SetTemplate("http://example.com/map?{x,y}#{x,hello,y,undef,empty}");
e = templ.SetParameter("var", "value");
e = templ.SetParameter("hello", "Hello World!");
e = templ.SetParameter("empty", "");
e = templ.SetParameter("path", "/foo/bar");
e = templ.SetParameter("x", "1024");
e = templ.SetParameter("y", "768");
return true;
}
bool SampleMain(int, char**) {
return AnalyzeUri() && ComposeUri() && RelativePath() && UseUriTemplate();
}
NLIB_MAINFUNC