mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:17:45 +00:00
AK: Forbid from_utf8
and from_deprecated_{...}
with unintended types
Calling `from_utf8` with a DeprecatedString will hide the fact that we have a DeprecatedString, while using `from_deprecated_string` with a StringView will silently and needlessly allocate a DeprecatedString, so let's forbid that.
This commit is contained in:
parent
02c4b69f16
commit
ca0106ba1d
3 changed files with 14 additions and 1 deletions
|
@ -21,6 +21,10 @@ public:
|
||||||
~FlyString();
|
~FlyString();
|
||||||
|
|
||||||
static ErrorOr<FlyString> from_utf8(StringView);
|
static ErrorOr<FlyString> from_utf8(StringView);
|
||||||
|
template<typename T>
|
||||||
|
requires(IsOneOf<RemoveCVReference<T>, DeprecatedString, DeprecatedFlyString>)
|
||||||
|
static ErrorOr<String> from_utf8(T&&) = delete;
|
||||||
|
|
||||||
FlyString(String const&);
|
FlyString(String const&);
|
||||||
FlyString& operator=(String const&);
|
FlyString& operator=(String const&);
|
||||||
|
|
||||||
|
@ -54,6 +58,9 @@ public:
|
||||||
// FIXME: Remove these once all code has been ported to FlyString
|
// FIXME: Remove these once all code has been ported to FlyString
|
||||||
[[nodiscard]] DeprecatedFlyString to_deprecated_fly_string() const;
|
[[nodiscard]] DeprecatedFlyString to_deprecated_fly_string() const;
|
||||||
static ErrorOr<FlyString> from_deprecated_fly_string(DeprecatedFlyString const&);
|
static ErrorOr<FlyString> from_deprecated_fly_string(DeprecatedFlyString const&);
|
||||||
|
template<typename T>
|
||||||
|
requires(IsSame<RemoveCVReference<T>, StringView>)
|
||||||
|
static ErrorOr<String> from_deprecated_fly_string(T&&) = delete;
|
||||||
|
|
||||||
// Compare this FlyString against another string with ASCII caseless matching.
|
// Compare this FlyString against another string with ASCII caseless matching.
|
||||||
[[nodiscard]] bool equals_ignoring_ascii_case(FlyString const&) const;
|
[[nodiscard]] bool equals_ignoring_ascii_case(FlyString const&) const;
|
||||||
|
|
|
@ -64,6 +64,9 @@ public:
|
||||||
|
|
||||||
// Creates a new String from a sequence of UTF-8 encoded code points.
|
// Creates a new String from a sequence of UTF-8 encoded code points.
|
||||||
static ErrorOr<String> from_utf8(StringView);
|
static ErrorOr<String> from_utf8(StringView);
|
||||||
|
template<typename T>
|
||||||
|
requires(IsOneOf<RemoveCVReference<T>, DeprecatedString, DeprecatedFlyString>)
|
||||||
|
static ErrorOr<String> from_utf8(T&&) = delete;
|
||||||
|
|
||||||
// Creates a new String by reading byte_count bytes from a UTF-8 encoded Stream.
|
// Creates a new String by reading byte_count bytes from a UTF-8 encoded Stream.
|
||||||
static ErrorOr<String> from_stream(Stream&, size_t byte_count);
|
static ErrorOr<String> from_stream(Stream&, size_t byte_count);
|
||||||
|
@ -225,6 +228,9 @@ public:
|
||||||
// FIXME: Remove these once all code has been ported to String
|
// FIXME: Remove these once all code has been ported to String
|
||||||
[[nodiscard]] DeprecatedString to_deprecated_string() const;
|
[[nodiscard]] DeprecatedString to_deprecated_string() const;
|
||||||
static ErrorOr<String> from_deprecated_string(DeprecatedString const&);
|
static ErrorOr<String> from_deprecated_string(DeprecatedString const&);
|
||||||
|
template<typename T>
|
||||||
|
requires(IsSame<RemoveCVReference<T>, StringView>)
|
||||||
|
static ErrorOr<String> from_deprecated_string(T&&) = delete;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// NOTE: If the least significant bit of the pointer is set, this is a short string.
|
// NOTE: If the least significant bit of the pointer is set, this is a short string.
|
||||||
|
|
|
@ -1047,7 +1047,7 @@ ErrorOr<String> mkdtemp(Span<char> pattern)
|
||||||
return Error::from_errno(errno);
|
return Error::from_errno(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
return String::from_utf8({ path, strlen(path) });
|
return String::from_utf8(StringView { path, strlen(path) });
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> rename(StringView old_path, StringView new_path)
|
ErrorOr<void> rename(StringView old_path, StringView new_path)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue