Last active
August 29, 2015 14:22
-
-
Save jdonaldson/9a09287e540e7392857f to your computer and use it in GitHub Desktop.
Unsafe String abstract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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