mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Implement StringView::to_number<T> from String::to_number<T>
Do exactly what String does, then use StringView's implementation as String's new one. This should allow us to call to_number on a StringView.
This commit is contained in:
parent
b63eb4a4dd
commit
cdf84a3e36
Notes:
sideshowbarker
2024-07-16 17:05:37 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/cdf84a3e36 Pull-request: https://github.com/SerenityOS/serenity/pull/22400
2 changed files with 14 additions and 8 deletions
|
@ -181,14 +181,7 @@ public:
|
|||
template<Arithmetic T>
|
||||
Optional<T> to_number(TrimWhitespace trim_whitespace = TrimWhitespace::Yes) const
|
||||
{
|
||||
#ifndef KERNEL
|
||||
if constexpr (IsFloatingPoint<T>)
|
||||
return StringUtils::convert_to_floating_point<T>(bytes_as_string_view(), trim_whitespace);
|
||||
#endif
|
||||
if constexpr (IsSigned<T>)
|
||||
return StringUtils::convert_to_int<T>(bytes_as_string_view(), trim_whitespace);
|
||||
else
|
||||
return StringUtils::convert_to_uint<T>(bytes_as_string_view(), trim_whitespace);
|
||||
return bytes_as_string_view().to_number<T>(trim_whitespace);
|
||||
}
|
||||
|
||||
static ErrorOr<String> vformatted(StringView fmtstr, TypeErasedFormatParams&);
|
||||
|
|
|
@ -353,6 +353,19 @@ public:
|
|||
}());
|
||||
}
|
||||
|
||||
template<Arithmetic T>
|
||||
Optional<T> to_number(TrimWhitespace trim_whitespace = TrimWhitespace::Yes) const
|
||||
{
|
||||
#ifndef KERNEL
|
||||
if constexpr (IsFloatingPoint<T>)
|
||||
return StringUtils::convert_to_floating_point<T>(*this, trim_whitespace);
|
||||
#endif
|
||||
if constexpr (IsSigned<T>)
|
||||
return StringUtils::convert_to_int<T>(*this, trim_whitespace);
|
||||
else
|
||||
return StringUtils::convert_to_uint<T>(*this, trim_whitespace);
|
||||
}
|
||||
|
||||
private:
|
||||
friend class ByteString;
|
||||
char const* m_characters { nullptr };
|
||||
|
|
Loading…
Reference in a new issue