mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-05 06:32:30 +02: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:
Notes:
sideshowbarker
2024-07-18 11:29:05 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/49018553d33
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user