|
@@ -151,8 +151,18 @@ class StringTools {
|
|
- `'` becomes `'`;
|
|
- `'` becomes `'`;
|
|
**/
|
|
**/
|
|
public static function htmlEscape( s : String, ?quotes : Bool ) : String {
|
|
public static function htmlEscape( s : String, ?quotes : Bool ) : String {
|
|
- s = s.split("&").join("&").split("<").join("<").split(">").join(">");
|
|
|
|
- return quotes ? s.split('"').join(""").split("'").join("'") : s;
|
|
|
|
|
|
+ var buf = new StringBuf();
|
|
|
|
+ for (code in new haxe.iterators.StringIteratorUnicode(s)) {
|
|
|
|
+ switch (code) {
|
|
|
|
+ case '&'.code: buf.add("&");
|
|
|
|
+ case '<'.code: buf.add("<");
|
|
|
|
+ case '>'.code: buf.add(">");
|
|
|
|
+ case '"'.code if (quotes): buf.add(""");
|
|
|
|
+ case '\''.code if (quotes): buf.add("'");
|
|
|
|
+ case _: buf.addChar(code);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return buf.toString();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|