sgml: rename str -> wstr
The sgml.hpp is about converting between SGML and UTF-16/Unicode actually. The "wstr" naming aligns better with std::wstring, wchar_t etc. Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
08de93ce2b
commit
6cdcb08365
@ -13,19 +13,19 @@ namespace UnitTests
|
|||||||
TEST_CLASS(sgml)
|
TEST_CLASS(sgml)
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TEST_METHOD(sgml2str)
|
TEST_METHOD(sgml2wstr)
|
||||||
{
|
{
|
||||||
Assert::AreEqual(L"This is a test.", stdex::sgml2str("This is a test.", (size_t)-1).c_str());
|
Assert::AreEqual(L"This is a test.", stdex::sgml2wstr("This is a test.", (size_t)-1).c_str());
|
||||||
Assert::AreEqual(L"Th\u00ed\u0161 i\u22c5 a te\u0073\u0304t.&unknown;😀😅", stdex::sgml2str("Thíš i⋅ a te&smacr;t.&unknown;😀😅", (size_t)-1).c_str());
|
Assert::AreEqual(L"Th\u00ed\u0161 i\u22c5 a te\u0073\u0304t.&unknown;😀😅", stdex::sgml2wstr("Thíš i⋅ a te&smacr;t.&unknown;😀😅", (size_t)-1).c_str());
|
||||||
Assert::AreEqual(L"This", stdex::sgml2str("This is a test.", 4).c_str());
|
Assert::AreEqual(L"This", stdex::sgml2wstr("This is a test.", 4).c_str());
|
||||||
Assert::AreEqual(L"T\u0068\u0301", stdex::sgml2str("T&hacute;is is a test.", 9).c_str());
|
Assert::AreEqual(L"T\u0068\u0301", stdex::sgml2wstr("T&hacute;is is a test.", 9).c_str());
|
||||||
Assert::AreEqual(L"T&hac", stdex::sgml2str("T&hacute;is is a test.", 5).c_str());
|
Assert::AreEqual(L"T&hac", stdex::sgml2wstr("T&hacute;is is a test.", 5).c_str());
|
||||||
Assert::AreEqual(L"The "quoted" & text.", stdex::sgml2str("The "quoted" & text.", (size_t)-1, stdex::sgml_c).c_str());
|
Assert::AreEqual(L"The "quoted" & text.", stdex::sgml2wstr("The "quoted" & text.", (size_t)-1, stdex::sgml_c).c_str());
|
||||||
|
|
||||||
stdex::mapping_vector<size_t> map;
|
stdex::mapping_vector<size_t> map;
|
||||||
constexpr size_t i = 0;
|
constexpr size_t i = 0;
|
||||||
constexpr size_t j = 0;
|
constexpr size_t j = 0;
|
||||||
stdex::sgml2str("Thíš i⋅ a te&smacr;t.&unknown;😀😅", (size_t)-1, 0, stdex::mapping<size_t>(i, j), &map);
|
stdex::sgml2wstr("Thíš i⋅ a te&smacr;t.&unknown;😀😅", (size_t)-1, 0, stdex::mapping<size_t>(i, j), &map);
|
||||||
Assert::IsTrue(stdex::mapping_vector<size_t>{
|
Assert::IsTrue(stdex::mapping_vector<size_t>{
|
||||||
{ i + 2, j + 2 },
|
{ i + 2, j + 2 },
|
||||||
{ i + 10, j + 3 },
|
{ i + 10, j + 3 },
|
||||||
@ -44,16 +44,16 @@ namespace UnitTests
|
|||||||
} == map);
|
} == map);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(str2sgml)
|
TEST_METHOD(wstr2sgml)
|
||||||
{
|
{
|
||||||
Assert::AreEqual("This is a test.", stdex::str2sgml(L"This is a test.", (size_t)-1).c_str());
|
Assert::AreEqual("This is a test.", stdex::wstr2sgml(L"This is a test.", (size_t)-1).c_str());
|
||||||
Assert::AreEqual("Thíš i⋅ a te&smacr;t.&unknown;😀😅", stdex::str2sgml(L"Th\u00ed\u0161 i\u22c5 a te\u0073\u0304t.&unknown;😀😅", (size_t)-1).c_str());
|
Assert::AreEqual("Thíš i⋅ a te&smacr;t.&unknown;😀😅", stdex::wstr2sgml(L"Th\u00ed\u0161 i\u22c5 a te\u0073\u0304t.&unknown;😀😅", (size_t)-1).c_str());
|
||||||
Assert::AreEqual("This", stdex::str2sgml(L"This is a test.", 4).c_str());
|
Assert::AreEqual("This", stdex::wstr2sgml(L"This is a test.", 4).c_str());
|
||||||
Assert::AreEqual("te&smacr;", stdex::str2sgml(L"te\u0073\u0304t", 4).c_str());
|
Assert::AreEqual("te&smacr;", stdex::wstr2sgml(L"te\u0073\u0304t", 4).c_str());
|
||||||
Assert::AreEqual("tes", stdex::str2sgml(L"te\u0073\u0304t", 3).c_str());
|
Assert::AreEqual("tes", stdex::wstr2sgml(L"te\u0073\u0304t", 3).c_str());
|
||||||
Assert::AreEqual("⌘‰͢", stdex::str2sgml(L"⌘‰͢", (size_t)-1).c_str());
|
Assert::AreEqual("⌘‰͢", stdex::wstr2sgml(L"⌘‰͢", (size_t)-1).c_str());
|
||||||
Assert::AreEqual("$\"<>&", stdex::str2sgml(L"$\"<>&", (size_t)-1).c_str());
|
Assert::AreEqual("$\"<>&", stdex::wstr2sgml(L"$\"<>&", (size_t)-1).c_str());
|
||||||
Assert::AreEqual("$"<>&", stdex::str2sgml(L"$\"<>&", (size_t)-1, stdex::sgml_c).c_str());
|
Assert::AreEqual("$"<>&", stdex::wstr2sgml(L"$\"<>&", (size_t)-1, stdex::sgml_c).c_str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -754,7 +754,7 @@ namespace stdex
|
|||||||
basic_set<char>(invert, locale)
|
basic_set<char>(invert, locale)
|
||||||
{
|
{
|
||||||
if (set)
|
if (set)
|
||||||
m_set = sgml2str(set, count);
|
m_set = sgml2wstr(set, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool match(
|
virtual bool match(
|
||||||
@ -842,7 +842,7 @@ namespace stdex
|
|||||||
public:
|
public:
|
||||||
sgml_string(const char* str, size_t count = (size_t)-1, _In_ const std::locale& locale = std::locale()) :
|
sgml_string(const char* str, size_t count = (size_t)-1, _In_ const std::locale& locale = std::locale()) :
|
||||||
sgml_parser(locale),
|
sgml_parser(locale),
|
||||||
m_str(sgml2str(str, count))
|
m_str(sgml2wstr(str, count))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
virtual bool match(
|
virtual bool match(
|
||||||
|
@ -91,7 +91,7 @@ namespace stdex
|
|||||||
/// \return Unicode string
|
/// \return Unicode string
|
||||||
///
|
///
|
||||||
template <class T>
|
template <class T>
|
||||||
inline void sgml2str(
|
inline void sgml2wstr(
|
||||||
_Inout_ std::wstring& dst,
|
_Inout_ std::wstring& dst,
|
||||||
_In_reads_or_z_opt_(count_src) const T* src, _In_ size_t count_src,
|
_In_reads_or_z_opt_(count_src) const T* src, _In_ size_t count_src,
|
||||||
_In_ int skip = 0,
|
_In_ int skip = 0,
|
||||||
@ -185,14 +185,14 @@ namespace stdex
|
|||||||
/// \return Unicode string
|
/// \return Unicode string
|
||||||
///
|
///
|
||||||
template <class T>
|
template <class T>
|
||||||
inline void sgml2str(
|
inline void sgml2wstr(
|
||||||
_Inout_ std::wstring& dst,
|
_Inout_ std::wstring& dst,
|
||||||
_In_ const std::basic_string<T>& src,
|
_In_ const std::basic_string<T>& src,
|
||||||
_In_ int skip = 0,
|
_In_ int skip = 0,
|
||||||
_In_ const mapping<size_t>& offset = mapping<size_t>(0, 0),
|
_In_ const mapping<size_t>& offset = mapping<size_t>(0, 0),
|
||||||
_Inout_opt_ mapping_vector<size_t>* map = nullptr)
|
_Inout_opt_ mapping_vector<size_t>* map = nullptr)
|
||||||
{
|
{
|
||||||
sgml2str(dst, src.data(), src.size(), skip, offset, map);
|
sgml2wstr(dst, src.data(), src.size(), skip, offset, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -207,14 +207,14 @@ namespace stdex
|
|||||||
/// \return Unicode string
|
/// \return Unicode string
|
||||||
///
|
///
|
||||||
template <class T>
|
template <class T>
|
||||||
inline std::wstring sgml2str(
|
inline std::wstring sgml2wstr(
|
||||||
_In_reads_or_z_opt_(count_src) const T* src, _In_ size_t count_src,
|
_In_reads_or_z_opt_(count_src) const T* src, _In_ size_t count_src,
|
||||||
_In_ int skip = 0,
|
_In_ int skip = 0,
|
||||||
_In_ const mapping<size_t>& offset = mapping<size_t>(0, 0),
|
_In_ const mapping<size_t>& offset = mapping<size_t>(0, 0),
|
||||||
_Inout_opt_ mapping_vector<size_t>* map = nullptr)
|
_Inout_opt_ mapping_vector<size_t>* map = nullptr)
|
||||||
{
|
{
|
||||||
std::wstring dst;
|
std::wstring dst;
|
||||||
sgml2str(dst, src, count_src, skip, offset, map);
|
sgml2wstr(dst, src, count_src, skip, offset, map);
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,13 +229,13 @@ namespace stdex
|
|||||||
/// \return Unicode string
|
/// \return Unicode string
|
||||||
///
|
///
|
||||||
template <class T>
|
template <class T>
|
||||||
inline std::wstring sgml2str(
|
inline std::wstring sgml2wstr(
|
||||||
_In_ const std::basic_string<T>& src,
|
_In_ const std::basic_string<T>& src,
|
||||||
_In_ int skip = 0,
|
_In_ int skip = 0,
|
||||||
_In_ const mapping<size_t>& offset = mapping<size_t>(0, 0),
|
_In_ const mapping<size_t>& offset = mapping<size_t>(0, 0),
|
||||||
_Inout_opt_ mapping_vector<size_t>* map = nullptr)
|
_Inout_opt_ mapping_vector<size_t>* map = nullptr)
|
||||||
{
|
{
|
||||||
return sgml2str(src.c_str(), src.size(), skip, offset, map);
|
return sgml2wstr(src.c_str(), src.size(), skip, offset, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \cond internal
|
/// \cond internal
|
||||||
@ -275,7 +275,7 @@ namespace stdex
|
|||||||
/// \param[in] count_src Unicode string character count limit
|
/// \param[in] count_src Unicode string character count limit
|
||||||
/// \param[in] what Bitwise flag of stdex::sgml_* constants that force extra characters otherwise not converted to SGML
|
/// \param[in] what Bitwise flag of stdex::sgml_* constants that force extra characters otherwise not converted to SGML
|
||||||
///
|
///
|
||||||
inline void str2sgml(
|
inline void wstr2sgml(
|
||||||
_Inout_ std::string& dst,
|
_Inout_ std::string& dst,
|
||||||
_In_reads_or_z_opt_(count_src) const wchar_t* src,
|
_In_reads_or_z_opt_(count_src) const wchar_t* src,
|
||||||
_In_ size_t count_src,
|
_In_ size_t count_src,
|
||||||
@ -378,12 +378,12 @@ namespace stdex
|
|||||||
/// \param[in] src Unicode string
|
/// \param[in] src Unicode string
|
||||||
/// \param[in] what Bitwise flag of stdex::sgml_* constants that force extra characters otherwise not converted to SGML
|
/// \param[in] what Bitwise flag of stdex::sgml_* constants that force extra characters otherwise not converted to SGML
|
||||||
///
|
///
|
||||||
inline void str2sgml(
|
inline void wstr2sgml(
|
||||||
_Inout_ std::string& dst,
|
_Inout_ std::string& dst,
|
||||||
_In_ const std::wstring& src,
|
_In_ const std::wstring& src,
|
||||||
_In_ size_t what = 0)
|
_In_ size_t what = 0)
|
||||||
{
|
{
|
||||||
str2sgml(dst, src.c_str(), src.size(), what);
|
wstr2sgml(dst, src.c_str(), src.size(), what);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -395,13 +395,13 @@ namespace stdex
|
|||||||
///
|
///
|
||||||
/// \return SGML string
|
/// \return SGML string
|
||||||
///
|
///
|
||||||
inline std::string str2sgml(
|
inline std::string wstr2sgml(
|
||||||
_In_reads_or_z_opt_(count_src) const wchar_t* src,
|
_In_reads_or_z_opt_(count_src) const wchar_t* src,
|
||||||
_In_ size_t count_src,
|
_In_ size_t count_src,
|
||||||
_In_ size_t what = 0)
|
_In_ size_t what = 0)
|
||||||
{
|
{
|
||||||
std::string dst;
|
std::string dst;
|
||||||
str2sgml(dst, src, count_src, what);
|
wstr2sgml(dst, src, count_src, what);
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,10 +413,10 @@ namespace stdex
|
|||||||
///
|
///
|
||||||
/// \return SGML string
|
/// \return SGML string
|
||||||
///
|
///
|
||||||
inline std::string str2sgml(
|
inline std::string wstr2sgml(
|
||||||
_In_ const std::wstring& src,
|
_In_ const std::wstring& src,
|
||||||
_In_ size_t what = 0)
|
_In_ size_t what = 0)
|
||||||
{
|
{
|
||||||
return str2sgml(src.c_str(), src.size(), what);
|
return wstr2sgml(src.c_str(), src.size(), what);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user