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

Re: lower case



Reply to note from "Morris Krok"  Fri, 17 May
2002 09:19:06 -0700

> your Au program works just fine.... could you explain the
> various steps of your program....

Sure. In plain English, the program observes the following general
rule: Once a period is typed, check for the next lowercase letter
and make it uppercase. (This extends AU to sentences that begin
with a non-alpha character, such as quotes or parens.)

There are two exceptions: Do NOT convert to uppercase if (1) a
lowercase letter immediately follows the period, with no intervening
space (the "g" in "e.g."), or (2) the period is followed by mid-
sentence punctuation (for example, the comma in "I was born in the
U.S., and I live there"). For purposes of the demo, I didn't
attempt to deal with the case where a period followed by a space
doesn't end the sentence. For example, the demo is fooled by "I am
a U.S. citizen" (erroneously capitalizes "Citizen").

The code will be easier to read if you understand the functions of
the various Save/Gets. Here's a list:

S/G Function
01  Look-up table for critical keystrokes
02  SUbroutine to read and translate keystrokes
03  Captured keystroke
04  Key code of captured keystroke
05  Uppercase captured keystroke? (1=Yes, 0=No)

Don't fret over the details of 01, 02 and 04. In brief, they make
sure that the program correctly interprets certain critical
keystrokes (space, period and carriage return) when the keyboard-
file assignment is non-standard. An interesting problem, but
tangential to AU.

The key things to remember are:  *captures* the keystroke.
 *writes* the captured keystroke, with or without first
converting it to uppercase with @upr(). Save/Get 05 is a
flag. If the flag is up (the value of 05 is 1), the next lowercase
keystroke is converted to uppercase (and the flag is lowered). If
the flag is down (the value of 05 is 0), the next lowercase
keystroke is written as is. The flag stays down until the next
sentence separator (period, question mark or exclamation point)
sends it back up.

One other thing. How do you detect a lowercase letter? A straight-
forward way is to test for inclusion in the 26-character set
"abcdefghijklmnopqrstuvwxyz". A more compact way is this: A
character is a lowercase letter if the uppercase operator (@upr)
produces something other than the character itself; in code, if
@upr() is *less than* . Why is an uppercase letter
"less than" its lowercase counterpart? Because in the Ascii
character set, the 26 uppercase letters have lower numbers than the
26 lowercase letters. For example, uppercase "A" is Ascii 65;
lowercase "a" is Ascii 97.

Here's the demo code with comments (issue DECODE to decode
it). The bird's eye view is as follows:

Endless loop starts at LaBel "b": Read a keystroke.
(1) If it's a sentence separator:
  (a) Write it and put the flag up
  (b) Read the next keystroke and test for the two exceptions
(2) If it's not a sentence separator, apply the general rule:
  (a) If the flag is up, uppercase it and lower the flag
  (b) Write it and loop back.

Have fun!

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][cr|lf] {<}MDBO{
>}** Working XPL code {<}MD+UL{>}with comments{<}MD-UL{>} - R
ead in eXPanded view **{<}MDNM{>}[cr|lf][cr|lf]Usage:[cr|lf]-
----[cr|lf]1) Turn off the native AU facility.[cr|lf]2) Open{32}
a file.[cr|lf]3) RUN AU.PM[cr|lf]4) Type a few sentenc
es. Try some that stump the native AU function:[cr|lf]  for
 example, sentences that begin with parens or quotation marks
, and[cr|lf]  sentences that include internal abbreviations{32}
(e.g., i.e., etc.).[cr|lf]5) Hit Escape to quit.[cr|lf]------
---------------[cr|lf][cr|lf]{<}LBa{>}[XH_];*; Cancel any dis
played menu[cr|lf];*;[cr|lf]{<}IF{<}VA$WS{>}<>1{>}{<}PRNo fil
e{>}{<}EX{>}{<}EI{>};*; If no file is open, say so and EXit[c
r|lf];*;[cr|lf][BX_]es 1[Q2_][GT_];*; Turn on Error Suppressi
on; move cursor to text area[cr|lf];*;[cr|lf];*;[cr|lf];*; Lo
ok-up table for critical keystrokes (work around non-standard
[cr|lf];*; keyboard-file assignments for hyphen, space, perio
d and Enter keys)[cr|lf]{<}SV01,|12=-|28=[cr|lf]|52=.|57= |10
4=[cr|lf]|{>};*; (end of look-up table)[cr|lf];*;[cr|lf];*; S
Ubroutine to read keystroke and translate non-standard input:
[cr|lf]{<}SU02,{<}SX03,{<}RK{>}{>}{<}SX04,{<}VA$KC{>}{>}{<}IF
{<}PV04{>}<2{>}{<}PRDone{>}{<}EX1{>}{<}EI{>}{<}IF{<}IS01{>}{2
40}("|"+{<}IS04{>}+"="){>}{<}SX04,"|"+{<}IS04{>}+"="{>}{<}XS0
1,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 very
 first keystroke is uppercased)[cr|lf];*;[cr|lf];*; Display i
nformational PRompt:[cr|lf]{<}LBb{>}{<}PR|Auto-Uppercase simu
lation: Type a few sentences. Escape quits{>};*;[cr|lf];*;[cr
|lf]{<}GT02{>};*; Read keystroke[cr|lf];*;[cr|lf];*; AU proce
dure:[cr|lf];*;[cr|lf];*; (1) IF the keystroke is a sentence{32}
separator (., !, ? or )[cr|lf];*;   W
rite it and put the flag up[cr|lf]{<}IF".!?[cr|lf]"{240}{<}IS
03{>}{>}{<}PV03{>}{<}SX05,1{>};*; [cr|lf];*;[cr|lf];*; If it{32}
was a carriage return, loop back to LaBel "b"[cr|lf];*; (beca
use the following exceptions do NOT apply to carriage returns
):[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:[cr|
lf];*; If the next character is a lowercase letter (the "g" i
n "e.g.")[cr|lf];*; or if it's mid-sentence punctuation (,;-)
, then lower the flag and...[cr|lf]{<}IF@upr({<}IS03{>})<{<}I
S03{>}!",;-"{240}{<}IS03{>}{>}{<}SX05,0{>}{<}EI{>};*;[cr|lf];
*;[cr|lf];*; ...write the character and loop back[cr|lf]{<}PV
03{>}{<}GLb{>}{<}EI{>};*;[cr|lf];*;[cr|lf];*;[cr|lf];*; (2) I
F the keystroke is NOT a sentence separator[cr|lf];*;   Gen
eral rule of Auto-Uppercase:[cr|lf];*;   If it's lowercase{32}
AND the flag is up...[cr|lf]{<}IF@upr({<}IS03{>})<{<}IS03{>}{
>}{<}IF{<}PV05{>}>0{>};*;[cr|lf];*;[cr|lf];*; ...make it uppe
rcase and lower the flag[cr|lf]{<}SX03,@upr({<}IS03{>}){>}{<}
SX05,0{>}{<}EI{>}{<}EI{>};*;[cr|lf];*;[cr|lf];*; Write the ke
ystroke and loop back[cr|lf]{<}PV03{>}{<}GLb{>}[cr|lf][cr|lf]
-nd
XPLeNCODE

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