Skip to content

Instantly share code, notes, and snippets.

@tadzik
Created August 18, 2011 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tadzik/1155010 to your computer and use it in GitHub Desktop.
Save tadzik/1155010 to your computer and use it in GitHub Desktop.
diff --git a/lib/Text/Escape.pm b/lib/Text/Escape.pm
index 2c9e840..5ba682b 100644
--- a/lib/Text/Escape.pm
+++ b/lib/Text/Escape.pm
@@ -1,10 +1,16 @@
use v6;
module Text::Escape;
+sub escape-html($str as Str) is export {
+ $str.subst('&', '&amp;', :g).subst('<', '&lt;', :g
+ ).subst('>', '&gt;', :g).subst('"', '&quot;', :g
+ ).subst("'", '&#39;', :g);
+}
+
sub escape($str as Str, Str $how) is export {
given $how.lc {
when 'none' { $str }
- when 'html' { escape_str($str, &escape_html_char) }
+ when 'html' { escape-html($str) }
when 'uri' | 'url' { escape_str($str, &escape_uri_char) }
default { fail "Don't know how to escape format $how yet" }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment