Ok so looking at LuaString.java, we find these methods.
public static LuaString valueOf(String string) {
LuaString s = index_get( index_java, string );
if ( s != null ) return s;
char[] c = string.toCharArray();
byte[] b = new byte[lengthAsUtf8(c)];
encodeToUtf8(c, b, 0);
s = valueOf(b, 0, b.length);
index_set( index_java, string, s );
return s;
}
public String tojstring() {
return decodeAsUtf8(m_bytes, m_offset, m_length);
}
public static String decodeAsUtf8(byte[] bytes, int offset, int length) {
int i,j,n,b;
for ( i=offset,j=offset+length,n=0; i<j; ++n ) {
switch ( 0xE0 & bytes[i++] ) {
case 0xE0: ++i;
case 0xC0: ++i;
}
}
char[] chars=new char[n];
for ( i=offset,j=offset+length,n=0; i< j; ) {
chars[n++] = (char) (
((b=bytes[i++])>=0||i>=j)? b:
(b<-32||i+1>=j)? (((b&0x3f) << 6) | (bytes[i++]&0x3f)):
(((b&0xf) << 12) | ((bytes[i++]&0x3f)<<6) | (bytes[i++]&0x3f)));
}
return new String(chars);
}
public static void encodeToUtf8(char[] chars, byte[] bytes, int off) {
final int n = chars.length;
char c;
for ( int i=0, j=off; i< n; i++ ) {
if ( (c = chars[i]) < 0x80 ) {
bytes[j++] = (byte) c;
} else if ( c < 0x800 ) {
bytes[j++] = (byte) (0xC0 | ((c>>6) & 0x1f));
bytes[j++] = (byte) (0x80 | ( c & 0x3f));
} else {
bytes[j++] = (byte) (0xE0 | ((c>>12) & 0x0f));
bytes[j++] = (byte) (0x80 | ((c>>6) & 0x3f));
bytes[j++] = (byte) (0x80 | ( c & 0x3f));
}
}
}
It would appear I'm correct. But there's also this method
public static LuaString valueOf(byte[] bytes) {
return valueOf(bytes, 0, bytes.length);
}
So CC can encode and decode to and from byte arrays just fine. Might make for some tedious code but it'd fix the bug.
EDIT: Also, Jarle212 you can probably use the knowledge of how these methods work to your advantage in figure out how to fix it Lua side.
Edited by ElvishJerricco, 20 February 2015 - 01:38 AM.