Last active
August 29, 2015 14:09
-
-
Save y-yu/18139b05415ccb179056 to your computer and use it in GitHub Desktop.
CharArray
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
abstract CharArray(String) { | |
inline function new(x) { | |
this = x; | |
} | |
public function get() { return this; } | |
@:from public static inline function fromString(x : String) : CharArray { | |
return new CharArray(x); | |
} | |
@:to public inline function toString() : String { | |
return this; | |
} | |
@:arrayAccess public inline function arrayGet(i:Int) : String { | |
return this.charAt(i); | |
} | |
@:arrayAccess public inline function arraySet(i:Int, v:String) : Void { | |
this = this.substr(0, i) + v + this.substr(i + 1); | |
} | |
// to access String's method | |
@:op(!A) public inline function fieldAccess() : String { | |
return this; | |
} | |
} | |
class Test { | |
static function main() { | |
var x : CharArray = "hoge"; | |
trace(x[1]); | |
trace((!x).substr(1)); // I have no idea except this... | |
x[1] = "O"; | |
trace(x); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment