diff options
Diffstat (limited to 'AK/String.cpp')
-rw-r--r-- | AK/String.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/AK/String.cpp b/AK/String.cpp index e589438c1b..ccc61dd08f 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -75,4 +75,19 @@ ByteBuffer String::toByteBuffer() const return ByteBuffer::copy(reinterpret_cast<const byte*>(characters()), length()); } +unsigned String::toUInt(bool& ok) const +{ + unsigned value = 0; + for (size_t i = 0; i < length(); ++i) { + if (characters()[i] < '0' || characters()[i] > '9') { + ok = false; + return 0; + } + value = value * 10; + value += characters()[i] - '0'; + } + ok = true; + return value; +} + } |