-- Euphoria 3.2.00,ru bilingual (English & Russian) library, cp866, -- for the bilingual interpreters with unlimited alphabet -- ex_r.exe, exw_r.exe, exu_r and eu_r.ex. -- Analog of the pure English version (rus_add.e) by Igor Kachan, -- this version doesn't work with the standard RDS interpreters. -- 28.02.2006 - fixed bug, thanks to Wolfgang Fritz -- 06.03.2011 - utf-8 encoding added -- ------! ࣠ ⥪ ४஢!!!!--------- ------------Attention! Do not recode this library!!!!------------------- global sequence codes -------------------------------------------------- --᫨ । ⮪, ᮡ ⥫-------------- --edit with very care--------------------------------------------------- sequence d,w,k,i,m,r,u,U------------------------------------------------ d="񦧨"--866 w="Ũ"--1251 k="ţ"--koi8-r i=""--8859-5 m="݆"--apple r="ABVGDEegZIJKLMNOPRSTUFHCXsz_Y_eWQabvgdeEGzijklmnoprstufhcxSZ_y_Ewq"--rlr u=""--utf-8b U=""--utf-8a codes={d,w,k,i,m,r,u,U}------------------------------------------------- --edit with very care--------------------------------------------------- --᫨ । ⮪, ᮡ ⥫-------------- ------! ࣠ ⥪ ४஢!!!!--------- ------------Attention! Do not recode this library!!!!------------------- -- global function case_ru(integer c, object x, sequence cp) -- convert Russian atom or sequence -- to upper or to lower case integer n sequence A, a if equal(cp,"dos") then n=1 elsif equal(cp,"win") then n=2 elsif equal(cp,"koi") then n=3 elsif equal(cp,"iso") then n=4 elsif equal(cp,"mac") then n=5 else n=0 end if if not n then return n end if if c then A=codes[n][ 1..33] a=codes[n][34..66] else a=codes[n][ 1..33] A=codes[n][34..66] end if if atom(x) then n=find(x,a) if n then return A[n] end if else for i=1 to length(x) do n=find(x[i],a) if n then x[i] = A[n] end if end for end if return x end function -- case_ru() global function ᪨_ॣ(integer c, object x, sequence cp) -- ८ࠧ ᪨ atom sequence -- 孥 ॣ integer n sequence A, a if equal(cp,"dos") then n=1 elsif equal(cp,"win") then n=2 elsif equal(cp,"koi") then n=3 elsif equal(cp,"iso") then n=4 elsif equal(cp,"mac") then n=5 else n=0 end if if not n then return n end if if c then A=codes[n][ 1..33] a=codes[n][34..66] else a=codes[n][ 1..33] A=codes[n][34..66] end if if atom(x) then n=find(x,a) if n then return A[n] end if else for i=1 to length(x) do n=find(x[i],a) if n then x[i] = A[n] end if end for end if return x end function -- ᪨_ॣ() global function case_la(integer c, object x) -- convert Latin atom or sequence to upper or to lower case integer d d='a' - 'A' if c then return x - (x >= 'a' and x <= 'z') * d else return x + (x >= 'A' and x <= 'Z') * d end if end function -- case_la() global function ⨭᪨_ॣ(integer c, object x) -- ८ࠧ ⨭᪨ atom sequence 孥 ॣ integer d d='a' - 'A' if c then return x - (x >= 'a' and x <= 'z') * d else return x + (x >= 'A' and x <= 'Z') * d end if end function -- ⨭᪨_ॣ() global function recode(object f, sequence m) -- recode Russian text from one encoding to another one integer c,r,i,o sequence F i=m[1] if i='d' then i=1 elsif i='w' then i=2 elsif i='k' then i=3 elsif i='i' then i=4 elsif i='m' then i=5 -- elsif i='u' then i=6 else i=0 end if o=m[2] if o='d' then o=1 elsif o='w' then o=2 elsif o='k' then o=3 elsif o='i' then o=4 elsif o='m' then o=5 elsif o='l' then o=6 -- ਡ⥫쭮 ⨭ elsif o='u' then o=7 -- utf-8 else o=0 end if if not i or not o then puts(1,"\n invalid recodeing mode") abort(1) end if if atom(f) then c=find(f,codes[i]) if c then return codes[o][c] else return f end if else if o != 7 then -- ⮢ ஢ for j=1 to length(f) do c=f[j] r=c if c>=128 then c=find(c,codes[i]) if c then f[j]=codes[o][c] else f[j]=r end if end if end for else -- utf-8 F={} for j=1 to length(f) do c=f[j] r=c if c>=128 then c=find(c,codes[i]) if c then F&=codes[8][c] F&=codes[7][c] end if else F&=r end if --end if end for f=F end if return f end if end function -- recode() -- global function ४஢(object f, sequence m) -- recode Russian text from one encoding to another one integer c,r,i,o sequence F i=m[1] if i='d' then i=1 elsif i='w' then i=2 elsif i='k' then i=3 elsif i='i' then i=4 elsif i='m' then i=5 -- elsif i='u' then i=6 else i=0 end if o=m[2] if o='d' then o=1 elsif o='w' then o=2 elsif o='k' then o=3 elsif o='i' then o=4 elsif o='m' then o=5 elsif o='l' then o=6 -- ਡ⥫쭮 ⨭ elsif o='u' then o=7 -- utf-8 else o=0 end if if not i or not o then puts(1,"\n invalid recodeing mode") abort(1) end if if atom(f) then c=find(f,codes[i]) if c then return codes[o][c] else return f end if else if o != 7 then -- ⮢ ஢ for j=1 to length(f) do c=f[j] r=c if c>=128 then c=find(c,codes[i]) if c then f[j]=codes[o][c] else f[j]=r end if end if end for else -- utf-8 F={} for j=1 to length(f) do c=f[j] r=c if c>=128 then c=find(c,codes[i]) if c then F&=codes[8][c] F&=codes[7][c] end if else F&=r end if end for f=F end if return f end if end function -- ४஢() -- global constant -- "ab" stands for "alphabet" -- pure Latin, ASCII ab_az = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz", -- Russian, cp 866, DOS (OEM) encoding ab_ru_d = "񆦇", -- Russian, cp 1251, Windows (ANSI) encoding ab_ru_w = "娸", -- Russian, cp koi8-r, UNIX/Linux encoding ab_ru_l = "ų", -- Russian, cp iso-8859-5, ISO encoding ab_ru_i = "бѲҳӴԵաַ׸عٺڻۼܽݾ޿", -- Russian, cp MAC, Macintosh encoding ab_ru_m = "ކ" -- Add yours native alphabets here for needed code pages and use them global function case_xx(integer c, object x, sequence alphabet) integer A, a sequence table table = repeat(0,256) for i=1 to length(alphabet) - 1 by 2 do A = alphabet[i] a = alphabet[i+1] if c then table[A]= A table[a]= A else table[A]= a table[a]= a end if end for if atom(x) then if x then x = table[x] if x then x = x end if end if else for i=1 to length(x) do a = x[i] if a then if table[a] then x[i] = table[a] end if end if end for end if return x end function -- case_xx() global function ॣ_(integer c, object x, sequence alphabet) integer A, a sequence table table = repeat(0,256) for i=1 to length(alphabet) - 1 by 2 do A = alphabet[i] a = alphabet[i+1] if c then table[A]= A table[a]= A else table[A]= a table[a]= a end if end for if atom(x) then if x then x = table[x] if x then x = x end if end if else for i=1 to length(x) do a = x[i] if a then if table[a] then x[i] = table[a] end if end if end for end if return x end function -- ॣ_() -- usage: -- text = case_xx(1, text, alphabet) -- upper case -- text = case_xx(0, text, alphabet) -- lower case -- text - sequence with your text. -- alphabet - sequence with alphabet for the text's language and code page, -- you need to add this sequence below using pure Latin as an example. -- To type your alphabet for DOS code page use the edit.com or ed.ex editor. -- To type your alphabet for Windows code page use the NotePad editor. global procedure ru_puts(integer p, sequence t, sequence m) sequence M if equal(m, "w") then M = "dw" elsif equal(m, "k") then M = "dk" elsif equal(m, "i") then M = "di" elsif equal(m, "m") then M = "dm" elsif equal(m, "u") then M = "du" else M = "" end if if length(M) then puts(p, recode(t, M)) else puts(p, "--invalid mode of ru_puts()--") end if end procedure -- ru_puts() global procedure ru_뢥(integer p, sequence t, sequence m) sequence M if equal(m, "w") then M = "dw" elsif equal(m, "k") then M = "dk" elsif equal(m, "i") then M = "di" elsif equal(m, "m") then M = "dm" elsif equal(m, "u") then M = "du" else M = "" end if if length(M) then puts(p, recode(t, M)) else puts(p, "--invalid mode of ru_puts()--") end if end procedure -- ru_뢥() global function ru_getc(integer i, sequence m) sequence M M={} if equal(m, "w") then M = "wd" elsif equal(m, "k") then M = "kd" elsif equal(m, "i") then M = "id" elsif equal(m, "m") then M = "md" -- elsif equal(m, "u") then M = "du" end if if length(M) then return(recode(getc(i), M)) else puts(1, "--invalid mode of ru_getc()--") return M end if end function -- ru_getc() ---------------------------------------- -- Igor N. Kachan, kinz@peterlink.ru -- 11.06.2005 -- 28.02.2006 -- 06.03.2011