Page 1 of 1

Error with Unicode characters?

Posted: Sun Oct 27, 2019 12:42 pm
by danielrr
I feel sometimes Live code doesnt treat Unicode characteres as it should. Here's an example. Vocals with acute accent have different codepoints for Modern Greek (monotonic) and ancient Greek (polytonic). That means, the same pair of accented vowel and acute accent has two different encodings.
The correspondence is as follows

monotonic 940 = polytonic 8049
monotonic 941 = polytonic 8051
monotonic 942 = polytonic 8053
monotonic 943 = polytonic 8055
monotonic 972 = polytonic 8057
monotonic 973 = polytonic 8059
monotonic 974 = polytonic 8061

Now, if you want to convert the monotonic characters into the corresponding polytonic version, you may think this would do the job:

Code: Select all

 
   put "940,941,942,943,972,973,974" into vi
   put "8049,8051,8053,8055,8057,8059,8061" into nu
   put 0 into x
   repeat for each item elViejo in vi
      add 1 to x
      put item x of nu into elNuevo
      put the numtocodepoint of elViejo into monotonic
      put the numtocodepoint of elNuevo into polytonic
      repeat while monotonic is in container
         put polytonic into char offset(monotonic,container) of container
      end repeat
   end repeat
   
Alas, if you try this script with a text with monotonic-accented characters, you get into a infinite loop. Why is it? Am I missing something?

Re: Error with Unicode characters?

Posted: Sun Oct 27, 2019 1:38 pm
by richmond62
I don't understand much about this, but THIS did something:

Code: Select all

on mouseUp
   put empty into fld "fOUTPUT"
   put "940,941,942,943,972,973,974" into vi
   put "8049,8051,8053,8055,8057,8059,8061" into nu
   put 1 into xx
   repeat for each item zz in vi
      add 1 to xx
      put numToCodePoint(zz) && "|" into line xx of fld "fOUTPUT"
   end repeat
   put 1 into ww
   repeat for each item zz in nu
      add 1 to ww
      put " " & numToCodePoint(zz) after line ww of fld "fOUTPUT"
   end repeat
end mouseUp
-
Monotone.png
-
I hope that is some help.

Re: Error with Unicode characters?

Posted: Sun Oct 27, 2019 2:34 pm
by [-hh]
You could try

Code: Select all

put "940,941,942,943,972,973,974" into vi
put "8049,8051,8053,8055,8057,8059,8061" into nu
repeat with i=1 to 7
  replace numtocodepoint(item i of vi) with \
        numtocodepoint(item i of nu) in container
end repeat
[Using "offset" with unicode text bears problems.]

Re: Error with Unicode characters?

Posted: Sun Oct 27, 2019 8:27 pm
by danielrr
thanks, Richmond, -hh! :D