2012-09-30 13:56:20 +00:00
|
|
|
#include <qse/cmn/uri.h>
|
|
|
|
#include <qse/cmn/main.h>
|
|
|
|
#include <qse/cmn/mbwc.h>
|
2016-04-29 03:55:42 +00:00
|
|
|
#include <qse/si/sio.h>
|
2012-09-30 13:56:20 +00:00
|
|
|
|
|
|
|
#include <locale.h>
|
|
|
|
#if defined(_WIN32)
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void xxx (const qse_wchar_t* ptr, qse_size_t len)
|
|
|
|
{
|
|
|
|
if (ptr)
|
|
|
|
{
|
|
|
|
qse_size_t i;
|
|
|
|
qse_printf (QSE_T(" ["));
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
qse_printf (QSE_T("%hc"), ptr[i]);
|
|
|
|
qse_printf (QSE_T("] "));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qse_printf (QSE_T(" (null) "));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-15 09:46:29 +00:00
|
|
|
static int test_main (int argc, qse_char_t* argv[])
|
2012-09-30 13:56:20 +00:00
|
|
|
{
|
|
|
|
static const qse_wchar_t* wcs[] =
|
|
|
|
{
|
|
|
|
QSE_WT("http://www.google.com"),
|
|
|
|
QSE_WT("http://www.google.com:80"),
|
|
|
|
QSE_WT("http://abc@www.google.com:80"),
|
|
|
|
QSE_WT("http://abc:def@www.google.com:80"),
|
|
|
|
QSE_WT("http://abc:def@www.google.com:80/"),
|
|
|
|
QSE_WT("http://abc:def@www.google.com:80/?#"),
|
|
|
|
QSE_WT("http://abc:def@www.google.com:80/abcdef/ghi?kkk=23#fragment"),
|
|
|
|
QSE_WT("http://abc:def@www.google.com:80/abcdef/ghi#fragment#fragment"),
|
|
|
|
QSE_WT("http://abc:def@www@.google.com:80/abcdef/ghi#fragment#fragment"),
|
|
|
|
QSE_WT("http://@@@@@abc:def@www@.google.com:80/abcdef/ghi#fragment#fragment")
|
|
|
|
};
|
|
|
|
|
|
|
|
qse_size_t i;
|
|
|
|
qse_uri_t uri;
|
|
|
|
|
|
|
|
for (i = 0; i < QSE_COUNTOF(wcs); i++)
|
|
|
|
{
|
|
|
|
qse_printf (QSE_T("[%ls] => "), wcs[i]);
|
|
|
|
if (qse_wcstouri (wcs[i], &uri, 0) <= -1)
|
|
|
|
{
|
|
|
|
qse_printf (QSE_T("[ERROR]"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xxx (uri.scheme.ptr, uri.scheme.len);
|
|
|
|
xxx (uri.auth.user.ptr, uri.auth.user.len);
|
|
|
|
xxx (uri.auth.pass.ptr, uri.auth.pass.len);
|
|
|
|
xxx (uri.host.ptr, uri.host.len);
|
|
|
|
xxx (uri.port.ptr, uri.port.len);
|
|
|
|
xxx (uri.path.ptr, uri.path.len);
|
|
|
|
xxx (uri.query.ptr, uri.query.len);
|
|
|
|
xxx (uri.frag.ptr, uri.frag.len);
|
|
|
|
}
|
|
|
|
qse_printf (QSE_T("\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_printf (QSE_T("================================================\n"));
|
|
|
|
|
|
|
|
for (i = 0; i < QSE_COUNTOF(wcs); i++)
|
|
|
|
{
|
|
|
|
qse_printf (QSE_T("[%ls] => "), wcs[i]);
|
|
|
|
if (qse_wcstouri (wcs[i], &uri, QSE_WCSTOURI_NOQUERY | QSE_WCSTOURI_NOAUTH) <= -1)
|
|
|
|
{
|
|
|
|
qse_printf (QSE_T("[ERROR]"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xxx (uri.scheme.ptr, uri.scheme.len);
|
|
|
|
xxx (uri.auth.user.ptr, uri.auth.user.len);
|
|
|
|
xxx (uri.auth.pass.ptr, uri.auth.pass.len);
|
|
|
|
xxx (uri.host.ptr, uri.host.len);
|
|
|
|
xxx (uri.port.ptr, uri.port.len);
|
|
|
|
xxx (uri.path.ptr, uri.path.len);
|
|
|
|
xxx (uri.query.ptr, uri.query.len);
|
|
|
|
xxx (uri.frag.ptr, uri.frag.len);
|
|
|
|
}
|
|
|
|
qse_printf (QSE_T("\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_printf (QSE_T("================================================\n"));
|
|
|
|
|
|
|
|
for (i = 0; i < QSE_COUNTOF(wcs); i++)
|
|
|
|
{
|
|
|
|
qse_printf (QSE_T("[%ls] => "), wcs[i]);
|
|
|
|
if (qse_wcstouri (wcs[i], &uri, QSE_WCSTOURI_NOQUERY | QSE_WCSTOURI_NOAUTH | QSE_WCSTOURI_NOFRAG) <= -1)
|
|
|
|
{
|
|
|
|
qse_printf (QSE_T("[ERROR]"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xxx (uri.scheme.ptr, uri.scheme.len);
|
|
|
|
xxx (uri.auth.user.ptr, uri.auth.user.len);
|
|
|
|
xxx (uri.auth.pass.ptr, uri.auth.pass.len);
|
|
|
|
xxx (uri.host.ptr, uri.host.len);
|
|
|
|
xxx (uri.port.ptr, uri.port.len);
|
|
|
|
xxx (uri.path.ptr, uri.path.len);
|
|
|
|
xxx (uri.query.ptr, uri.query.len);
|
|
|
|
xxx (uri.frag.ptr, uri.frag.len);
|
|
|
|
}
|
|
|
|
qse_printf (QSE_T("\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_printf (QSE_T("================================================\n"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-15 09:46:29 +00:00
|
|
|
int qse_main (int argc, qse_achar_t* argv[])
|
2012-09-30 13:56:20 +00:00
|
|
|
{
|
2015-03-11 06:12:48 +00:00
|
|
|
int x;
|
2012-09-30 13:56:20 +00:00
|
|
|
#if defined(_WIN32)
|
2015-03-11 06:12:48 +00:00
|
|
|
char locale[100];
|
|
|
|
UINT codepage = GetConsoleOutputCP();
|
2012-09-30 13:56:20 +00:00
|
|
|
if (codepage == CP_UTF8)
|
|
|
|
{
|
|
|
|
/*SetConsoleOUtputCP (CP_UTF8);*/
|
2012-10-15 09:36:39 +00:00
|
|
|
qse_setdflcmgrbyid (QSE_CMGR_UTF8);
|
2012-09-30 13:56:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-11 06:12:48 +00:00
|
|
|
sprintf (locale, ".%u", (unsigned int)codepage);
|
|
|
|
setlocale (LC_ALL, locale);
|
2015-04-27 08:37:57 +00:00
|
|
|
/*qse_setdflcmgrbyid (QSE_CMGR_SLMB);*/
|
2012-09-30 13:56:20 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
setlocale (LC_ALL, "");
|
2015-04-27 08:37:57 +00:00
|
|
|
/*qse_setdflcmgrbyid (QSE_CMGR_SLMB);*/
|
2012-09-30 13:56:20 +00:00
|
|
|
#endif
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_open_stdsios ();
|
2018-09-13 03:16:23 +00:00
|
|
|
x = qse_run_main (argc, argv, test_main);
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_close_stdsios ();
|
2015-03-11 06:12:48 +00:00
|
|
|
return x;
|
2012-09-30 13:56:20 +00:00
|
|
|
}
|
|
|
|
|