(phixonline)-->
with javascript_semantics
function unicode_reverse(string utf8)
sequence utf32 = utf8_to_utf32(utf8)
-- The assumption is made that <char><comb1><comb2>
-- and <char><comb2><comb1> etc would work the same.
-- The following loop converts <char><comb1><comb2>
-- to <comb1><comb2><char>, as a pre-reverse() step.
for i=1 to length(utf32) do
integer ch = utf32[i]
if (ch>=0x300 and ch<=0x36f)
or (ch>=0x1dc0 and ch<=0x1dff)
or (ch>=0x20d0 and ch<=0x20ff)
or (ch>=0xfe20 and ch<=0xfe2f) then
utf32[i] = utf32[i-1]
utf32[i-1] = ch
end if
end for
utf32 = reverse(utf32)
utf8 = utf32_to_utf8(utf32)
return utf8
end function
string r4 = "as\u203Ddf\u0305",
rt = r4&" reversed is "&unicode_reverse(r4)&"\n"
puts(1,rt)