Skip to content

Commit

Permalink
replace new CodePoint with CodePoint.fromInt
Browse files Browse the repository at this point in the history
[breaking-change]
  • Loading branch information
mandel59 committed Sep 1, 2015
1 parent 09b45cb commit 958d805
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Main {
trace("日本語".uLength()); // ==> 3
trace("русский".uCharAt(5)); // ==> и
trace("🍺".uCodePointAt(0).toInt()); // ==> 127866
trace(new CodePoint(0x1F37B)); // ==> 🍻
trace(CodePoint.fromInt(0x1F37B)); // ==> 🍻
for (c in "♠♡♢♣".uIterator()) {
trace(c);
trace(c + 4);
Expand Down
4 changes: 2 additions & 2 deletions test/TestCodePoint.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class TestCodePoint extends haxe.unit.TestCase {
}

public function test_CodePoint_cons_and_snoc() {
assertEquals("𩸽あëa", new CodePoint(0x29E3D) + "あëa");
assertEquals("あëa𩸽", "あëa" + new CodePoint(0x29E3D));
assertEquals("𩸽あëa", CodePoint.fromInt(0x29E3D) + "あëa");
assertEquals("あëa𩸽", "あëa" + CodePoint.fromInt(0x29E3D));
}

}
2 changes: 1 addition & 1 deletion test/TestUtf32.hx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TestUtf32 extends haxe.unit.TestCase {
}

public function test_cons_and_snoc() {
var c = new CodePoint(0x29E3D);
var c = CodePoint.fromInt(0x29E3D);
assertTrue(Utf32.fromString("𩸽あëa") == c + Utf32.fromString("あëa"));
assertTrue(Utf32.fromString("あëa𩸽") == Utf32.fromString("あëa") + c);
}
Expand Down
13 changes: 9 additions & 4 deletions unifill/CodePoint.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ package unifill;

abstract CodePoint(Int) {

@:from
public static inline function fromInt(code : Int) : CodePoint {
if (!Unicode.isScalar(code)) {
throw Exception.InvalidCodePoint(code);
}
return new CodePoint(code);
}

@:op(A + B)
public static inline function cons(a : CodePoint, b : String) : String
return a.toString() + b;
Expand Down Expand Up @@ -29,10 +37,7 @@ abstract CodePoint(Int) {
@:op(A > B) public static function gt(a : CodePoint, b : CodePoint) : Bool;
@:op(A >= B) public static function gte(a : CodePoint, b : CodePoint) : Bool;

public inline function new(code : Int) : Void {
if (!Unicode.isScalar(code)) {
throw Exception.InvalidCodePoint(code);
}
inline function new(code : Int) : Void {
this = code;
}

Expand Down

0 comments on commit 958d805

Please sign in to comment.