mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:27:43 +00:00
LibJS: Use the new is_ascii_foo() helpers from AK
These constexpr helpers generate nicer code than the LibC ctype.h variants, so let's make use of them. :^)
This commit is contained in:
parent
d476144565
commit
39ad705c13
5 changed files with 30 additions and 31 deletions
|
@ -7,9 +7,9 @@
|
|||
|
||||
#include "Token.h"
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/CharacterTypes.h>
|
||||
#include <AK/GenericLexer.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <ctype.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
|
@ -64,7 +64,7 @@ double Token::double_value() const
|
|||
} else if (value_string[1] == 'b' || value_string[1] == 'B') {
|
||||
// binary
|
||||
return static_cast<double>(strtoul(value_string.characters() + 2, nullptr, 2));
|
||||
} else if (isdigit(value_string[1])) {
|
||||
} else if (is_ascii_digit(value_string[1])) {
|
||||
// also octal, but syntax error in strict mode
|
||||
if (!m_value.contains('8') && !m_value.contains('9'))
|
||||
return static_cast<double>(strtoul(value_string.characters() + 1, nullptr, 8));
|
||||
|
@ -75,10 +75,10 @@ double Token::double_value() const
|
|||
|
||||
static u32 hex2int(char x)
|
||||
{
|
||||
VERIFY(isxdigit(x));
|
||||
VERIFY(is_ascii_hex_digit(x));
|
||||
if (x >= '0' && x <= '9')
|
||||
return x - '0';
|
||||
return 10u + (tolower(x) - 'a');
|
||||
return 10u + (to_ascii_lowercase(x) - 'a');
|
||||
}
|
||||
|
||||
String Token::string_value(StringValueStatus& status) const
|
||||
|
@ -115,7 +115,7 @@ String Token::string_value(StringValueStatus& status) const
|
|||
continue;
|
||||
}
|
||||
// Null-byte escape
|
||||
if (lexer.next_is('0') && !isdigit(lexer.peek(1))) {
|
||||
if (lexer.next_is('0') && !is_ascii_digit(lexer.peek(1))) {
|
||||
lexer.ignore();
|
||||
builder.append('\0');
|
||||
continue;
|
||||
|
@ -123,7 +123,7 @@ String Token::string_value(StringValueStatus& status) const
|
|||
// Hex escape
|
||||
if (lexer.next_is('x')) {
|
||||
lexer.ignore();
|
||||
if (!isxdigit(lexer.peek()) || !isxdigit(lexer.peek(1)))
|
||||
if (!is_ascii_hex_digit(lexer.peek()) || !is_ascii_hex_digit(lexer.peek(1)))
|
||||
return encoding_failure(StringValueStatus::MalformedHexEscape);
|
||||
auto code_point = hex2int(lexer.consume()) * 16 + hex2int(lexer.consume());
|
||||
VERIFY(code_point <= 255);
|
||||
|
@ -137,7 +137,7 @@ String Token::string_value(StringValueStatus& status) const
|
|||
if (lexer.next_is('{')) {
|
||||
lexer.ignore();
|
||||
while (true) {
|
||||
if (!lexer.next_is(isxdigit))
|
||||
if (!lexer.next_is(is_ascii_hex_digit))
|
||||
return encoding_failure(StringValueStatus::MalformedUnicodeEscape);
|
||||
auto new_code_point = (code_point << 4u) | hex2int(lexer.consume());
|
||||
if (new_code_point < code_point)
|
||||
|
@ -149,7 +149,7 @@ String Token::string_value(StringValueStatus& status) const
|
|||
lexer.ignore();
|
||||
} else {
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
if (!lexer.next_is(isxdigit))
|
||||
if (!lexer.next_is(is_ascii_hex_digit))
|
||||
return encoding_failure(StringValueStatus::MalformedUnicodeEscape);
|
||||
code_point = (code_point << 4u) | hex2int(lexer.consume());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue