global function utf8_to_ascii(sequence s) -- created from Tommy's Unicode Library 1.2 -- copyright (c) 2003-2004 Tommy Carlier integer i, char, byte, bytes sequence res i = 1 res = "" while i < length(s) do byte = s[i] char = 0 if and_bits(byte,#80) = 0 then bytes = 1 elsif and_bits(byte,#20) = 0 then bytes = 2 elsif and_bits(byte,#10) = 0 then bytes = 3 elsif and_bits(byte,#8) = 0 then bytes = 4 elsif and_bits(byte,#4) = 0 then bytes = 5 elsif and_bits(byte,#2) = 0 then bytes = 6 else return "Incorrect UTF-8 char" end if byte = and_bits(byte, power(2, 8 - bytes) - 1) char += byte * power(64, bytes - 1) for n=1 to bytes-1 do i += 1 byte = s[i] if byte=0 then return "Unexpected end of UTF-8 string" elsif byte<0 then return "Incorrect UTF-8 char" end if byte = and_bits(byte,63) char += byte * power(64,bytes-1-n) end for res &= char i += 1 end while return res end function