Added html special chars methods to the string.

This commit is contained in:
Relintai 2022-02-04 06:37:14 +01:00
parent 33be242319
commit 33ba5337b7
2 changed files with 19 additions and 0 deletions

View File

@ -915,6 +915,22 @@ void String::append_repeat(const String &other, const int times) {
}
}
void String::to_html_special_chars() {
replace("&", "&");
replace("\"", """);
replace("'", "'");
replace("<", "&lt;");
replace(">", "&gt;");
}
void String::from_html_special_chars() {
replace("&amp;", "&");
replace("&quot;", "\"");
replace("&#039;", "'");
replace("&lt;", "<");
replace("&gt;", ">");
}
bool String::to_bool() const {
if (_size == 0) {
return 0;

View File

@ -97,6 +97,9 @@ public:
void append_repeat(const char* str, const int times);
void append_repeat(const String &other, const int times);
void to_html_special_chars();
void from_html_special_chars();
bool to_bool() const;
float to_float() const;
double to_double() const;