More string_view

This commit is contained in:
halx99 2022-02-08 21:41:28 +08:00
parent 3c9111dc8c
commit d6fac0ac39
2 changed files with 7 additions and 21 deletions

View File

@ -7440,28 +7440,16 @@ namespace pugi
}
#ifndef PUGIXML_NO_STL
PUGI__FN std::string PUGIXML_FUNCTION as_utf8(const wchar_t* str)
PUGI__FN std::string PUGIXML_FUNCTION as_utf8(const pugi::wstring_view& str)
{
assert(str);
return impl::as_utf8_impl(str, impl::strlength_wide(str));
return impl::as_utf8_impl(str.data(), str.length());
}
PUGI__FN std::string PUGIXML_FUNCTION as_utf8(const std::basic_string<wchar_t>& str)
PUGI__FN std::wstring PUGIXML_FUNCTION as_wide(const pugi::string_view& str)
{
return impl::as_utf8_impl(str.c_str(), str.size());
}
assert(str.data());
PUGI__FN std::basic_string<wchar_t> PUGIXML_FUNCTION as_wide(const char* str)
{
assert(str);
return impl::as_wide_impl(str, strlen(str));
}
PUGI__FN std::basic_string<wchar_t> PUGIXML_FUNCTION as_wide(const std::string& str)
{
return impl::as_wide_impl(str.c_str(), str.size());
return impl::as_wide_impl(str.data(), str.length());
}
#endif

View File

@ -1561,12 +1561,10 @@ namespace pugi
#ifndef PUGIXML_NO_STL
// Convert wide string to UTF8
std::basic_string<char, std::char_traits<char>, std::allocator<char> > PUGIXML_FUNCTION as_utf8(const wchar_t* str);
std::basic_string<char, std::char_traits<char>, std::allocator<char> > PUGIXML_FUNCTION as_utf8(const std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >& str);
std::string PUGIXML_FUNCTION as_utf8(const pugi::wstring_view& str);
// Convert UTF8 to wide string
std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_wide(const char* str);
std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > PUGIXML_FUNCTION as_wide(const std::basic_string<char, std::char_traits<char>, std::allocator<char> >& str);
std::wstring PUGIXML_FUNCTION as_wide(const pugi::string_view& str);
#endif
// Memory allocation function interface; returns pointer to allocated memory or NULL on failure