Skip to content

Commit

Permalink
Support the java target. (#2)
Browse files Browse the repository at this point in the history
Fix creating utf16 from an array.
  • Loading branch information
skial authored May 14, 2019
1 parent 6361e5a commit 78c1910
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .haxerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "0826bf6",
"version": "92c7833",
"resolveLibs": "scoped"
}
13 changes: 13 additions & 0 deletions build.java.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-lib hx3compat

-dce full
-D eval-stack
-D analyzer-optimize

-main test.Main

--each

#-D jvm
-java test/test_java
-cmd java -jar test/test_java/Main.jar
5 changes: 5 additions & 0 deletions haxe_libraries/hxjava.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-D hxjava=3.2.0
# @install: lix --silent download "haxelib:/hxjava#3.2.0" into hxjava/3.2.0/haxelib
# @run: haxelib run-dir hxjava ${HAXE_LIBCACHE}/hxjava/3.2.0/haxelib
-cp ${HAXE_LIBCACHE}/hxjava/3.2.0/haxelib/
-java-lib lib/hxjava-std.jar
4 changes: 2 additions & 2 deletions test/TestUtf8.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestUtf8 extends haxe.unit.TestCase {
var u = Utf8.fromString("𩸽あëa");
// I expect having different indexes for different platforms is wrong.
var index =
#if (neko || js || python || hl)
#if (neko || js || python || hl || java)
[0, 4, 7, 9];
#else
[0, 1, 2, 3];
Expand All @@ -26,7 +26,7 @@ class TestUtf8 extends haxe.unit.TestCase {
var codepoints = ["𩸽".code, "".code, "ë".code, "a".code];
var u = Utf8.fromCodePoints(codepoints);
var index =
#if (neko || js || python || hl)
#if (neko || js || python || hl || java)
[0, 4, 7, 9];
#else
[0, 1, 2, 3];
Expand Down
12 changes: 10 additions & 2 deletions unifill/Utf16.hx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ abstract Utf16 (StringU16) {
}

public static inline function fromArray(a : Array<Int>) : Utf16 {
return new Utf16(StringU16.fromArray(a));
#if java
var na:java.NativeArray<java.types.Char16> = new java.NativeArray(a.length);
for (i in 0...a.length) na[i] = a[i];
var s = java.NativeString.valueOf(na);
var r = new Utf16(StringU16.fromString(s));
#else
var r = new Utf16(StringU16.fromArray(a));
#end
return r;
}

public static inline function encodeWith(f : Int -> Void, c : Int) : Void {
Expand Down Expand Up @@ -207,7 +215,7 @@ private class Utf16Impl {

}

#if (js || hl)
#if (js || hl || java)
@:forward private abstract StringU16Buffer(BytesBuffer) {
public inline function new() this = new BytesBuffer();

Expand Down
2 changes: 1 addition & 1 deletion unifill/UtfX.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package unifill;
typedef UtfX = Utf8;
#elseif (utf32 || python)
typedef UtfX = Utf32;
#elseif (utf16 || hl || js)
#elseif (utf16 || hl || js || java)
typedef UtfX = Utf16;
#else
typedef UtfX = Utf16;
Expand Down

0 comments on commit 78c1910

Please sign in to comment.