ladybird/Userland/Libraries/LibSQL/Token.cpp
Brian Gianforcaro 1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00

54 lines
1.2 KiB
C++

/*
* Copyright (c) 2021, Tim Flynn <trflynn89@pm.me>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "Token.h"
#include <AK/Assertions.h>
#include <AK/String.h>
#include <stdlib.h>
namespace SQL {
StringView Token::name(TokenType type)
{
switch (type) {
#define __ENUMERATE_SQL_TOKEN(value, type, category) \
case TokenType::type: \
return #type;
ENUMERATE_SQL_TOKENS
#undef __ENUMERATE_SQL_TOKEN
default:
VERIFY_NOT_REACHED();
}
}
TokenCategory Token::category(TokenType type)
{
switch (type) {
#define __ENUMERATE_SQL_TOKEN(value, type, category) \
case TokenType::type: \
return TokenCategory::category;
ENUMERATE_SQL_TOKENS
#undef __ENUMERATE_SQL_TOKEN
default:
VERIFY_NOT_REACHED();
}
}
double Token::double_value() const
{
VERIFY(type() == TokenType::NumericLiteral);
String value(m_value);
if (value[0] == '0' && value.length() >= 2) {
if (value[1] == 'x' || value[1] == 'X')
return static_cast<double>(strtoul(value.characters() + 2, nullptr, 16));
}
return strtod(value.characters(), nullptr);
}
}