mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2025-02-20 15:14:26 +01:00
Implement parse for variants.
This commit is contained in:
parent
3d81df493c
commit
b8442280dd
@ -951,6 +951,44 @@ int String::to_int() const {
|
|||||||
return atoi(c_str());
|
return atoi(c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool String::is_bool() const {
|
||||||
|
if (_size == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_size == 1) {
|
||||||
|
if (_data[0] == '0') {
|
||||||
|
return true;
|
||||||
|
} else if (_data[0] == '1') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_size == 4) {
|
||||||
|
String l = as_lower();
|
||||||
|
|
||||||
|
if (l[0] == 't' && l[1] == 'r' && l[2] == 'u' && l[3] == 'e') {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_size == 5) {
|
||||||
|
String l = as_lower();
|
||||||
|
|
||||||
|
if (l[0] == 'f' && l[1] == 'a' && l[2] == 'l' && l[3] == 's' && l[3] == 'e') {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool String::is_numeric() const {
|
bool String::is_numeric() const {
|
||||||
if (_size == 0) {
|
if (_size == 0) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -102,6 +102,7 @@ public:
|
|||||||
double to_double() const;
|
double to_double() const;
|
||||||
int to_int() const;
|
int to_int() const;
|
||||||
|
|
||||||
|
bool is_bool() const;
|
||||||
bool is_numeric() const;
|
bool is_numeric() const;
|
||||||
bool is_int() const;
|
bool is_int() const;
|
||||||
bool is_uint() const;
|
bool is_uint() const;
|
||||||
|
@ -79,9 +79,34 @@ void Variant::zero() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Variant::parse(const String &str) {
|
void Variant::parse(const String &str) {
|
||||||
|
if (str.is_bool()) {
|
||||||
|
set_bool(str.to_bool());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str.is_int()) {
|
||||||
|
set_int(str.to_int());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str.is_uint()) {
|
||||||
|
set_uint(str.to_uint());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str.is_numeric()) {
|
||||||
|
set_float(str.to_float());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
set_string(str);
|
||||||
}
|
}
|
||||||
Variant Variant::parse_string(const String &str) {
|
Variant Variant::parse_string(const String &str) {
|
||||||
return Variant();
|
Variant v = Variant();
|
||||||
|
|
||||||
|
v.parse(str);
|
||||||
|
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Variant::is_null() const {
|
bool Variant::is_null() const {
|
||||||
|
Loading…
Reference in New Issue
Block a user