mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Add reinterpret_as_octal()
This is useful for parsing user-provided integers that should be interpreted as octals.
This commit is contained in:
parent
57f0ea186e
commit
f923016e0b
Notes:
sideshowbarker
2024-07-17 07:11:12 +09:00
Author: https://github.com/implicitfield Commit: https://github.com/SerenityOS/serenity/commit/f923016e0b Pull-request: https://github.com/SerenityOS/serenity/pull/23098 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/supercomputer7
1 changed files with 12 additions and 0 deletions
|
@ -75,4 +75,16 @@ constexpr bool is_power_of(U x)
|
|||
return true;
|
||||
}
|
||||
|
||||
template<Unsigned T>
|
||||
constexpr T reinterpret_as_octal(T decimal)
|
||||
{
|
||||
T result = 0;
|
||||
T n = 0;
|
||||
while (decimal > 0) {
|
||||
result += pow<T>(8, n++) * (decimal % 10);
|
||||
decimal /= 10;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue