aboutsummaryrefslogtreecommitdiff
path: root/src/NetUtils.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-07-19 19:28:45 +0200
committerdec05eba <dec05eba@protonmail.com>2021-07-19 19:28:45 +0200
commitcd4d2e98c34ed413ca164dbad61ba19636377f77 (patch)
tree69a1ab7f19acc4b9abf016025921efed3b80c2a9 /src/NetUtils.cpp
parente671784144174c4fceaa6df3737ba9b4de4a6c63 (diff)
Add hotexamples
Diffstat (limited to 'src/NetUtils.cpp')
-rw-r--r--src/NetUtils.cpp39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/NetUtils.cpp b/src/NetUtils.cpp
index cc19094..28256cb 100644
--- a/src/NetUtils.cpp
+++ b/src/NetUtils.cpp
@@ -34,12 +34,43 @@ namespace QuickMedia {
std::string unescaped_str;
};
+ static bool to_num(const char *str, size_t size, int &num) {
+ num = 0;
+ for(size_t i = 0; i < size; ++i) {
+ const char num_c = str[i] - '0';
+ if(num_c < 0 || num_c > 9)
+ return false;
+ num = (num * 10) + num_c;
+ }
+ return true;
+ }
+
+ static void html_unescape_sequence_numbers(std::string &str) {
+ size_t index = 0;
+ while(true) {
+ index = str.find("&#", index);
+ if(index == std::string::npos)
+ break;
+
+ index += 2;
+ size_t end_index = str.find(';', index);
+ if(end_index != std::string::npos && end_index - index <= 3) {
+ const size_t num_length = end_index - index;
+ int num;
+ if(to_num(str.c_str() + index, num_length, num)) {
+ const char num_c = (char)num;
+ str.replace(index - 2, 2 + num_length + 1, &num_c, 1);
+ index += (-2 + 1);
+ }
+ }
+ }
+ }
+
void html_unescape_sequences(std::string &str) {
- const std::array<HtmlUnescapeSequence, 7> unescape_sequences = {
+ html_unescape_sequence_numbers(str);
+
+ const std::array<HtmlUnescapeSequence, 4> unescape_sequences = {
HtmlUnescapeSequence { "&quot;", "\"" },
- HtmlUnescapeSequence { "&#039;", "'" },
- HtmlUnescapeSequence { "&#39;", "'" },
- HtmlUnescapeSequence { "&#10;", "\n" },
HtmlUnescapeSequence { "&lt;", "<" },
HtmlUnescapeSequence { "&gt;", ">" },
HtmlUnescapeSequence { "&amp;", "&" } // This should be last, to not accidentally replace a new sequence caused by replacing this