mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-07 01:56:38 +00:00
AK: Implement UTF-16 string-to-number conversions
This commit is contained in:
parent
6e0290ecaa
commit
d40e3af697
Notes:
github-actions[bot]
2025-07-18 16:47:05 +00:00
Author: https://github.com/trflynn89
Commit: d40e3af697
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5388
Reviewed-by: https://github.com/shannonbooth ✅
6 changed files with 163 additions and 45 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <AK/Optional.h>
|
||||
#include <AK/Span.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringConversions.h>
|
||||
#include <AK/StringHash.h>
|
||||
#include <AK/Traits.h>
|
||||
#include <AK/Types.h>
|
||||
|
@ -210,6 +211,14 @@ public:
|
|||
return { m_string.utf16, length_in_code_units() };
|
||||
}
|
||||
|
||||
template<Arithmetic T>
|
||||
ALWAYS_INLINE Optional<T> to_number(TrimWhitespace trim_whitespace = TrimWhitespace::Yes) const
|
||||
{
|
||||
if (has_ascii_storage())
|
||||
return parse_number<T>(bytes(), trim_whitespace);
|
||||
return parse_number<T>(*this, trim_whitespace);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool operator==(Utf16View const& other) const
|
||||
{
|
||||
if (length_in_code_units() != other.length_in_code_units())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue