Swedish character crashes Corona badly

Hi,

This snippet of code crashes Corona badly:

s = "stämma"  
s1 = string.sub(s,3,3)  
print(s1)  

Anyone? Is this corona or Lua related…

Joakim [import]uid: 81188 topic_id: 32851 reply_id: 332851[/import]

These are the errors I am getting:

2012-11-11 00:15:28.437 Corona Simulator[62675:f03] NSInvalidArgumentException: \*\*\* -[\_\_NSArrayM insertObject:atIndex:]: object cannot be nil ( 0 CoreFoundation 0x00007fff8ee0cf56 \_\_exceptionPreprocess + 198 1 libobjc.A.dylib 0x00007fff8ab9fd5e objc\_exception\_throw + 43 2 CoreFoundation 0x00007fff8edb3ab8 -[\_\_NSArrayM insertObject:atIndex:] + 296 3 Corona Simulator 0x000000010008bff8 Corona Simulator + 573432 4 Corona Simulator 0x0000000100094b3d Corona Simulator + 609085 5 Corona Simulator 0x00000001000a3cf2 Corona Simulator + 670962 6 Corona Simulator 0x0000000100094d16 Corona Simulator + 609558 7 Corona Simulator 0x00000001000a43bd Corona Simulator + 672701 8 Corona Simulator 0x0000000100094fce Corona Simulator + 610254 9 Corona Simulator 0x000000010008df5f Corona Simulator + 581471 10 Corona Simulator 0x0000000100057503 Corona Simulator + 357635 11 Corona Simulator 0x00000001000577a3 Corona Simulator + 358307 12 Corona Simulator 0x00000001000702cb Corona Simulator + 459467 13 Corona Simulator 0x000000010007282a Corona Simulator + 469034 14 Corona Simulator 0x00000001000724d7 Corona Simulator + 468183 15 Corona Simulator 0x00000001000291f3 Corona Simulator + 168435 16 Corona Simulator 0x000000010000703a Corona Simulator + 28730 17 Corona Simulator 0x000000010000ddd1 Corona Simulator + 56785 18 Corona Simulator 0x00000001000244fc Corona Simulator + 148732 19 CarbonCore 0x00007fff8e3087a3 implementation\_callback\_rpc + 1753 20 CarbonCore 0x00007fff8e30804b \_Xcallback\_rpc + 458 21 CarbonCore 0x00007fff8e307e7a FSEventsD2F\_server + 148 22 CarbonCore 0x00007fff8e307ddd FSEventsClientProcessMessageCallback + 29 23 CoreFoundation 0x00007fff8ed6bc52 \_\_CFMachPortPerform + 386 24 CoreFoundation 0x00007fff8ed6babc \_\_CFRUNLOOP\_IS\_CALLING\_OUT\_TO\_A\_SOURCE1\_PERFORM\_FUNCTION\_\_ + 44 25 CoreFoundation 0x00007fff8ed6b7eb \_\_CFRunLoopDoSource1 + 155 26 CoreFoundation 0x00007fff8eda1f27 \_\_CFRunLoopRun + 1895 27 CoreFoundation 0x00007fff8eda1486 CFRunLoopRunSpecific + 230 28 HIToolbox 0x00007fff89b362bf RunCurrentEventLoopInMode + 277 29 HIToolbox 0x00007fff89b3d56d ReceiveNextEventCommon + 355 30 HIToolbox 0x00007fff89b3d3fa BlockUntilNextEventMatchingListInMode + 62 31 AppKit 0x00007fff85a03779 \_DPSNextEvent + 659 32 AppKit 0x00007fff85a0307d -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 135 33 AppKit 0x00007fff859ff9b9 -[NSApplication run] + 470 34 AppKit 0x00007fff85c7beac NSApplicationMain + 867 35 Corona Simulator 0x0000000100001974 Corona Simulator + 6516 36 ??? 0x0000000000000001 0x0 + 1 [import]uid: 81188 topic_id: 32851 reply_id: 130570[/import]

These are the errors I am getting:

2012-11-11 00:15:28.437 Corona Simulator[62675:f03] NSInvalidArgumentException: \*\*\* -[\_\_NSArrayM insertObject:atIndex:]: object cannot be nil ( 0 CoreFoundation 0x00007fff8ee0cf56 \_\_exceptionPreprocess + 198 1 libobjc.A.dylib 0x00007fff8ab9fd5e objc\_exception\_throw + 43 2 CoreFoundation 0x00007fff8edb3ab8 -[\_\_NSArrayM insertObject:atIndex:] + 296 3 Corona Simulator 0x000000010008bff8 Corona Simulator + 573432 4 Corona Simulator 0x0000000100094b3d Corona Simulator + 609085 5 Corona Simulator 0x00000001000a3cf2 Corona Simulator + 670962 6 Corona Simulator 0x0000000100094d16 Corona Simulator + 609558 7 Corona Simulator 0x00000001000a43bd Corona Simulator + 672701 8 Corona Simulator 0x0000000100094fce Corona Simulator + 610254 9 Corona Simulator 0x000000010008df5f Corona Simulator + 581471 10 Corona Simulator 0x0000000100057503 Corona Simulator + 357635 11 Corona Simulator 0x00000001000577a3 Corona Simulator + 358307 12 Corona Simulator 0x00000001000702cb Corona Simulator + 459467 13 Corona Simulator 0x000000010007282a Corona Simulator + 469034 14 Corona Simulator 0x00000001000724d7 Corona Simulator + 468183 15 Corona Simulator 0x00000001000291f3 Corona Simulator + 168435 16 Corona Simulator 0x000000010000703a Corona Simulator + 28730 17 Corona Simulator 0x000000010000ddd1 Corona Simulator + 56785 18 Corona Simulator 0x00000001000244fc Corona Simulator + 148732 19 CarbonCore 0x00007fff8e3087a3 implementation\_callback\_rpc + 1753 20 CarbonCore 0x00007fff8e30804b \_Xcallback\_rpc + 458 21 CarbonCore 0x00007fff8e307e7a FSEventsD2F\_server + 148 22 CarbonCore 0x00007fff8e307ddd FSEventsClientProcessMessageCallback + 29 23 CoreFoundation 0x00007fff8ed6bc52 \_\_CFMachPortPerform + 386 24 CoreFoundation 0x00007fff8ed6babc \_\_CFRUNLOOP\_IS\_CALLING\_OUT\_TO\_A\_SOURCE1\_PERFORM\_FUNCTION\_\_ + 44 25 CoreFoundation 0x00007fff8ed6b7eb \_\_CFRunLoopDoSource1 + 155 26 CoreFoundation 0x00007fff8eda1f27 \_\_CFRunLoopRun + 1895 27 CoreFoundation 0x00007fff8eda1486 CFRunLoopRunSpecific + 230 28 HIToolbox 0x00007fff89b362bf RunCurrentEventLoopInMode + 277 29 HIToolbox 0x00007fff89b3d56d ReceiveNextEventCommon + 355 30 HIToolbox 0x00007fff89b3d3fa BlockUntilNextEventMatchingListInMode + 62 31 AppKit 0x00007fff85a03779 \_DPSNextEvent + 659 32 AppKit 0x00007fff85a0307d -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 135 33 AppKit 0x00007fff859ff9b9 -[NSApplication run] + 470 34 AppKit 0x00007fff85c7beac NSApplicationMain + 867 35 Corona Simulator 0x0000000100001974 Corona Simulator + 6516 36 ??? 0x0000000000000001 0x0 + 1 [import]uid: 81188 topic_id: 32851 reply_id: 130570[/import]

that’s not crashing for me, just printing something weird [import]uid: 53195 topic_id: 32851 reply_id: 130574[/import]

that’s not crashing for me, just printing something weird [import]uid: 53195 topic_id: 32851 reply_id: 130574[/import]

i can’t explain why it crashes, i would expect ?? to be printed out
string.sub, string.len, string.reverse, string.find work only with the 26 characters of the latin alphabet.
you might find this useful
http://developer.coronalabs.com/forum/2010/08/08/string-greek-characters
[import]uid: 6459 topic_id: 32851 reply_id: 132007[/import]

i can’t explain why it crashes, i would expect ?? to be printed out
string.sub, string.len, string.reverse, string.find work only with the 26 characters of the latin alphabet.
you might find this useful
http://developer.coronalabs.com/forum/2010/08/08/string-greek-characters
[import]uid: 6459 topic_id: 32851 reply_id: 132008[/import]

This is probably because Lua’s string functions are not designed to handle characters outside of the normal ASCII character set. Seems kind of crazy to me that this is the case.

I ran into this exact problem myself a while ago. Fortunately after a bunch of searching I was able to find a Lua library that’s Corona compatible and solves this issue.

https://gist.github.com/4128882

Just load this library and use the string functions it provides instead of the ones you’re using now. In this case it would be utf8sub(). [import]uid: 135827 topic_id: 32851 reply_id: 132010[/import]

thank you!

i knew the workaround would fail for characters with 3 bytes or more
[import]uid: 6459 topic_id: 32851 reply_id: 132058[/import]

i can’t explain why it crashes, i would expect ?? to be printed out
string.sub, string.len, string.reverse, string.find work only with the 26 characters of the latin alphabet.
you might find this useful
http://developer.coronalabs.com/forum/2010/08/08/string-greek-characters
[import]uid: 6459 topic_id: 32851 reply_id: 132007[/import]

i can’t explain why it crashes, i would expect ?? to be printed out
string.sub, string.len, string.reverse, string.find work only with the 26 characters of the latin alphabet.
you might find this useful
http://developer.coronalabs.com/forum/2010/08/08/string-greek-characters
[import]uid: 6459 topic_id: 32851 reply_id: 132008[/import]

This is probably because Lua’s string functions are not designed to handle characters outside of the normal ASCII character set. Seems kind of crazy to me that this is the case.

I ran into this exact problem myself a while ago. Fortunately after a bunch of searching I was able to find a Lua library that’s Corona compatible and solves this issue.

https://gist.github.com/4128882

Just load this library and use the string functions it provides instead of the ones you’re using now. In this case it would be utf8sub(). [import]uid: 135827 topic_id: 32851 reply_id: 132010[/import]

thank you!

i knew the workaround would fail for characters with 3 bytes or more
[import]uid: 6459 topic_id: 32851 reply_id: 132058[/import]

Hello Guys,

I’ve tried using the utf function, but I cannot get it working

I’m using something like:

local file = io.open(system.pathForFile("dicts/"..settings.game.gameLang..".csv"), "r");  
for line in file:lines() do  
 utf8sub(line, 1, 1);  
end  

and it’s seems weird, but I’m getting the hole text for parameters 1, 1. Do you know how could I solve this issue?

For example, for line “ARAÑA”, I’m getting “ARAÑA” in position 1,1

Thanks for your help

Best regards
[import]uid: 112380 topic_id: 32851 reply_id: 138903[/import]

juan

i run the same code with a text file instead of a csv and it works fine

if you open the csv file can you read the characters?

[import]uid: 6459 topic_id: 32851 reply_id: 139136[/import]

@Tetu thanks for trying, I did test that with a new file, created from start and it worked, I guess there was something funny in my file, but the notepad++ opened it right, I dont know.

Thanks, now it’s working great! [import]uid: 112380 topic_id: 32851 reply_id: 139326[/import]

Hello Guys,

I’ve tried using the utf function, but I cannot get it working

I’m using something like:

local file = io.open(system.pathForFile("dicts/"..settings.game.gameLang..".csv"), "r");  
for line in file:lines() do  
 utf8sub(line, 1, 1);  
end  

and it’s seems weird, but I’m getting the hole text for parameters 1, 1. Do you know how could I solve this issue?

For example, for line “ARAÑA”, I’m getting “ARAÑA” in position 1,1

Thanks for your help

Best regards
[import]uid: 112380 topic_id: 32851 reply_id: 138903[/import]

juan

i run the same code with a text file instead of a csv and it works fine

if you open the csv file can you read the characters?

[import]uid: 6459 topic_id: 32851 reply_id: 139136[/import]

@Tetu thanks for trying, I did test that with a new file, created from start and it worked, I guess there was something funny in my file, but the notepad++ opened it right, I dont know.

Thanks, now it’s working great! [import]uid: 112380 topic_id: 32851 reply_id: 139326[/import]