summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-02-13 08:46:00 +0100
committerAndreas Kling <kling@serenityos.org>2020-02-13 08:46:00 +0100
commit3e486f75ff76463aad5ddb4dc6825fe017b49c27 (patch)
tree44447bfa65553ac20e7dba9f525d05c9505c822a
parentdeca1d8b77b39226fc557c73337191798b1c72c2 (diff)
downloadserenity-3e486f75ff76463aad5ddb4dc6825fe017b49c27.zip
AK: Move escape_html_entities() from LibHTML to AK
This sort of thing can be useful to things that don't want to link with all of LibHTML.
-rw-r--r--AK/String.cpp15
-rw-r--r--AK/String.h3
-rw-r--r--Libraries/LibHTML/Parser/HTMLParser.cpp16
-rw-r--r--Libraries/LibHTML/Parser/HTMLParser.h1
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("&lt;");
+ else if (html[i] == '>')
+ builder.append("&gt;");
+ else if (html[i] == '&')
+ builder.append("&amp;");
+ 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("&lt;");
- else if (html[i] == '>')
- builder.append("&gt;");
- else if (html[i] == '&')
- builder.append("&amp;");
- 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&);