Ladybird/Qt: Support non-ASCII when converting a QString to a String

QString is UTF-16, thus QString::size returns the number of UTF-16 code
units. Thus, we would fail to perform, for example:

    ak_string_from_qstring(QString("😀"));

Which is 2 UTF-16 code units, but 4 UTF-8 code units.
This commit is contained in:
Timothy Flynn 2023-12-04 10:12:06 -05:00 committed by Andrew Kaster
parent 1aedb0ae5a
commit 82c827fc56
Notes: sideshowbarker 2024-07-17 01:10:58 +09:00

View File

@ -13,7 +13,8 @@ AK::DeprecatedString ak_deprecated_string_from_qstring(QString const& qstring)
ErrorOr<String> ak_string_from_qstring(QString const& qstring)
{
return String::from_utf8(StringView(qstring.toUtf8().data(), qstring.size()));
auto utf8_data = qstring.toUtf8();
return String::from_utf8(StringView(utf8_data.data(), utf8_data.size()));
}
QString qstring_from_ak_string(StringView ak_string)