Skip to content

Commit

Permalink
Merge branch 'vd/java-string-bug' into master-pu
Browse files Browse the repository at this point in the history
  • Loading branch information
proxyles committed Dec 27, 2011
2 parents 81d6c22 + e01d6f3 commit d3bd4d5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
Expand Up @@ -154,13 +154,16 @@ protected int doHashCode() {
* Unicode code points
*/

public static int[] stringToCodePoints(final String s) {
final int m = s.codePointCount(0, s.length());
final int [] codePoints = new int[m];
for (int i = 0, j = 0; j < m; i = s.offsetByCodePoints(i, 1), j++) {
codePoints[j] = s.codePointAt(i);
}
return codePoints;
public static int[] stringToCodePoints(final String s) {
final int m = s.codePointCount(0, s.length());
final int[] codePoints = new int[m];
int j = 0;
for (int offset = 0; offset < s.length();) {
final int codepoint = s.codePointAt(offset);
codePoints[j++] = codepoint;
offset += Character.charCount(codepoint);
}
return codePoints;
}

/**
Expand Down
7 changes: 5 additions & 2 deletions lib/jinterface/test/nc_SUITE.erl
Expand Up @@ -296,7 +296,8 @@ lists_roundtrip_2(Config) when is_list(Config) ->
{[z,23|24],tail3},
{[z|25],tail3},
{"abc123",sub3atom},
{"abc",sub3atom}
{"abc",sub3atom},
{"abcdefg",codepointBug}
],
Trans =
fun ([_|T], tail) ->
Expand All @@ -308,7 +309,9 @@ lists_roundtrip_2(Config) when is_list(Config) ->
(L, tail3) when is_list(L) ->
null;
([_,_,_|L], sub3atom) ->
list_to_atom(L)
list_to_atom(L);
(L, codepointBug) ->
L
end,
OutTrans =
fun ({L,Twist}) ->
Expand Down
6 changes: 6 additions & 0 deletions lib/jinterface/test/nc_SUITE_data/echo_server.java
Expand Up @@ -202,6 +202,12 @@ private static OtpErlangObject twist(final OtpErlangObject i,
final OtpErlangAtom o = new OtpErlangAtom(s.stringValue()
.substring(3));
return o;
} else if (atomValue.equals("codepointBug")
&& i instanceof OtpErlangString) {
final OtpErlangString s = (OtpErlangString) i;
final String ss = s.stringValue().substring(3, 6);
final int[] cps = OtpErlangString.stringToCodePoints(ss);
return s;
} else if (atomValue.equals("utf8")) {
if (i instanceof OtpErlangString) {
final OtpErlangString s = (OtpErlangString) i;
Expand Down

0 comments on commit d3bd4d5

Please sign in to comment.