mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
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.
This commit is contained in:
parent
deca1d8b77
commit
3e486f75ff
Notes:
sideshowbarker
2024-07-19 09:21:57 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/3e486f75ff7
4 changed files with 18 additions and 17 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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&);
|
||||
|
|
Loading…
Reference in a new issue