util/AllocatedString: add string_view constructor

Replaces the static Duplicate() method.
This commit is contained in:
Max Kellermann
2021-01-14 13:16:52 +01:00
committed by Max Kellermann
parent 32b7b2e2fa
commit 6e1c8edf09
5 changed files with 18 additions and 14 deletions

View File

@@ -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);