1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:27:43 +00:00

AK: Add DeprecatedString::from_utf8()

This will be used in Jakt to help transition off of DeprecatedString.
This commit is contained in:
Andreas Kling 2023-01-28 21:08:14 +01:00
parent 6b497b8710
commit 230cb3b0cb
2 changed files with 9 additions and 0 deletions

View file

@ -455,4 +455,11 @@ DeprecatedStringCodePointIterator DeprecatedString::code_points() const
return DeprecatedStringCodePointIterator(*this);
}
ErrorOr<DeprecatedString> DeprecatedString::from_utf8(ReadonlyBytes bytes)
{
if (!Utf8View(bytes).validate())
return Error::from_string_literal("DeprecatedString::from_utf8: Input was not valid UTF-8");
return DeprecatedString { StringImpl::create(bytes) };
}
}