Page 1 of 1

uniDecode/uniEncode UTF8 conversion? [Android]

Posted: Tue Mar 05, 2013 6:08 am
by n9yty
Since I am just learning LiveCode, I am posting this here instead of the Android subforum. If this should be over there let me know.

I'm puzzled by an anomaly with extracting web text using the revXML routines, converting from UTF-8 and displaying it on screen. On the desktop (Mac OS X) the following works fine, and was taken from a hint in these forums:

put uniDecode( uniEncode( myXMLExtractedText, "UTF8" ) ) into myTitle

Yet even though both functions above are shown as supported on Android it does not work to convert the special characters. I also tried supplying the language "English" to the uniDecode function and it didn't change anything.

Can anyone help point out what I am doing wrong?

Re: uniDecode/uniEncode UTF8 conversion? [Android]

Posted: Tue Mar 05, 2013 6:58 am
by snm
Try just:

Code: Select all

put uniEncode(myXMLExtractedText, "UTF8") into fld "myField"
if myXMLExtractedText is variable containing the result of any revXML function.

Marek

Re: uniDecode/uniEncode UTF8 conversion? [Android]

Posted: Tue Mar 05, 2013 7:01 am
by n9yty
snm wrote:Try just:

Code: Select all

put uniEncode(myXMLExtractedText, "UTF8") into fld "myField"
if myXMLExtractedText is variable containing the result of any revXML function.
I initially tried just that but it wouldn't work until I added the uniDecode. And, because of other stuff I am doing I am setting the htmlText of the field if that makes a difference. But I will try this and get back with the results.

Re: uniDecode/uniEncode UTF8 conversion? [Android]

Posted: Tue Mar 05, 2013 11:30 am
by snm
I'm sorry, it was too early morning and I gave you wrong code. Please try:

Code: Select all

set the unicodeText of fld "myField" to uniEncode(myXMLExtractedText, "UTF8")
And check if XML is utf-8 coded.
Marek

Re: uniDecode/uniEncode UTF8 conversion? [Android]

Posted: Tue Mar 05, 2013 4:16 pm
by n9yty
snm wrote:I'm sorry, it was too early morning and I gave you wrong code. Please try:

Code: Select all

set the unicodeText of fld "myField" to uniEncode(myXMLExtractedText, "UTF8")
And check if XML is utf-8 coded.
Marek
Yes, the XML data is UTF-8 encoded. And it does work on the desktop version. I did try the above code but it does not fix the data and would be unworkable anyway because I need to set the htmlText of the field.

It is puzzling to me why it works on the desktop, and on iOS Emulator but not on Android, which would seem to indicate it is a bug on the Android platform. :) But I am still open to ideas.

Re: uniDecode/uniEncode UTF8 conversion? [Android]

Posted: Wed Mar 06, 2013 4:12 am
by Simon
I've just been testing this on Win7/Android emulator with Marek's code and it seems to work.
...because I need to set the htmlText of the field.
Just have the first field hidden and set the htmltext of displayField to hiddenField.

Could you post your XML?

Simon

Re: uniDecode/uniEncode UTF8 conversion? [Android]

Posted: Wed Mar 06, 2013 5:07 am
by n9yty
Simon wrote:I've just been testing this on Win7/Android emulator with Marek's code and it seems to work.
...because I need to set the htmlText of the field.
Just have the first field hidden and set the htmltext of displayField to hiddenField.
Could you post your XML?
I'm sorry for being maybe somewhat thick-headed here, but to me the issue is that it works when I try on my Mac, and on the iOS emulator, but not on the Android. I did not test on Windows or Linux, but two out of the three platforms I test work, so I don't know that I'm doing anything terribly wrong, but something seems to be misbehaving in the Android stack somewhere.

At any rate, the XML I am pulling is just a web page encoded in UTF-8... At least for this test for the non-profit I am working with the site is (I can't post a link yet I don't think) at sga.org. The content type for the page is utf-8 and one example of the character string is "The “Transformation” Story"

Thanks, it just seems like we are veering off target. :) But if I knew enough about LiveCode to say that definitively, I wouldn't be asking would I? LoL

Re: uniDecode/uniEncode UTF8 conversion? [Android]

Posted: Wed Mar 06, 2013 5:19 am
by Simon
&#8221
Is a straight up html code, you shouldn't need utf8. Setting the htmtext should work just on that code.

Simon

Re: uniDecode/uniEncode UTF8 conversion? [Android]

Posted: Wed Mar 06, 2013 5:33 am
by n9yty
My mistake, I took that from Safari, I am not sure how to best extract it raw. Let me set a debug point and try to catch it from inside LiveCode... It comes out as "The “Transformation” Story" if that is of any use. Running that through a binaryDecode("h*".... call gives "458656022e08c9452716e63766f627d6164796f6e62e08d9023547f62797" if that is more useful. You can see that text on the sga.org main page at present, I think it is the second or third story on the list.

Re: uniDecode/uniEncode UTF8 conversion? [Android]

Posted: Wed Mar 06, 2013 3:35 pm
by n9yty
Maybe I am looking at the tree when the leaves are the problem.... Could it be that the default font being used on Android simply does not support the characters being requested? I took it for granted that it would be a full unicode font, but perhaps not.

The result of the uniDecode/uniEncode pair produces similar results, although not exactly the same, on the Desktop and Android. I owe that to the fact that it is converting ultimately into the native character set of the final device so the translation may be different for a UTF-8 char in the native character space of Mac (OSX/iOS) than it is for Android.

Mac OS X: 458656022d452716e63766f627d6164796f6e63d023547f62797
Android: 45865602f3452716e63766f627d6164796f6e6f3023547f62797

I guess it is time to look at Android fonts.. :) Sorry for the stolen time to look at an essentially nonexistent problem. :oops:

Just to look at your other suggestion of a separate field for the unicode value, I tried something like this:

[I did not use uniDecode/uniEncode on any of the data, so it was left intact as it came from the page source at this point]
set the unicodeText of field "unicodedText" of card "scratchFields" to uniEncode(tHTML, "UTF8")
set htmlText of field "StoryList" to the text of field "unicodedText" of card "scratchFields"

And while this works on the Mac it produces the same result as my previous attempt on the Android. Yet when I view the web page in a browser on an Android it dos the right thing with regard to those UTF8 characters.

However, if I do the following:

set the unicodeText of field "StoryList" to uniEncode(tHTML, "UTF8")

I get the HTML code but the characters display properly! So how do I get this into the htmlText portion of my display field? If I try this:

set htmlText of field "StoryList" to the unicodeText of field "unicodedText" of card "scratchFields"

I get some garbage characters in the text and loose my HTML coding.

If I try this I get the HTML but it is not interpreted in the view:

set htmlText of field "StoryList" to the htmlText of field "unicodedText" of card "scratchFields"

Scratching my head . . . :)

Re: uniDecode/uniEncode UTF8 conversion? [Android]

Posted: Thu Mar 07, 2013 11:56 pm
by n9yty
Even more strange... The use of the field was primarily for testing, I knew that eventually I would want to move to data grids. I am working through that now, and wouldn't you know that in the data grid the characters display properly? The difference is that in this case I only have to set the unicodeText of the field that is in the data grid record format...

Parsing is simple like this:

Code: Select all

put revXMLNodeContents(tTree,  tNode) into tContent
put word 1 to -1 of tContent into postExcerpt
put postExcerpt into myGridData[storyCount]["colExcerpt"]
And the behavior script for the datagrid takes it and puts it in like this:

Code: Select all

set the unicodeText of field "Excerpt" of me to uniEncode(pDataArray["colExcerpt"], "UTF8")
So, this fixes the display in the data grid, but when they select a line to view the full content, for which I am needing the (albeit limited) HTML abilities by using htmlText to handle including images, the characters are back to mostly ? instead of what they should be. Very frustrating that it only shows this problem on Android.

Re: uniDecode/uniEncode UTF8 conversion? [Android]

Posted: Tue Mar 25, 2014 11:52 am
by atout66
Hi n9yty,

I get mostly the same problem as you, but on desktop.
I made a post on that link : http://forums.runrev.com/viewtopic.php?f=7&t=19732
I tried many different ways to read unicode chars in a field (from a source HTML code), compare two fields with each a unicode char, etc. but without success 'til now.

I follow this topic so if by chance you find a solution, I'll give it a look, who knows ? :wink: