wei-spring / codenameone

Automatically exported from code.google.com/p/codenameone
0 stars 0 forks source link

String constructors not working correctly with ios.newVM #1299

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am using a couple of String constructors that are not working in the new iOS 
VM:

String(byte[] bytes, int off, int len, String enc)
Construct a new String by converting the specified subarray of bytes using the 
specified character encoding.

String(byte[] bytes, int off, int len)
Construct a new String by converting the specified subarray of bytes using the 
platform's default character encoding.

Sample code attached. If you run it on the old VM you will get the expected 
results.

If you run it on the new VM the offset is being ignored:

    String str = "This1234 is a test string";
    byte[] bytes = str.getBytes();

    String str2 = new String(bytes, 4, 4);

With the old VM str2 contains 1234 as expected. 

With the new VM str2 contains This

There are other String constructors that take an offset, I have not checked 
them. The above constructor with character encoding I use quite a bit.

Original issue reported on code.google.com by mwarn...@readerware.com on 22 Jan 2015 at 4:40

Attachments:

GoogleCodeExporter commented 9 years ago
this should be fixed now. It was a problem with the string encoding function in 
the native code that ignored the offset value. 

Original comment by shai.almog on 25 Jan 2015 at 1:05

GoogleCodeExporter commented 9 years ago
No, still not working. It is different, but still not correct.

Did you use the test case I included to test your fix?

    String str = "This1234 is a test string";
    byte[] bytes = str.getBytes();

    String str2 = new String(bytes, 4, 4);

With your latest code str2 now contains "st s". It looks like it is picking up 
the string at offset 16, it should be 4.

The expected result is "1234".

Original comment by mwarn...@readerware.com on 26 Jan 2015 at 7:39

GoogleCodeExporter commented 9 years ago
OK, now it should be fixed. 

Original comment by shai.almog on 27 Jan 2015 at 1:16

GoogleCodeExporter commented 9 years ago
Yes, it is working now.

Thanks

Original comment by mwarn...@readerware.com on 27 Jan 2015 at 2:52