Skip to content

Instantly share code, notes, and snippets.

@jdonaldson
Last active August 29, 2015 14:22
Show Gist options
  • Save jdonaldson/9a09287e540e7392857f to your computer and use it in GitHub Desktop.
Save jdonaldson/9a09287e540e7392857f to your computer and use it in GitHub Desktop.
Unsafe String abstract
class Main {
static function main() {
var us = new Unsafe("<b>hi!</b>");
foo(us);
}
static function foo(s:String){
trace(s);
}
}
abstract Unsafe(String) {
inline public function new(s:String){
this = s;
}
@:to
public function toString() : String {
return StringTools.htmlEscape(this) ;
}
@:to
public static function fromString(s:String) {
return new Unsafe(s);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment