mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
AK: Generalize AK::String::to_int() for more types
This commit is contained in:
parent
39364bdda4
commit
37df4bbd90
Notes:
sideshowbarker
2024-07-19 00:43:10 +09:00
Author: https://github.com/ccapitalK
Commit: 37df4bbd90
Pull-request: https://github.com/SerenityOS/serenity/pull/4459
Issue: https://github.com/SerenityOS/serenity/issues/4377
8 changed files with 93 additions and 24 deletions
|
@ -217,16 +217,28 @@ ByteBuffer String::to_byte_buffer() const
|
|||
return ByteBuffer::copy(reinterpret_cast<const u8*>(characters()), length());
|
||||
}
|
||||
|
||||
Optional<int> String::to_int() const
|
||||
template<typename T>
|
||||
Optional<T> String::to_int() const
|
||||
{
|
||||
return StringUtils::convert_to_int(view());
|
||||
return StringUtils::convert_to_int<T>(view());
|
||||
}
|
||||
|
||||
Optional<unsigned> String::to_uint() const
|
||||
template Optional<i8> String::to_int() const;
|
||||
template Optional<i16> String::to_int() const;
|
||||
template Optional<i32> String::to_int() const;
|
||||
template Optional<i64> String::to_int() const;
|
||||
|
||||
template<typename T>
|
||||
Optional<T> String::to_uint() const
|
||||
{
|
||||
return StringUtils::convert_to_uint(view());
|
||||
return StringUtils::convert_to_uint<T>(view());
|
||||
}
|
||||
|
||||
template Optional<u8> String::to_uint() const;
|
||||
template Optional<u16> String::to_uint() const;
|
||||
template Optional<u32> String::to_uint() const;
|
||||
template Optional<u64> String::to_uint() const;
|
||||
|
||||
template<typename T>
|
||||
String String::number(T value) { return formatted("{}", value); }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue