Error 403 from Google Calendar? Upgrade to the new Google Calendar support. See here for details. close
Welcome, Guest
Please Login or Register.    Lost Password?

[Solved] About Rainlendar_SetItemValue()
(1 viewing) (1) Guest
Go to bottomPage: 12
TOPIC: [Solved] About Rainlendar_SetItemValue()
#14382
[Solved] About Rainlendar_SetItemValue() 3 Years, 10 Months ago  
There is a small problem, I have a .lua file use the following code:
Code:


sTime = os.date("%x %a")
Rainlendar_SetItemValue("LunarCal", "LunarCal.info", "text", "今日情報:" .. sTime .. "\n" .. todaymsg1)


If the file is set to ANSI, it works fine(a),
If the file is set to UTF-8, it will not show(b), but Rainlendar_Message (sTime, 0) is normal display(c)


I found all the time-format that display with local language can not be showed.

How can I display properly using the UTF-8 encoded file??

Thank!!
anoob
Platinum Boarder
Posts: 510
graphgraph
User Offline Click here to see the profile of this user
Gender: Male Location: TaiChung, Taiwan, R.O.C. Birthday: 02/12
Last Edit: 2013/03/06 12:45 By anoob.
The administrator has disabled public write access.
I couldn't speak English! This skin released to Customize.org(Do you want it? Click Picture) Please contact me if interested: jhg5702@gmail.com
 
#14383
Re:About Rainlendar_SetItemValue() 3 Years, 10 Months ago  
When i was mading a Maya calendar from a Maya font, i need to use Unicode values above 63000. Finding on the web i finally found this:

"The proper way to convert between UCS-4 and UTF-8 is to use bitmask (and, or) and bitshift operations. But if you would like to convert only a couple of characters by hand or if your program development environment (scripting language) does not support bit operations, then integer division and multiplication can be used as follows."

Because i didn't want to lose time searching for how to do the bitshift operations i use the mathematical way:

This will be valid if the dec value is between 2048 and 65535 (UTF-8 is 3 bytes long)
Code:

function UCS4_UTF8(dec)
    a = 224 + (math.floor(dec / 4096))
    b = 128 + (math.floor(dec / 64) % 64)
    c = 128 + (dec % 64)
    return string.char(a, b, c)
end



EDIT: This would be the full converter code from UTF-32 to UTF-8:
Code:

function UTF32_UTF8(dec)
    if (dec < 128) then
        a = dec
        return string.char(a)
    elseif (dec >= 128 and dec <= 2047) then
        a = 192 + (math.floor(dec / 64))
        b = 128 + (dec % 64)
        return string.char(a, b)
    elseif (dec >=2048 and dec <= 65535) then
        a = 224 + (math.floor(dec / 4096))
        b = 128 + (math.floor(dec / 64) % 64)
        c = 128 + (dec % 64)
        return string.char(a, b, c)
    elseif (dec >= 65536 and dec <= 2097151) then
        a = 240 + (math.floor(dec / 262144))
        b = 128 + (math.floor(dec / 4096) % 64)
        c = 128 + (math.floor(dec / 64) % 64)
        d = 128 + (dec % 64)
        return string.char(a, b, c, d)
    elseif (dec >= 2097152 and dec <= 67108863) then
        a = 248 + (math.floor(dec / 16777216))
        b = 128 + (math.floor(dec / 262144) % 64)
        c = 128 + (math.floor(dec / 4096) % 64)
        d = 128 + (math.floor(dec / 64) % 64)
        e = 128 + (dec % 64)
        return string.char(a, b, c, d, e)
    elseif (dec >= 67108864 and dec <= 2147483647) then
        a = 252 + (math.floor(dec / 1073741824))
        b = 128 + (math.floor(dec / 16777216) % 64)
        c = 128 + (math.floor(dec / 262144) % 64)
        d = 128 + (math.floor(dec / 4096) % 64)
        e = 128 + (math.floor(dec / 64) % 64)
        f = 128 + (dec % 64)
        return string.char(a, b, c, d, e, f)
    end
end

Jorge_Luis
Platinum Boarder
Posts: 795
graphgraph
User Offline Click here to see the profile of this user
Gender: Male My Rainlendar Skins Location: Argentina Birthday: 03/15
Last Edit: 2011/02/04 06:59 By Jorge_Luis.Reason: Full converter code
The administrator has disabled public write access.
 
#14387
Re: About Rainlendar_SetItemValue() 3 Years, 10 Months ago  
I at least can use the Rainlendar_SetItemValue() to display some Chinese characters in a text element. Can you attach a full example of this?
Rainy
Moderator
Posts: 6092
graph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#14408
Re:About Rainlendar_SetItemValue() 3 Years, 10 Months ago  
To Jorge_Luis:
Sorry, i can not understand what you say.

To all guys:
i think the real question is about the code os.date("%x %a")
in English OS it display "4/2/2011 Fri"(maybe),
in my pc(Chinese OS) it display "2011/2/4 &#26143;&#26399;&#20116;"
if i only write sTime = os.date("%x"), it work fine
but if i write sTime = "&#20170;&#26085;&#24773;&#22577;&#65306;" .. os.date("%x %a"), it can not show.
this issue happen on Rainlendar_Message() too.

i posted the skin that include this issue on customize.org/rainlendar/skins/79993
you can download it to try.
thank!!
anoob
Platinum Boarder
Posts: 510
graphgraph
User Offline Click here to see the profile of this user
Gender: Male Location: TaiChung, Taiwan, R.O.C. Birthday: 02/12
Last Edit: 2011/02/04 13:29 By anoob.
The administrator has disabled public write access.
I couldn't speak English! This skin released to Customize.org(Do you want it? Click Picture) Please contact me if interested: jhg5702@gmail.com
 
#14410
Re:About Rainlendar_SetItemValue() 3 Years, 10 Months ago  
EDIT/UPDATE: I'm not sure of the next text. Is writed before this. I got totally confused because in the forum i can't see the Unicode fonts, only the Unicode values. My native language is Spanish, with ISO-8859-1 i've got all i need. So i don't know if the problem are the Unicode values or... well... i'm speechless.

sTime = "&#20170;&#26085;&#24773;&#22577;&#65306;" .. os.date("%x %a")
Did you try to remove "&#65306;" from the string? I see some CJK glyphs without this last character, but strange letters with it.


-----------

Oh my god!, i been watching this a few days ago and i completely forget it.

This code is from RSS.lua file on Shadow4. Is the same as the laaaaaarge function i wrote before. I was thinking of the Lua function to search and replace using regular expression, but then i thought... why reinvent the wheel:

Code:


function DecodeString(s)
  s = string.gsub(s, "&#(%d+);",
    function (d)
      val = tonumber(d, 10)
      if (val < 128) then
        return string.char(val)
      elseif (val < 2048) then
        return string.char(192 + val / 64) .. string.char(128 + (val % 64))
      elseif (val < 65536) then
        return string.char(224 + val / 4096) .. string.char(128 + ((val / 64) % 64)) .. string.char(128 + (val % 64))
      end
    end)
end



This code take a numerical value &26143; for example and convert it to UTF-8.
I think all you need to do is:

Code:

sTime = DecodeString(os.date("%x %a"))
Jorge_Luis
Platinum Boarder
Posts: 795
graphgraph
User Offline Click here to see the profile of this user
Gender: Male My Rainlendar Skins Location: Argentina Birthday: 03/15
Last Edit: 2011/02/04 15:59 By Jorge_Luis.
The administrator has disabled public write access.
 
#14417
Re:About Rainlendar_SetItemValue() 3 Years, 10 Months ago  
Did you try to remove "&#65306;" from the string?yes, i did. it does not affect.
Code:
sTime = DecodeString(os.date("%x %a"))

function DecodeString(s)
s = string.gsub(s, "&#(%d+);", .........
i can not to get the "&#NNN;" of os.date("%x %a").

Anyway thank you Jorge_Luis.
Probably because I can not understand how it works, so I did not solve the problem.
I decided to not directly display <"&#20170;&#26085;&#24773;&#22577;&#65306;" .. os.date("%x %a")>,
but are independent display <"&#20170;&#26085;&#24773;&#22577;&#65306;"> and <os.date("%x %a")>

I hope someone can help solve.
anoob
Platinum Boarder
Posts: 510
graphgraph
User Offline Click here to see the profile of this user
Gender: Male Location: TaiChung, Taiwan, R.O.C. Birthday: 02/12
The administrator has disabled public write access.
I couldn't speak English! This skin released to Customize.org(Do you want it? Click Picture) Please contact me if interested: jhg5702@gmail.com
 
Go to topPage: 12
get the latest posts directly to your desktop