util/AllocatedString: rename to BasicAllocatedString
To make things simpler, AllocatedString is now a non-template class.
This commit is contained in:

committed by
Max Kellermann

parent
1b89b4ef83
commit
c70b63c183
@@ -38,13 +38,13 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
AllocatedString<>
|
||||
AllocatedString
|
||||
IcuCaseFold(std::string_view src) noexcept
|
||||
try {
|
||||
#ifdef HAVE_ICU
|
||||
const auto u = UCharFromUTF8(src);
|
||||
if (u.IsNull())
|
||||
return AllocatedString<>::Duplicate(src);
|
||||
return AllocatedString::Duplicate(src);
|
||||
|
||||
AllocatedArray<UChar> folded(u.size() * 2U);
|
||||
|
||||
@@ -54,7 +54,7 @@ try {
|
||||
U_FOLD_CASE_DEFAULT,
|
||||
&error_code);
|
||||
if (folded_length == 0 || error_code != U_ZERO_ERROR)
|
||||
return AllocatedString<>::Duplicate(src);
|
||||
return AllocatedString::Duplicate(src);
|
||||
|
||||
folded.SetSize(folded_length);
|
||||
return UCharToUTF8({folded.begin(), folded.size()});
|
||||
@@ -63,7 +63,7 @@ try {
|
||||
#error not implemented
|
||||
#endif
|
||||
} catch (...) {
|
||||
return AllocatedString<>::Duplicate(src);
|
||||
return AllocatedString::Duplicate(src);
|
||||
}
|
||||
|
||||
#endif /* HAVE_ICU_CASE_FOLD */
|
||||
|
@@ -27,9 +27,9 @@
|
||||
|
||||
#include <string_view>
|
||||
|
||||
template<typename T> class AllocatedString;
|
||||
class AllocatedString;
|
||||
|
||||
AllocatedString<char>
|
||||
AllocatedString
|
||||
IcuCaseFold(std::string_view src) noexcept;
|
||||
|
||||
#endif
|
||||
|
@@ -88,7 +88,7 @@ IcuCollate(std::string_view a, std::string_view b) noexcept
|
||||
b.data(), b.size(), &code);
|
||||
|
||||
#elif defined(_WIN32)
|
||||
AllocatedString<wchar_t> wa = nullptr, wb = nullptr;
|
||||
BasicAllocatedString<wchar_t> wa = nullptr, wb = nullptr;
|
||||
|
||||
try {
|
||||
wa = MultiByteToWideChar(CP_UTF8, a);
|
||||
|
@@ -46,7 +46,7 @@ IcuCompare::IcuCompare(std::string_view _needle) noexcept
|
||||
#else
|
||||
|
||||
IcuCompare::IcuCompare(std::string_view _needle) noexcept
|
||||
:needle(AllocatedString<>::Duplicate(_needle)) {}
|
||||
:needle(AllocatedString::Duplicate(_needle)) {}
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -38,9 +38,9 @@ class IcuCompare {
|
||||
#ifdef _WIN32
|
||||
/* Windows API functions work with wchar_t strings, so let's
|
||||
cache the MultiByteToWideChar() result for performance */
|
||||
AllocatedString<wchar_t> needle;
|
||||
BasicAllocatedString<wchar_t> needle;
|
||||
#else
|
||||
AllocatedString<> needle;
|
||||
AllocatedString needle;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
@@ -77,7 +77,7 @@ IcuConverter::Create(const char *charset)
|
||||
#ifdef HAVE_ICU
|
||||
#elif defined(HAVE_ICONV)
|
||||
|
||||
static AllocatedString<char>
|
||||
static AllocatedString
|
||||
DoConvert(iconv_t conv, std::string_view src)
|
||||
{
|
||||
// TODO: dynamic buffer?
|
||||
@@ -95,12 +95,12 @@ DoConvert(iconv_t conv, std::string_view src)
|
||||
if (in_left > 0)
|
||||
throw std::runtime_error("Charset conversion failed");
|
||||
|
||||
return AllocatedString<>::Duplicate({buffer, sizeof(buffer) - out_left});
|
||||
return AllocatedString::Duplicate({buffer, sizeof(buffer) - out_left});
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
AllocatedString<char>
|
||||
AllocatedString
|
||||
IcuConverter::ToUTF8(std::string_view s) const
|
||||
{
|
||||
#ifdef HAVE_ICU
|
||||
@@ -128,7 +128,7 @@ IcuConverter::ToUTF8(std::string_view s) const
|
||||
#endif
|
||||
}
|
||||
|
||||
AllocatedString<char>
|
||||
AllocatedString
|
||||
IcuConverter::FromUTF8(std::string_view s) const
|
||||
{
|
||||
#ifdef HAVE_ICU
|
||||
@@ -151,7 +151,7 @@ IcuConverter::FromUTF8(std::string_view s) const
|
||||
throw std::runtime_error(FormatString("Failed to convert from Unicode: %s",
|
||||
u_errorName(code)).c_str());
|
||||
|
||||
return AllocatedString<>::Duplicate({buffer, size_t(target - buffer)});
|
||||
return AllocatedString::Duplicate({buffer, size_t(target - buffer)});
|
||||
|
||||
#elif defined(HAVE_ICONV)
|
||||
return DoConvert(from_utf8, s);
|
||||
|
@@ -40,7 +40,7 @@
|
||||
struct UConverter;
|
||||
#endif
|
||||
|
||||
template<typename T> class AllocatedString;
|
||||
class AllocatedString;
|
||||
|
||||
/**
|
||||
* This class can convert strings with a certain character set to and
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
* Throws std::runtime_error on error.
|
||||
*/
|
||||
gcc_nonnull_all
|
||||
AllocatedString<char> ToUTF8(std::string_view s) const;
|
||||
AllocatedString ToUTF8(std::string_view s) const;
|
||||
|
||||
/**
|
||||
* Convert the string from UTF-8.
|
||||
@@ -93,7 +93,7 @@ public:
|
||||
* Throws std::runtime_error on error.
|
||||
*/
|
||||
gcc_nonnull_all
|
||||
AllocatedString<char> FromUTF8(std::string_view s) const;
|
||||
AllocatedString FromUTF8(std::string_view s) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -48,7 +48,7 @@ UCharFromUTF8(std::string_view src)
|
||||
return dest;
|
||||
}
|
||||
|
||||
AllocatedString<>
|
||||
AllocatedString
|
||||
UCharToUTF8(std::basic_string_view<UChar> src)
|
||||
{
|
||||
/* worst-case estimate */
|
||||
@@ -65,5 +65,5 @@ UCharToUTF8(std::basic_string_view<UChar> src)
|
||||
throw std::runtime_error(u_errorName(error_code));
|
||||
|
||||
dest[dest_length] = 0;
|
||||
return AllocatedString<>::Donate(dest.release());
|
||||
return AllocatedString::Donate(dest.release());
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@
|
||||
#include <string_view>
|
||||
|
||||
template<typename T> class AllocatedArray;
|
||||
template<typename T> class AllocatedString;
|
||||
class AllocatedString;
|
||||
|
||||
/**
|
||||
* Wrapper for u_strFromUTF8().
|
||||
@@ -40,7 +40,7 @@ UCharFromUTF8(std::string_view src);
|
||||
*
|
||||
* Throws std::runtime_error on error.
|
||||
*/
|
||||
AllocatedString<char>
|
||||
AllocatedString
|
||||
UCharToUTF8(std::basic_string_view<UChar> src);
|
||||
|
||||
#endif
|
||||
|
@@ -25,7 +25,7 @@
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
AllocatedString<char>
|
||||
AllocatedString
|
||||
WideCharToMultiByte(unsigned code_page, std::wstring_view src)
|
||||
{
|
||||
int length = WideCharToMultiByte(code_page, 0, src.data(), src.size(),
|
||||
@@ -42,10 +42,10 @@ WideCharToMultiByte(unsigned code_page, std::wstring_view src)
|
||||
throw MakeLastError("Failed to convert from Unicode");
|
||||
|
||||
buffer[length] = '\0';
|
||||
return AllocatedString<char>::Donate(buffer.release());
|
||||
return AllocatedString::Donate(buffer.release());
|
||||
}
|
||||
|
||||
AllocatedString<wchar_t>
|
||||
BasicAllocatedString<wchar_t>
|
||||
MultiByteToWideChar(unsigned code_page, std::string_view src)
|
||||
{
|
||||
int length = MultiByteToWideChar(code_page, 0, src.data(), src.size(),
|
||||
@@ -60,5 +60,5 @@ MultiByteToWideChar(unsigned code_page, std::string_view src)
|
||||
throw MakeLastError("Failed to convert to Unicode");
|
||||
|
||||
buffer[length] = L'\0';
|
||||
return AllocatedString<wchar_t>::Donate(buffer.release());
|
||||
return BasicAllocatedString<wchar_t>::Donate(buffer.release());
|
||||
}
|
||||
|
@@ -24,20 +24,21 @@
|
||||
|
||||
#include <string_view>
|
||||
|
||||
template<typename T> class AllocatedString;
|
||||
class AllocatedString;
|
||||
template<typename T> class BasicAllocatedString;
|
||||
|
||||
/**
|
||||
* Throws std::system_error on error.
|
||||
*/
|
||||
gcc_pure gcc_nonnull_all
|
||||
AllocatedString<char>
|
||||
AllocatedString
|
||||
WideCharToMultiByte(unsigned code_page, std::wstring_view src);
|
||||
|
||||
/**
|
||||
* Throws std::system_error on error.
|
||||
*/
|
||||
gcc_pure gcc_nonnull_all
|
||||
AllocatedString<wchar_t>
|
||||
BasicAllocatedString<wchar_t>
|
||||
MultiByteToWideChar(unsigned code_page, std::string_view src);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user