RE: Small feature request for future EU versions
- Posted by "Ricardo M. Forno" <rforno at uyuyuy.com> Oct 26, 2004
- 558 views
----- Original Message ----- From: Igor Kachan <kinz at peterlink.ru> To: <EUforum at topica.com> Sent: Monday, October 25, 2004 8:57 AM Subject: Re: Small feature request for future EU versions > > > Hi, Dear EU users! > > Me wrote: > > [snip] > > Me did not provide the universal function for any alphabet, > > but a *way* to make the concrete function for concrete alphabet. > [snip] > > The task is not very difficult if you do know your native alphabet, > > be sure, dear End Users. > > Let us try to use that way to make the concrete (i.e. specific, only > this one, not any other) function for concrete well known alphabet > -- pure Latin -- alphabet_la, just for example. > > }}} <eucode> > > sequence alphabet_la > alphabet_la="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" > > global function case_LA(integer c, object x) > -- case_LA -- to not confuse with the existing case_la() function > -- convert Latin atom or sequence to upper or to lower case > integer n > sequence A, a > if c then > A=alphabet_la[1 ..26] > a=alphabet_la[27..52] > else > a=alphabet_la[1 ..26] > A=alphabet_la[27..52] > end if > n = 0 > if atom(x) then n=find(x,a) > if n then return A[n] > else return 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_LA() > > puts(1, alphabet_la & '\n') > puts(1, case_LA(1, alphabet_la) & '\n') > puts(1, case_LA(0, alphabet_la) & '\n') > > </eucode> {{{ > > Just replace the alphabet_la sequence with your native alphabet > and you will have concrete function for your native language > and for your current code page. > If you see your alphabet correctly in your editor, all right. > Do not forget, on DOS and Windows may be different results. > > Say, > sequence alphabet_mj > alphabet_mj = "......place here The Great Mumbo Jumbo Alphabet....." > > global function case_mj(integer c, object x) > And so on. > > Do not forget: > A=alphabet_mj[1 .. not 26, but needed number] > a=alphabet_mj[not 27, but needed number .. not 52, but needed number] > -- Just first and second half. > > ... is easy peasy, NO? -- by Pete Lomax > > But I just now found one old bug in my case_ru() function. > Thanks for your questions! > > Regards, > Igor Kachan > kinz at peterlink.ru Hi, Igor. Your function is slow compared to other approaches. Since in Euphoria (and also i C and other languages) a character is just a number, may I suggest a change? I think it would be much faster having two 256-character sequences, one representing the "translation" of the other (characters in the same position), and using the input characters as indexes. This way, you will get not only a way to translate between upper and lower case, but also (changing the sequences) to translate ASCII to EBCDIC or vice-versa, or any translation character by character you want. Regards.