upper() & lower()
- Posted by kbochert at copper.net Jul 08, 2003
- 406 views
--Message-Boundary-18521 Content-description: Mail message body On 8 Jul 2003 at 9:14, rml at rubis.trix.net wrote: > >If so, what code page are you using? (Open a dos box and type "chcp" > >at the prompt). > > Microsoft Windows 2000 [Version 5.00.2195] > (C) Copyright 1985-2000 Microsoft Corp. > > C:\>chcp > Active code page: 437 > Same as yours. > The problem occurs in dos boxes, and in the trace window. > I will test today in windows. > Code page 437 is the English page. Code page 860 is Portugese. I tried to switch code pages in my Dos box as documented in an old MSDOS manual but was unable to get it to work. In any event, attached is a program containing a table-driven replacement for upper() and lower() with tables for code pages 1252, 437 and 860. A lot of effort, given that it only effects seven characters on code page 437!! Karl Bochert --Message-Boundary-18521 Content-type: text/plain; charset=ISO-8859-1 Content-transfer-encoding: Quoted-printable Content-description: Text from file 'case.exw' -- -- code-page version of upper() and lower() -- -- 08 Jul 03 kbochert at copper.net constant l =3D 'A' - 'a' constant u =3D 'a' - 'A' constant casetab =3D { -- common to all code pages 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u, -- @ A u,u,u,u,u,u,u,u,u,u,u,0,0,0,0,0, -- P Q 0,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l, -- @ a l,l,l,l,l,l,l,l,l,l,l,0,0,0,0,0, -- p q } constant map1252 =3D { -- for code page 1252 (Windows) { 0,0,0,0,0,0,0,0,0,0, 16,0, 16,0,0,0, -- =8A =8C 0,0,0,0,0,0,0,0,0,0,-16,0,-16,0,0,0, -- =9A =9C 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, u,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u, -- =C0 =C1 =C2 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0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } constant map437 =3D { -- For code page 437 (English) { -- 1 =3D uppercase; -2 =3D lowercase 1,-2,-2,0,-2,0,-2,-2, 0,0,0,0,0,0,1,1, 1,0,0,0 -2, 0,0,0, 0, 1,1,0,0,0,0,0, 0,0,0,0,-2, 1,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { -- offset to other case 7, 25, 14, 0,10, 0, 9, -7, 0, 0, 0, 0, 0, 0,-10, -9, -14, 0, 0, 0, 5, 0, 0, 0, 0, -5,-25, 0, 0,0, 0, 0, 0, 0, 0, 0, 1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } sequence map map =3D map437 function up_char(integer x) if x < 'A' or x > 255 then return x end if if x < 128 then if casetab[x] < 0 then --lower case return x + casetab[x] else return x end if end if if map[1][x-127] < 0 then --lower case return x + map[2][x-127] end if return x end function function dn_char(integer x) if x < 'A' or x > 255 then return x end if if x < 128 then if casetab[x] > 0 then --upper case return x + casetab[x] else return x end if end if if map[1][x-127] > 0 then --upper case return x + map[2][x-127] end if return x end function global function upper(object x) if not sequence(x) then return up_char(x) end if for i =3D 1 to length (x) do x[i] =3D up_char(x[i]) end for return x end function global function lower(object x) if not sequence(x) then return dn_char(x) end if for i =3D 1 to length (x) do x[i] =3D dn_char(x[i]) end for return x end function sequence x x =3D "12345678" procedure show(integer n) for i =3D 1 to 8 do x[i] =3D n + i -1 end for puts(1, " " & x & '\n') puts(1, "upper: " & upper(x) & '\n') puts(1, "lower: " & lower(x) & '\n') end procedure show(60) show(120) show(128) show(136) pause --Message-Boundary-18521--