support html colors, hex/octal/bin integers
This commit is contained in:
@ -16,6 +16,7 @@ enum class node_t
|
||||
data_integer,
|
||||
data_float,
|
||||
data_vector,
|
||||
data_color,
|
||||
data_string,
|
||||
data_istring,
|
||||
data_file,
|
||||
@ -126,6 +127,7 @@ struct node_false;
|
||||
struct node_integer;
|
||||
struct node_float;
|
||||
struct node_vector;
|
||||
struct node_color;
|
||||
struct node_string;
|
||||
struct node_istring;
|
||||
struct node_file;
|
||||
@ -234,6 +236,7 @@ using false_ptr = std::unique_ptr<node_false>;
|
||||
using integer_ptr = std::unique_ptr<node_integer>;
|
||||
using float_ptr = std::unique_ptr<node_float>;
|
||||
using vector_ptr = std::unique_ptr<node_vector>;
|
||||
using color_ptr = std::unique_ptr<node_color>;
|
||||
using string_ptr = std::unique_ptr<node_string>;
|
||||
using istring_ptr = std::unique_ptr<node_istring>;
|
||||
using file_ptr = std::unique_ptr<node_file>;
|
||||
@ -358,6 +361,7 @@ union expr_ptr
|
||||
integer_ptr as_integer;
|
||||
float_ptr as_float;
|
||||
vector_ptr as_vector;
|
||||
color_ptr as_color;
|
||||
string_ptr as_string;
|
||||
istring_ptr as_istring;
|
||||
file_ptr as_file;
|
||||
@ -699,6 +703,27 @@ struct node_vector : public node
|
||||
}
|
||||
};
|
||||
|
||||
struct node_color : public node
|
||||
{
|
||||
std::string value;
|
||||
|
||||
node_color(const std::string& value)
|
||||
: node(node_t::data_color), value(value) {}
|
||||
|
||||
node_color(const location& loc, const std::string& value)
|
||||
: node(node_t::data_color, loc), value(value) {}
|
||||
|
||||
auto print() -> std::string override
|
||||
{
|
||||
return "#"s += value;
|
||||
}
|
||||
|
||||
friend bool operator==(const node_color& lhs, const node_color& rhs)
|
||||
{
|
||||
return lhs.value == rhs.value;
|
||||
}
|
||||
};
|
||||
|
||||
struct node_string : public node
|
||||
{
|
||||
std::string value;
|
||||
|
@ -8,6 +8,21 @@
|
||||
namespace xsk::gsc::utils
|
||||
{
|
||||
|
||||
auto string::oct_to_dec(const char* str) -> std::string
|
||||
{
|
||||
return std::to_string(std::stoi(str, nullptr, 8));
|
||||
}
|
||||
|
||||
auto string::bin_to_dec(const char* str) -> std::string
|
||||
{
|
||||
return std::to_string(std::stoi(&str[2], nullptr, 2)); // str must prefix 0[bB]
|
||||
}
|
||||
|
||||
auto string::hex_to_dec(const char* str) -> std::string
|
||||
{
|
||||
return std::to_string(std::stoi(&str[2], nullptr, 16)); // str must prefix 0[xX]
|
||||
}
|
||||
|
||||
auto string::iequals(const std::string& a, const std::string& b) -> bool
|
||||
{
|
||||
return (a.size() == b.size()) && std::equal(a.begin(), a.end(), b.begin(), b.end(),
|
||||
|
@ -21,6 +21,9 @@ public:
|
||||
return std::string(buf.data(), buf.data() + size - 1);
|
||||
}
|
||||
|
||||
static auto oct_to_dec(const char* str) -> std::string;
|
||||
static auto bin_to_dec(const char* str) -> std::string;
|
||||
static auto hex_to_dec(const char* str) -> std::string;
|
||||
static auto iequals(const std::string& a, const std::string& b) -> bool;
|
||||
static auto is_number(const std::string& s) -> bool;
|
||||
static auto is_hex_number(const std::string& s) -> bool;
|
||||
|
@ -35,6 +35,7 @@ expr_ptr::~expr_ptr()
|
||||
case node_t::data_integer: as_integer.~integer_ptr(); break;
|
||||
case node_t::data_float: as_float.~float_ptr(); break;
|
||||
case node_t::data_vector: as_vector.~vector_ptr(); break;
|
||||
case node_t::data_color: as_color.~color_ptr(); break;
|
||||
case node_t::data_string: as_string.~string_ptr(); break;
|
||||
case node_t::data_istring: as_istring.~istring_ptr(); break;
|
||||
case node_t::data_file: as_file.~file_ptr(); break;
|
||||
@ -156,6 +157,7 @@ bool expr_ptr::operator==(const expr_ptr& rhs) const
|
||||
case node_t::data_integer: return *as_integer == *rhs.as_integer;
|
||||
case node_t::data_float: return *as_float == *rhs.as_float;
|
||||
case node_t::data_vector: return *as_vector == *rhs.as_vector;
|
||||
case node_t::data_color: return *as_color == *rhs.as_color;
|
||||
case node_t::data_string: return *as_string == *rhs.as_string;
|
||||
case node_t::data_istring: return *as_istring == *rhs.as_istring;
|
||||
case node_t::data_file: return *as_file == *rhs.as_file;
|
||||
|
Reference in New Issue
Block a user