return buf.to_s
end
+ # Escape the four characters `<`, `>`, `&`, and `"` with their html counterpart
+ #
+ # assert "a&b->\"x\"".html_escape == "a&b->"x""
+ fun html_escape: SELFTYPE
+ do
+ var buf = new FlatBuffer
+
+ for i in [0..length[ do
+ var c = chars[i]
+ if c == '&' then
+ buf.append "&"
+ else if c == '<' then
+ buf.append "<"
+ else if c == '>' then
+ buf.append ">"
+ else if c == '"' then
+ buf.append """
+ else buf.add c
+ end
+
+ return buf.to_s
+ end
+
# Equality of text
# Two pieces of text are equals if thez have the same characters in the same order.
#
do
return self.split_with(p).join(string)
end
-
- # Escape the four characters `<`, `>`, `&`, and `"` with their html counterpart
- #
- # assert "a&b->\"x\"".html_escape == "a&b->"x""
- fun html_escape: SELFTYPE
- do
- var ret = self
- if ret.chars.has('&') then ret = ret.replace('&', "&")
- if ret.chars.has('<') then ret = ret.replace('<', "<")
- if ret.chars.has('>') then ret = ret.replace('>', ">")
- if ret.chars.has('"') then ret = ret.replace('"', """)
- return ret
- end
end