[Date Prev][Date Next][Subject Prev][Subject Next][ Date Index][ Subject Index]

Re: lower case



Reply to note from cld@xxxxxxxx (myself) Sat, 18 May 2002 03:50:46
-0400

A good night's sleep helped me realize that there's a bug in my AU
demo. If you manually uppercase the first letter of the sentence
(by pressing the Shift key), the *second* letter is auto-uppercased!
No good.

The fix was easy. Before testing for a lowercase keystroke with
) < >, it was necessary to test for an uppercase
keystroke; if the keystroke was already uppercase, the flag had to
be lowered () so that the next letter was *not* forced into
uppercase.

At first blush, you might think that if the test for lowercase is
) < >, the test for uppercase must be
) == >. Think again. That statement is not
only true for uppercase letters, but for all non-alpha characters as
well. Specifically, @upr(" ") == " ", and we certainly don't want
to lower the flag after the user types a space! So, to test
accurately for uppercase, we have to mention the set of all
uppercase letters expressly and test for containment of the current
keystroke: >.

Here's the revised demo:

XPLeNCODE v2.0
b-gin [UNTITLED]
{<}GLa{>}[cr|lf]Auto-Uppercase Simulation Using XPL[cr|lf]Dem
o for XyWrite 4+ [C.L.Distefano rev. 5/18/02-a][cr|lf] {<}MDB
O{>}** Working XPL code {<}MD+UL{>}with comments{<}MD-UL{>} -
 Read in eXPanded view **{<}MDNM{>}[cr|lf][cr|lf]Usage:[cr|lf
]-----[cr|lf]1) Turn off the native AU facility.[cr|lf]2) Ope
n a file.[cr|lf]3) RUN AU.PM[cr|lf]4) Type a few sente
nces. Try some that stump the native AU function:[cr|lf]  f
or example, sentences that begin with parens or quotation mar
ks, and[cr|lf]  sentences that include internal abbreviation
s (e.g., i.e., etc.).[cr|lf]5) Hit Escape to quit.[cr|lf]----
-----------------[cr|lf][cr|lf]{<}LBa{>}[XH_];*; Cancel any d
isplayed menu[cr|lf];*;[cr|lf]{<}IF{<}VA$WS{>}<>1{>}{<}PRNo f
ile{>}{<}EX{>}{<}EI{>};*; If no file is open, say so and EXit
[cr|lf];*;[cr|lf][BX_]es 1[Q2_][GT_];*; Turn on Error Suppres
sion; move cursor to text area[cr|lf];*;[cr|lf];*;[cr|lf];*;{32}
Look-up table for critical keystrokes (work around non-standa
rd[cr|lf];*; keyboard-file assignments for hyphen, space, per
iod and Enter keys)[cr|lf]{<}SV01,|12=-|28=[cr|lf]|52=.|57= |
104=[cr|lf]|{>};*; (end of look-up table)[cr|lf];*;[cr|lf];*;
 SUbroutine to read keystroke and translate non-standard inpu
t:[cr|lf]{<}SU02,{<}SX03,{<}RK{>}{>}{<}SX04,{<}VA$KC{>}{>}{<}
IF{<}PV04{>}<2{>}{<}PRDone{>}{<}EX1{>}{<}EI{>}{<}IF{<}IS01{>}
{240}("|"+{<}IS04{>}+"="){>}{<}SX04,"|"+{<}IS04{>}+"="{>}{<}X
S01,04,,04,04{>}{<}SX03,{<}VA@04|1{>}{>}{<}EI{>}{>};*;[cr|lf]
;*;[cr|lf];*;     Save/Get 05 is a flag (1 = up, 0 = down
)[cr|lf]{<}SX05,1{>};*; Uppercase flag is up (ensures that ve
ry first keystroke is uppercased)[cr|lf];*;[cr|lf];*; Display
 informational PRompt:[cr|lf]{<}LBb{>}{<}PR|Auto-Uppercase si
mulation: Type a few sentences. Escape quits{>};*;[cr|lf];*;[
cr|lf]{<}GT02{>};*; Read keystroke[cr|lf];*;[cr|lf];*; AU pro
cedure:[cr|lf];*;[cr|lf];*; (1) IF the keystroke is a sentenc
e separator (., !, ? or )[cr|lf];*;  {32}
 Write it and put the flag up[cr|lf]{<}IF".!?[cr|lf]"{240}{<}
IS03{>}{>}{<}PV03{>}{<}SX05,1{>};*; [cr|lf];*;[cr|lf];*; If i
t was a carriage return, loop back to LaBel "b"[cr|lf];*; (be
cause the following exceptions do NOT apply to carriage retur
ns):[cr|lf]{<}IF{<}IS03{>}=="[cr|lf]"{>}{<}GLb{>}{<}EI{>};*;[
cr|lf];*;[cr|lf];*; Otherwise, read the next character[cr|lf]
{<}GT02{>};*; [cr|lf];*;[cr|lf];*; Test for two exceptions:[c
r|lf];*; If the next character is a lowercase letter (the "g"
 in "e.g.")[cr|lf];*; or if it's mid-sentence punctuation (,;
-), then lower the flag and...[cr|lf]{<}IF@upr({<}IS03{>})<{<
}IS03{>}!",;-"{240}{<}IS03{>}{>}{<}SX05,0{>}{<}EI{>};*;[cr|lf
];*;[cr|lf];*; ...write the character and loop back[cr|lf]{<}
PV03{>}{<}GLb{>}{<}EI{>};*;[cr|lf];*;[cr|lf];*;[cr|lf];*; (2)
 IF the keystroke is NOT a sentence separator[cr|lf];*;[cr|lf
];*; General rule of Auto-Uppercase:[cr|lf];*;[cr|lf];*; If{32}
keystroke is already uppercase, write it, lower the flag[cr|l
f];*; loop back:[cr|lf]{<}IF"ABCDEFGHIJKLMNOPQRSTUVWXYZ"{240
}{<}IS03{>}{>}{<}PV03{>}{<}SX05,0{>}{<}GLb{>}{<}EI{>};*;[cr|l
f];*;[cr|lf];*; Otherwise, if it's lowercase AND the flag is
 up...[cr|lf]{<}IF@upr({<}IS03{>})<{<}IS03{>}{>}{<}IF{<}PV05{
>}>0{>};*;[cr|lf];*;[cr|lf];*; ...make it uppercase and lower
 the flag[cr|lf]{<}SX03,@upr({<}IS03{>}){>}{<}SX05,0{>}{<}EI{
>}{<}EI{>};*;[cr|lf];*;[cr|lf];*; Write the keystroke and loo
p back[cr|lf]{<}PV03{>}{<}GLb{>}[cr|lf][cr|lf]
-nd
XPLeNCODE

--
Carl Distefano
cld@xxxxxxxx
http://users.datarealm.com/xywwweb/