diff options
-rw-r--r-- | AK/String.cpp | 15 | ||||
-rw-r--r-- | AK/String.h | 3 | ||||
-rw-r--r-- | Libraries/LibHTML/Parser/HTMLParser.cpp | 16 | ||||
-rw-r--r-- | Libraries/LibHTML/Parser/HTMLParser.h | 1 |
4 files changed, 18 insertions, 17 deletions
diff --git a/AK/String.cpp b/AK/String.cpp index 3ad0ba0a33..4e064b8070 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -391,5 +391,20 @@ bool String::equals_ignoring_case(const StringView& other) const return true; } +String escape_html_entities(const StringView& html) +{ + StringBuilder builder; + for (size_t i = 0; i < html.length(); ++i) { + if (html[i] == '<') + builder.append("<"); + else if (html[i] == '>') + builder.append(">"); + else if (html[i] == '&') + builder.append("&"); + else + builder.append(html[i]); + } + return builder.to_string(); } +} diff --git a/AK/String.h b/AK/String.h index e2c4c72036..71c4a48293 100644 --- a/AK/String.h +++ b/AK/String.h @@ -302,7 +302,10 @@ inline bool operator<=(const char* characters, const String& string) return !(characters > string); } +String escape_html_entities(const StringView& html); + } using AK::CaseInsensitiveStringTraits; using AK::String; +using AK::escape_html_entities; diff --git a/Libraries/LibHTML/Parser/HTMLParser.cpp b/Libraries/LibHTML/Parser/HTMLParser.cpp index 7319d9f157..d105d87750 100644 --- a/Libraries/LibHTML/Parser/HTMLParser.cpp +++ b/Libraries/LibHTML/Parser/HTMLParser.cpp @@ -378,19 +378,3 @@ RefPtr<Document> parse_html_document(const StringView& html, const URL& url) return document; } - -String escape_html_entities(const StringView& html) -{ - StringBuilder builder; - for (size_t i = 0; i < html.length(); ++i) { - if (html[i] == '<') - builder.append("<"); - else if (html[i] == '>') - builder.append(">"); - else if (html[i] == '&') - builder.append("&"); - else - builder.append(html[i]); - } - return builder.to_string(); -} diff --git a/Libraries/LibHTML/Parser/HTMLParser.h b/Libraries/LibHTML/Parser/HTMLParser.h index 9e089d096f..726cae246e 100644 --- a/Libraries/LibHTML/Parser/HTMLParser.h +++ b/Libraries/LibHTML/Parser/HTMLParser.h @@ -33,4 +33,3 @@ class DocumentFragment; RefPtr<Document> parse_html_document(const StringView&, const URL& = URL()); RefPtr<DocumentFragment> parse_html_fragment(Document&, const StringView&); -String escape_html_entities(const StringView&); |