mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2025-05-02 13:47:56 +02:00
Add size check to string to number conversion methods.
This commit is contained in:
parent
557c2a3934
commit
e79ddd1b4a
@ -904,6 +904,10 @@ void String::append_repeat(const String &other, const int times) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool String::to_bool() const {
|
bool String::to_bool() const {
|
||||||
|
if (_size == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (is_numeric()) {
|
if (is_numeric()) {
|
||||||
return to_int() != 0;
|
return to_int() != 0;
|
||||||
}
|
}
|
||||||
@ -912,14 +916,26 @@ bool String::to_bool() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float String::to_float() const {
|
float String::to_float() const {
|
||||||
|
if (_size == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return atof(c_str());
|
return atof(c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
double String::to_double() const {
|
double String::to_double() const {
|
||||||
|
if (_size == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return atof(c_str());
|
return atof(c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
int String::to_int() const {
|
int String::to_int() const {
|
||||||
|
if (_size == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return atoi(c_str());
|
return atoi(c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user