mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:57:35 +00:00
LibJS+LibCrypto: Allow '_' as a numeric literal separator :^)
This patch adds support for the NumericLiteralSeparator concept from the ECMAScript grammar.
This commit is contained in:
parent
527c639c1f
commit
49018553d3
4 changed files with 61 additions and 15 deletions
|
@ -72,6 +72,8 @@ UnsignedBigInteger UnsignedBigInteger::from_base10(const String& str)
|
|||
UnsignedBigInteger ten { 10 };
|
||||
|
||||
for (auto& c : str) {
|
||||
if (c == '_')
|
||||
continue;
|
||||
result = result.multiplied_by(ten).plus(parse_ascii_digit(c));
|
||||
}
|
||||
return result;
|
||||
|
@ -83,6 +85,8 @@ UnsignedBigInteger UnsignedBigInteger::from_base2(const String& str)
|
|||
UnsignedBigInteger two { 2 };
|
||||
|
||||
for (auto& c : str) {
|
||||
if (c == '_')
|
||||
continue;
|
||||
result = result.multiplied_by(two).plus(parse_ascii_digit(c));
|
||||
}
|
||||
return result;
|
||||
|
@ -94,6 +98,8 @@ UnsignedBigInteger UnsignedBigInteger::from_base8(const String& str)
|
|||
UnsignedBigInteger eight { 8 };
|
||||
|
||||
for (auto& c : str) {
|
||||
if (c == '_')
|
||||
continue;
|
||||
result = result.multiplied_by(eight).plus(parse_ascii_digit(c));
|
||||
}
|
||||
return result;
|
||||
|
@ -105,6 +111,8 @@ UnsignedBigInteger UnsignedBigInteger::from_base16(const String& str)
|
|||
UnsignedBigInteger sixteen { 16 };
|
||||
|
||||
for (auto& c : str) {
|
||||
if (c == '_')
|
||||
continue;
|
||||
result = result.multiplied_by(sixteen).plus(parse_ascii_hex_digit(c));
|
||||
}
|
||||
return result;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue