mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:48:10 +00:00
AK: Generalize AK::String::to_int() for more types
This commit is contained in:
parent
39364bdda4
commit
37df4bbd90
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