: "@(#)shar.sh 1.8" #! /bin/sh # # This is a shell archive. # Remove everything above this line and run sh on the resulting file. # If this archive is complete, you will see this message at the end: # "All files extracted" # # Created: Wed Jul 28 14:31:24 EDT 1999 by informix at Informix Software Ltd. # Files archived in this archive: # README # newupper.def.sql # #-------------------- if [ -f README -a "$1" != "-c" ] then echo shar: README already exists else echo 'x - README (676 characters)' sed -e 's/^X//' >README <<'SHAR-EOF' XNew upper. X XI know its too late because Informix has implemented the upper but I thought that maybe a few people were stuck on older versions. X XHere is a better UPPER. I can't believe nobody thought of these before. The Binary search is coded (because I wanted to prove that it was faster and it was a real pain in the butt, tedious). The other is a simple change to the current version of the UPPER ( it is mentioned in the comments) that is on this web site and it will make you thump your forehead if you have been using the upper. X XUse these and enjoy. X XIf you win the Nobel peace prize as a result of using these routines then mention my name in your acceptance speech. SHAR-EOF if [ `wc -c newupper.def.sql <<'SHAR-EOF' X{ X XCurtis Crowson Xcrowson.curtis@bapco.bls.com X Xuse and enjoy. idea taken from Programming Pearls. A very good book. X X XThis is a better upper routine. X XIt uses a hard coded binary search of the letters a - z to figure out which letter you have. :-p (yuck, arrays would be nice.) This uses 6 compares vs the average 11 (13 if the letter frequencies are evenly distributed, which they are obviously not) compares of the algorithm that uses 26 ordered if statements. (The words in USA English contain more letters from the first half of the alphabet.) X Xif you don't like doing a hard coded binary search you can rearrange your compares in the standard upper Xto match the letter frequency in your language. You need to do a letter count of the data you upper and then rearrange the Xcompares from most frequent to least frequent. In all cases this will be faster than the a - z ordering. In some cases (specialized reduced alphabets) the reordering will even be faster than the binary search algorithm. XThe binary search algorithm is faster in general. X XIf you need to make this work with extended alphabets just add code where appropriate ;-). Hint order the letters by a 'z' then X let retstr = retstr || str[1,1]; X elif str[1,1] < 'n' then X if str[1,1] < 'h' then X if str[1,1] < 'e' then X if str[1,1] < 'c' then X if str[1,1] = 'a' then X let retstr = retstr || "A"; X else X let retstr = retstr || "B"; X end if; X elif str[1,1] = 'c' then X let retstr = retstr || "C"; X else X let retstr = retstr || "D"; X end if; X X elif str[1,1] < 'g' then X if str[1,1] = 'e' then X let retstr = retstr || "E"; X else X let retstr = retstr || "F"; X end if; X else X let retstr = retstr || "G"; X end if; X elif str[1,1] < 'k' then X if str[1,1] < 'j' then X if str[1,1] = 'h' then X let retstr = retstr || "H"; X else X let retstr = retstr || "I"; X end if; X else X let retstr = retstr || "J"; X end if; X elif str[1,1] < 'm' then X if str[1,1] = 'k' then X let retstr = retstr || "K"; X else X let retstr = retstr || "L"; X end if; X else X let retstr = retstr || "M"; X end if; X elif str[1,1] < 'u' then X if str[1,1] < 'r' then X if str[1,1] < 'p' then X if str[1,1] = 'n' then X let retstr = retstr || "N"; X else X let retstr = retstr || "O"; X end if; X elif str[1,1] = 'p' then X let retstr = retstr || "P"; X else X let retstr = retstr || "Q"; X end if; X elif str[1,1] < 't' then X if str[1,1] = 'r' then X let retstr = retstr || "R"; X else X let retstr = retstr || "S"; X end if; X else X let retstr = retstr || "T"; X end if; X elif str[1,1] < 'x' then X if str[1,1] < 'w' then X if str[1,1] = 'u' then X let retstr = retstr || "U"; X else X let retstr = retstr || "V"; X end if; X else X let retstr = retstr || "W"; X end if; X elif str[1,1] < 'z' then X if str[1,1] = 'x' then X let retstr = retstr || "X"; X else X let retstr = retstr || "Y"; X end if; X else X let retstr = retstr || "Z"; X end if; X-- end-- if; X X LET str = str[2,255]; X X END FOR; X X-- LET retstr = retstr[2,255]; X X RETURN retstr; X X END IF; X XEND PROCEDURE; X X X SHAR-EOF if [ `wc -c