home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PROG / FTPARS.ZIP / FTPARS.PRG < prev   
Encoding:
Text File  |  1993-04-20  |  2.4 KB  |  90 lines

  1. /*
  2.  * File......: FTPARSE.PRG
  3.  * Author....: Gary F. Alderson
  4.  * CIS ID....: INTERNET> Gary_Alderson@UManitoba.CA
  5.  * Date......: $1993-04-10$
  6.  * Revision..: $1.00$
  7.  * Log file..: $Logfile$
  8.  * 
  9.  * This is an original work by [Gary F. Alderson] and is placed in the
  10.  * public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log$
  16.  *
  17.  */
  18.  
  19. #ifdef FT_TEST
  20.  
  21.     FUNCTION MAIN()
  22.     MEMVAR GETLIST
  23.     LOCAL aToken
  24.     LOCAL cString := "The quick brown fox jumped over the lazy dog"
  25.     LOCAL cDelim := " "
  26.  
  27.     CLS
  28.     SET CONFIRM ON
  29.     @ 10,01 SAY "String to be parsed:";
  30.             GET cString PICTURE "@KS44"
  31.     @ 12,01 SAY "Delimiter between tokens:";
  32.             GET cDelim
  33.     READ
  34.  
  35.     aToken := FT_PARSE(cString, cDelim)
  36.     QOUT('The string "'+cString+'"')
  37.     QOUT('Delimiter  "'+cDelim+'"')
  38.     QOUT("Its tokens:")
  39.     AEVAL( aToken, {|cToken| QOUT('"'+cToken+'"')} )
  40.  
  41.     RETURN (NIL)
  42.  
  43. #endif
  44.  
  45. /*  $DOC$
  46.  *  $FUNCNAME$
  47.  *      FT_PARSE()
  48.  *  $CATEGORY$
  49.  *      To be assigned
  50.  *  $ONELINER$
  51.  *      This routine will split up a character string into tokens.
  52.  *  $SYNTAX$
  53.  *      FT_PARSE( <cString>, [<cDelim>] ) -> aToken
  54.  *  $ARGUMENTS$
  55.  *      cString - the character string to be parsed into tokens
  56.  *      cDelim  - the delimiter which seperates the tokens
  57.  *  $RETURNS$
  58.  *      An array of tokens contained in the string is returned.
  59.  *  $DESCRIPTION$
  60.  *      This routine when called with a character string containing several
  61.  *      tokens and a character string containing the delimiter between those
  62.  *      tokens, will return an array of the tokens. If a delimiter is not
  63.  *      passed then a space will be used. As well, leading and trailing blanks
  64.  *      are removed from the string and its tokens.
  65.  *  $EXAMPLES$
  66.  *      aToken := FT_PARSE("C:\A\VERY\LONG\FILE\SPEC\ABC.TXT", "\")
  67.  *      Upon return, aToken will contain the following array
  68.  *           {"C:","A","VERY","LONG","FILE","SPEC","ABC.TXT"}
  69.  *  $SEEALSO$
  70.  *      none
  71.  *  $INCLUDE$
  72.  *      none
  73.  *  $END$
  74.  */
  75. FUNCTION FT_PARSE(cString, cDelim)
  76. LOCAL nPtr
  77. LOCAL aToken := {}
  78.  
  79. cDelim  := IF(cDelim == NIL, " ", cDelim)
  80. cString := ALLTRIM(cString)
  81.  
  82. DO  WHILE (nPtr := AT(cDelim, cString)) != 0
  83.     AADD(aToken, IF(nPtr > 1, RTRIM(LEFT(cString, nPtr-1)), ""))
  84.     cString := IF(LEN(cString) > nPtr, LTRIM(SUBSTR(cString, nPtr+1)), "")
  85. ENDDO
  86.  
  87. AADD(aToken, cString)
  88.  
  89. RETURN(aToken)
  90.