diff options
author | Max Kellermann <mk@cm4all.com> | 2021-01-14 12:39:45 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2021-03-04 18:03:56 +0100 |
commit | cfb7f8ab84ca4c2d6d2f2826f893992c27a7f591 (patch) | |
tree | 78a5491811fa0384e1a810fe46a82bbdb04a06fb /src/lib | |
parent | 8d80280ab9ac9ec17abd981990771ea9927767a3 (diff) |
util/AllocatedString: rename to BasicAllocatedString
To make things simpler, AllocatedString is now a non-template class.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/icu/CaseFold.cxx | 8 | ||||
-rw-r--r-- | src/lib/icu/CaseFold.hxx | 4 | ||||
-rw-r--r-- | src/lib/icu/Collate.cxx | 2 | ||||
-rw-r--r-- | src/lib/icu/Compare.cxx | 2 | ||||
-rw-r--r-- | src/lib/icu/Compare.hxx | 4 | ||||
-rw-r--r-- | src/lib/icu/Converter.cxx | 10 | ||||
-rw-r--r-- | src/lib/icu/Converter.hxx | 6 | ||||
-rw-r--r-- | src/lib/icu/Util.cxx | 4 | ||||
-rw-r--r-- | src/lib/icu/Util.hxx | 4 | ||||
-rw-r--r-- | src/lib/icu/Win32.cxx | 8 | ||||
-rw-r--r-- | src/lib/icu/Win32.hxx | 7 |
11 files changed, 30 insertions, 29 deletions
diff --git a/src/lib/icu/CaseFold.cxx b/src/lib/icu/CaseFold.cxx index edc466a48..ebb75f324 100644 --- a/src/lib/icu/CaseFold.cxx +++ b/src/lib/icu/CaseFold.cxx @@ -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 */ diff --git a/src/lib/icu/CaseFold.hxx b/src/lib/icu/CaseFold.hxx index 73d4e2289..3aed54af0 100644 --- a/src/lib/icu/CaseFold.hxx +++ b/src/lib/icu/CaseFold.hxx @@ -27,9 +27,9 @@ #include <string_view> -template<typename T> class AllocatedString; +class AllocatedString; -AllocatedString<char> +AllocatedString IcuCaseFold(std::string_view src) noexcept; #endif diff --git a/src/lib/icu/Collate.cxx b/src/lib/icu/Collate.cxx index 859e60978..c31f46883 100644 --- a/src/lib/icu/Collate.cxx +++ b/src/lib/icu/Collate.cxx @@ -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); diff --git a/src/lib/icu/Compare.cxx b/src/lib/icu/Compare.cxx index 14184752d..6bc82bdd5 100644 --- a/src/lib/icu/Compare.cxx +++ b/src/lib/icu/Compare.cxx @@ -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 diff --git a/src/lib/icu/Compare.hxx b/src/lib/icu/Compare.hxx index 2751f1b4b..6f4841739 100644 --- a/src/lib/icu/Compare.hxx +++ b/src/lib/icu/Compare.hxx @@ -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: diff --git a/src/lib/icu/Converter.cxx b/src/lib/icu/Converter.cxx index 228010c80..a231668a8 100644 --- a/src/lib/icu/Converter.cxx +++ b/src/lib/icu/Converter.cxx @@ -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); diff --git a/src/lib/icu/Converter.hxx b/src/lib/icu/Converter.hxx index 8368cc166..fc7d6ae40 100644 --- a/src/lib/icu/Converter.hxx +++ b/src/lib/icu/Converter.hxx @@ -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 diff --git a/src/lib/icu/Util.cxx b/src/lib/icu/Util.cxx index 3087bed73..a473f987b 100644 --- a/src/lib/icu/Util.cxx +++ b/src/lib/icu/Util.cxx @@ -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()); } diff --git a/src/lib/icu/Util.hxx b/src/lib/icu/Util.hxx index 7b2958e22..835acb4f6 100644 --- a/src/lib/icu/Util.hxx +++ b/src/lib/icu/Util.hxx @@ -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 diff --git a/src/lib/icu/Win32.cxx b/src/lib/icu/Win32.cxx index e556a3b2b..05da2ef49 100644 --- a/src/lib/icu/Win32.cxx +++ b/src/lib/icu/Win32.cxx @@ -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()); } diff --git a/src/lib/icu/Win32.hxx b/src/lib/icu/Win32.hxx index ab804d82c..287495010 100644 --- a/src/lib/icu/Win32.hxx +++ b/src/lib/icu/Win32.hxx @@ -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 |