Corona Code Exchange

Oh ok. Makes sense. 

I’m still working on this issue and experimenting with the CDATA tag, but as I dig deeper I’m not convinced it’s a parser issue - I think it’s more about how I’m handling the data after I’ve consumed the rss feed.

It appears to be more about how Corona handles special characters in strings. For example I have  myString = “dönüyor” - when I ask Corona how long the string is #myString = 9 - no doubt because of the two special characters. That’s fine and I can output the string just fine. The problem arises when I want to shorten the string for display purposes if I get a substring that ends in the “middle” of one of the special characters all I get back is an empty string…

e.g. myString:sub(1,8) when output to screen is “dönüyo” which is fine, but myString:sub(1,2) outputs to “” when I’m expecting “dö”, but that’s only achievable with myString:sub(1,3). Is there any way to test a character to see if it’s “special” so I can extend my string length in this special case?

Thanks,

Nathan.

@beernathan Check out this function Ingemar made, maybe it helps: http://forums.coronalabs.com/topic/42019-split-utf-8-string-word-with-foreign-characters-to-letters/

Awesome - thanks. Couldn’t get the whole thing to work for me, but used parts to be able to analyse my strings for special characters.

Not working for my Polish feed that I referenced earlier, but it is working for other languages - will get to the Polish soon!

+1

That’s a good idea.  I’lll suggest it, but it will  have more impact if there is a feature request for it at http://feedback.coronalabs.com with all your +1’s

Rob

Auto posted to the forum would be nice too.

yes the code exchange has needed some attention for a while. there’s a lot of good stuff in there. perhaps a better link location to it also making it easier to find for new users. and since the API has changed a lot recently maybe split it into pre gpx2.0 and gpx2.0 compatible

For Graphics 1 vs. Graphics 2, I would suggest using tags to identify them.

there are RSS feeds available for the code exchange, though i’m not sure exactly what types of info it will contain (e.g., new items, updates, etc).

main level is at: http://code.coronalabs.com/code
look for orange wifi-looking circled icon near top.

also, if i visit *any* URL for a tag or group, my RSS reader will show me choices to subscribe to that feed – note that the actual RSS URL is embedded in the HEAD of the HTML page, not available as an icon on the page itself.

+1 for separate feeds for New and Updated contributions.

Using the double byte code I’ve managed to detect special characters in Turkish & Japanese, but I’m still struggling with my Polish feed - I can’t get the contents of the feed to be displayed. I’m starting to wonder if this is a Corona issue.

Here’s an example of a title in the RSS feed: “Zespoły zaakceptowały propozycje zmian w formacie kwalifikacji?” (one of the examples from this feed http://www.f1wm.pl/rss_f1.php)

When the RSS code reads it in and I output it to the console (in Glider) I get “Zespo�y zaakceptowa�y propozycje zmian w formacie kwalifikacji” (note the weird diamond characters)

I tried wrapping the content in CDATA as per Rob’s suggestion

<![CDATA[Zespoły zaakceptowały propozycje zmian w formacie kwalifikacji?]]>

Console still shows exactly the same output : “Zespo�y zaakceptowa�y propozycje zmian w formacie kwalifikacji”

This makes me think that the CDATA tags aren’t making a difference - in both cases the XML parser is successfully delivering the content. The issue is that when I try to set the contents of a text object to this string I get nothing on screen.

The characters that are delivered by the parser aren’t “double byte” either. I tried pumping out the string through native.showAlert and I got the following error - the plot thickens:

Corona Simulator Generic error

NSInternalInconsistencyException: Invalid parameter not satisfying: aString != nil

(

    0   CoreFoundation                      0x00007fff96c64b06 __exceptionPreprocess + 198

    1   libobjc.A.dylib                     0x00007fff94c9b3f0 objc_exception_throw + 43

    2   CoreFoundation                      0x00007fff96c64948 +[NSException raise:format:arguments:] + 104

    3   Foundation                          0x00007fff951eb4c2 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189

    4   AppKit                              0x00007fff957ac125 -[NSCell _objectValue:forString:errorDescription:] + 159

    5   AppKit                              0x00007fff957ac07f -[NSCell _objectValue:forString:] + 20

    6   AppKit                              0x00007fff957abffb -[NSCell setStringValue:] + 39

    7   AppKit                              0x00007fff9584032c -[NSControl setStringValue:] + 138

    8   AppKit                              0x00007fff95a0ab71 -[NSAlert setInformativeText:] + 33

    9   Corona SimuNSInternalInconsistencyException

Any ideas about what is actually going on here?

Thanks,

Nathan.

OK, problem solved - it tuned out that it was an encoding problem. Rather than UTF-8 the feed was encoding=“iso-8859-2” so the characters weren’t double byte! The other thing to note is that Polish is “special” and has a set of 18 characters that you need to handle specially (the ones that were encoded) http://en.wikipedia.org/wiki/Polish_code_pages

The XML parser was passing them through just fine - I just had to write a function to parse the string looking for these special characters and converting them to a double-byte equivalent.

What happened to all the codes in code exchange? For instance I could found all the great modules from Glitch Games. I kind of miss the old code exchange! The only bad was it was not possible to find stuff. With the new exchange we can now search but most of the old are gone? Am I missing something? Thanks. Mo

Guys, just FYI, the Code Exchange has an RSS feed now:

http://code.coronalabs.com/code/feed

Also, the old code exchange is still there (but you cannot add new submissions to it):

http://developer.coronalabs.com/code

here you are Mo
https://developer.coronalabs.com/code

Thanks guys! I feel much better :) 

Mo

Hi guys,

I’ve got the RSS reader and it’s working well except for some when I hit some unusual characters. I assume it’s an encoding thing, but I really have no knowledge in that area. It’s reading the characters up from the RSS and putting them in a table, but when I try to output them to the device I just get nothing on screen. If I copy & paste those same characters into my code and output it’s fine, but I’m assuming the cut & paste is somehow resolving things that the xml.rss code isn’t handling.

This is the source of the feed http://www.f1wm.pl/rss_f1.php would appreciate any help…

Thanks,

Nathan.

Just a quick look, there are a bunch of UTF-8 characters which have to be encoded correctly for XML.  If you look in the xml.lua file you will see a big if statement where some characters are converted to their ASCII equivs.  This is at best a Hack way of handling it.  If you’re not in control of the feed and can’t get the fields wrapped in C-DATA tags, then you will have to make the XML processor handle the UTF-8 characters in a safe way.

Rob

OK thanks Rob.

I’m new to the whole character set issue, so I’m wondering how one would go about fixing this problem? A big lookup table? The fact that I can cut & paste the same characters into my code and display them has me baffled - is this doing some sort of auto-conversion?

Nathan.