util/AllocatedString: add string_view constructor
Replaces the static Duplicate() method.
This commit is contained in:

committed by
Max Kellermann

parent
1caf57644f
commit
a81c9bfb81
@@ -44,7 +44,7 @@ try {
|
||||
#ifdef HAVE_ICU
|
||||
const auto u = UCharFromUTF8(src);
|
||||
if (u.IsNull())
|
||||
return AllocatedString::Duplicate(src);
|
||||
return AllocatedString(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(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(src);
|
||||
}
|
||||
|
||||
#endif /* HAVE_ICU_CASE_FOLD */
|
||||
|
@@ -46,7 +46,7 @@ IcuCompare::IcuCompare(std::string_view _needle) noexcept
|
||||
#else
|
||||
|
||||
IcuCompare::IcuCompare(std::string_view _needle) noexcept
|
||||
:needle(AllocatedString::Duplicate(_needle)) {}
|
||||
:needle(_needle) {}
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -95,7 +95,7 @@ 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({buffer, sizeof(buffer) - out_left});
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -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({buffer, size_t(target - buffer)});
|
||||
|
||||
#elif defined(HAVE_ICONV)
|
||||
return DoConvert(from_utf8, s);
|
||||
|
Reference in New Issue
Block a user