home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
xbase
/
library
/
clipper
/
keyboard
/
caps
/
fcap1.prg
< prev
next >
Wrap
Text File
|
1986-03-12
|
3KB
|
104 lines
*********************************************
* V E R S I O N 1 *
*********************************************
*
* Function.....: Firstcap() . . . Version 1
* Author.......: Dennis L. Dias
* The Source ID....: NAN449
* Date.........: 12/14/85
*
* Syntax: FIRSTCAP( <expC> )
* Return:
* Character string with first letter of each word capitalized
* and the rest lower case. The special words "and", "but", "for",
* "the", "by", "an", "of", "on", "in", "if", "to", "or", "at" and
* "a" will remain lower case unless: (A) The word is the first word
* in the string with no leading word separators; (B) The word is
* followed by a non-space character or (C) The word is the last
* word in the string.
*
* Note:
* This first version is written entirely in dBASE. It calls upon
* a second function (ISCHAR()..also written in dBASE) to determine
* which characters are "in-word" characters and which are not. The
* execution speed is slow..unacceptable for repeated calls.
*
FUNCTION FIRSTCAP
*
PARAMETERS fl_strg
PRIVATE fl_begn,fl_len,fl_pos,fl_outstr,fl_part,fl_true
*
fl_begn = 0
fl_len = 0
fl_pos = 1
IF LEN(fl_strg) = 1
fl_outstr = UPPER(fl_strg)
ELSE
fl_outstr = ""
ENDIF
fl_part = ""
fl_true = LEN(fl_strg) > 1
DO WHILE fl_true
fl_begn = fl_pos
*
* Scan past in-word characters
*
DO WHILE ISCHAR(SUBSTR(fl_strg,fl_pos,1)).AND.fl_pos < LEN(fl_strg)
fl_pos = fl_pos + 1
ENDDO
*
* Scan past word separators
*
DO WHILE .NOT. ISCHAR(SUBSTR(fl_strg,fl_pos,1)) .AND.;
fl_pos < LEN(fl_strg)
fl_pos = fl_pos + 1
ENDDO
*
* Determine if this is the last word
*
IF fl_pos = LEN(fl_strg).AND.(ISCHAR(SUBSTR(fl_strg,fl_pos - 1,1));
.OR. fl_begn = fl_pos)
fl_len = fl_pos - fl_begn + 1
*
* Set false to exit main loop
*
fl_true = .F.
ELSE
fl_len = fl_pos - fl_begn
ENDIF
*
* Isolate one word and convert it to lower case
*
fl_part = LOWER(SUBSTR(fl_strg,fl_begn,fl_len))
*
* Test for special word or a one character word at the end of
* the line. The use of (" " + TRIM() + " ") protects against
* an unwanted substring match such as ("he " $ "the ").
*
DO CASE
CASE (" " + TRIM(fl_part) + " ") $ " and the for but to or by" +;
" an in of on at if a " .AND. LEN(fl_outstr) > 0 .AND.;
fl_pos < LEN(fl_strg)
*
* Special word found in mid-string position where it should
* not be capitalized..concatenate the word as is
*
fl_outstr = fl_outstr + fl_part
CASE LEN(fl_part) = 1
*
* LEN() = 1 only occurs when a one character word appears
* at the end of the string..capitalize and concatenate
*
fl_outstr = fl_outstr + UPPER(fl_part)
OTHERWISE
*
* Capitalize the first character and concatenate
* the word to the output string
*
fl_outstr = fl_outstr + UPPER(SUBSTR(fl_part,1,1)) +;
SUBSTR(fl_part,2)
ENDCASE
ENDDO
RETURN(fl_outstr)
*