diff --git a/AK/DeprecatedString.cpp b/AK/DeprecatedString.cpp index 0b1064f9900..9c45cced074 100644 --- a/AK/DeprecatedString.cpp +++ b/AK/DeprecatedString.cpp @@ -455,4 +455,11 @@ DeprecatedStringCodePointIterator DeprecatedString::code_points() const return DeprecatedStringCodePointIterator(*this); } +ErrorOr 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) }; +} + } diff --git a/AK/DeprecatedString.h b/AK/DeprecatedString.h index 0155fcdf19a..35474f9bffc 100644 --- a/AK/DeprecatedString.h +++ b/AK/DeprecatedString.h @@ -95,6 +95,8 @@ public: DeprecatedString(DeprecatedFlyString const&); + static ErrorOr from_utf8(ReadonlyBytes); + [[nodiscard]] static DeprecatedString repeated(char, size_t count); [[nodiscard]] static DeprecatedString repeated(StringView, size_t count);