home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / firstcap.zip / FCAP1.PRG < prev    next >
Text File  |  1986-03-12  |  3KB  |  104 lines

  1. *********************************************
  2. *           V E R S I O N   1               *
  3. *********************************************
  4. *
  5. *  Function.....: Firstcap() . . . Version 1
  6. *  Author.......: Dennis L. Dias
  7. *  The Source ID....: NAN449
  8. *  Date.........: 12/14/85
  9. *
  10. *  Syntax:  FIRSTCAP( <expC> )
  11. *  Return:
  12. *  Character string with first letter of each word capitalized
  13. *  and the rest lower case.  The special words "and", "but", "for",
  14. *  "the", "by", "an", "of", "on", "in", "if", "to", "or", "at" and
  15. *  "a" will remain lower case unless: (A) The word is the first word
  16. *  in the string with no leading word separators; (B) The word is
  17. *  followed by a non-space character or (C) The word is the last
  18. *  word in the string.
  19. *
  20. *  Note:
  21. *  This first version is written entirely in dBASE.  It calls upon
  22. *  a second function (ISCHAR()..also written in dBASE) to determine
  23. *  which characters are "in-word" characters and which are not. The
  24. *  execution speed is slow..unacceptable for repeated calls.
  25. *
  26. FUNCTION FIRSTCAP
  27. *
  28. PARAMETERS fl_strg
  29. PRIVATE fl_begn,fl_len,fl_pos,fl_outstr,fl_part,fl_true
  30. *
  31. fl_begn = 0
  32. fl_len = 0
  33. fl_pos = 1
  34. IF LEN(fl_strg) = 1
  35.   fl_outstr = UPPER(fl_strg)
  36. ELSE
  37.   fl_outstr = ""
  38. ENDIF
  39. fl_part = ""
  40. fl_true = LEN(fl_strg) > 1
  41. DO WHILE fl_true
  42.   fl_begn = fl_pos
  43.   *
  44.   *  Scan past in-word characters
  45.   *
  46.   DO WHILE ISCHAR(SUBSTR(fl_strg,fl_pos,1)).AND.fl_pos < LEN(fl_strg)
  47.     fl_pos = fl_pos + 1
  48.   ENDDO
  49.   *
  50.   *  Scan past word separators
  51.   *
  52.   DO WHILE .NOT. ISCHAR(SUBSTR(fl_strg,fl_pos,1)) .AND.;
  53.     fl_pos < LEN(fl_strg)
  54.     fl_pos = fl_pos + 1
  55.   ENDDO
  56.   *
  57.   *  Determine if this is the last word
  58.   *
  59.   IF fl_pos = LEN(fl_strg).AND.(ISCHAR(SUBSTR(fl_strg,fl_pos - 1,1));
  60.     .OR. fl_begn = fl_pos)
  61.     fl_len = fl_pos - fl_begn + 1
  62.     *
  63.     *  Set false to exit main loop
  64.     *
  65.     fl_true = .F.
  66.   ELSE
  67.     fl_len = fl_pos - fl_begn
  68.   ENDIF
  69.   *
  70.   *  Isolate one word and convert it to lower case
  71.   *
  72.   fl_part = LOWER(SUBSTR(fl_strg,fl_begn,fl_len))
  73.   *
  74.   *  Test for special word or a one character word at the end of
  75.   *  the line.  The use of (" " + TRIM() + " ") protects against
  76.   *  an unwanted substring match such as ("he " $ "the ").
  77.   *
  78.   DO CASE
  79.     CASE (" " + TRIM(fl_part) + " ") $ " and the for but to or by" +;
  80.          " an in of on at if a " .AND. LEN(fl_outstr) > 0 .AND.;
  81.       fl_pos < LEN(fl_strg)
  82.       *
  83.       *  Special word found in mid-string position where it should
  84.       *  not be capitalized..concatenate the word as is
  85.       *
  86.       fl_outstr = fl_outstr + fl_part
  87.     CASE LEN(fl_part) = 1
  88.       *
  89.       *  LEN() = 1 only occurs when a one character word appears
  90.       *  at the end of the string..capitalize and concatenate
  91.       *
  92.       fl_outstr = fl_outstr + UPPER(fl_part)
  93.     OTHERWISE
  94.       *
  95.       *  Capitalize the first character and concatenate
  96.       *  the word to the output string
  97.       *
  98.       fl_outstr = fl_outstr + UPPER(SUBSTR(fl_part,1,1)) +;
  99.       SUBSTR(fl_part,2)
  100.   ENDCASE
  101. ENDDO
  102. RETURN(fl_outstr)
  103. *
  104.