util/AllocatedArray: migrate from {Const,Writable}Buffer to std::span

This commit is contained in:
Max Kellermann
2022-05-11 16:19:44 +02:00
committed by Max Kellermann
parent 23dd613ff9
commit 5fb97b81d1
15 changed files with 93 additions and 103 deletions

View File

@@ -43,21 +43,21 @@ IcuCaseFold(std::string_view src) noexcept
try {
#ifdef HAVE_ICU
const auto u = UCharFromUTF8(src);
if (u.IsNull())
if (u.data() == nullptr)
return {src};
AllocatedArray<UChar> folded(u.size() * 2U);
UErrorCode error_code = U_ZERO_ERROR;
size_t folded_length = u_strFoldCase(folded.begin(), folded.size(),
u.begin(), u.size(),
size_t folded_length = u_strFoldCase(folded.data(), folded.size(),
u.data(), u.size(),
U_FOLD_CASE_DEFAULT,
&error_code);
if (folded_length == 0 || error_code != U_ZERO_ERROR)
return {src};
folded.SetSize(folded_length);
return UCharToUTF8({folded.begin(), folded.size()});
return UCharToUTF8(std::basic_string_view{folded.data(), folded.size()});
#else
#error not implemented

View File

@@ -141,11 +141,11 @@ IcuConverter::FromUTF8(std::string_view s) const
// TODO: dynamic buffer?
char buffer[4096], *target = buffer;
const UChar *source = u.begin();
const UChar *source = u.data();
UErrorCode code = U_ZERO_ERROR;
ucnv_fromUnicode(converter, &target, buffer + std::size(buffer),
&source, u.end(),
&source, u.data() + u.size(),
nullptr, true, &code);
if (code != U_ZERO_ERROR)

View File

@@ -38,7 +38,7 @@ UCharFromUTF8(std::string_view src)
UErrorCode error_code = U_ZERO_ERROR;
int32_t dest_length;
u_strFromUTF8(dest.begin(), dest_capacity, &dest_length,
u_strFromUTF8(dest.data(), dest_capacity, &dest_length,
src.data(), src.size(),
&error_code);
if (U_FAILURE(error_code))