home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / orx8.zip / routine_strip_quote.cmd < prev    next >
OS/2 REXX Batch file  |  1997-07-21  |  4KB  |  77 lines

  1. /******************************************************************************/
  2. /*
  3. program:   routine_strip_quote.cmd
  4. type:      Object REXX, REXXSAA 6.0
  5. purpose:   filters a string to contain English alphanumeric chars only; embedded non-alphanum chars are
  6.            translated into an underscore ("_")
  7. version:   1.0
  8. date:      1997-04-15
  9. changed:   ---
  10.  
  11. author:    Rony G. Flatscher
  12.            Rony.Flatscher@wu-wien.ac.at
  13.            (Wirtschaftsuniversitaet Wien, University of Economics and Business
  14.            Administration, Vienna/Austria/Europe)
  15. needs:     ---
  16.  
  17. usage:     call or require & see code, resp. comments
  18.            (also, you might copy & paste the code to the desired module, given its size)
  19.  
  20. comments:  prepared for the "8th International Rexx Symposium 1997", April 1997, Heidelberg/Germany
  21.  
  22.  
  23. All rights reserved and copyrighted 1995-1997 by the author, no guarantee that
  24. it works without errors, etc.  etc.
  25.  
  26. You are granted the right to use this module under the condition that you don't charge money for this module (as you didn't write
  27. it in the first place) or modules directly derived from this module, that you document the original author (to give appropriate
  28. credit) with the original name of the module and that you make the unaltered, original source-code of this module available on
  29. demand.  If that holds, you may even bundle this module (either in source or compiled form) with commercial software.
  30.  
  31. If you find an error, please send me the description (preferably a *very* short example);
  32. I'll try to fix it and re-release it to the net.
  33. */
  34.  
  35.  
  36.  
  37. /*                                                                            */
  38. /* name:    strip_quote( string [, flag [, quote ] ] )                        */
  39. /*                                                                            */
  40. /* purpose: strip or add quotes around a string                               */
  41. /*                                                                            */
  42. /* returns: appropriate string                                                */
  43. /*                                                                            */
  44. /* remarks: if "flag" is .false, then string gets quoted with "quote"         */
  45. /*                                                                            */
  46. /* created: rgf, 96-02-09, 97-04-11                                           */
  47.  
  48. :: ROUTINE strip_quotes         PUBLIC
  49.    USE ARG string, bStrip, quote
  50.  
  51.   bStrip = ( bStrip <> .false )                 /* default to stripping quotes  */
  52.  
  53.   IF bStrip THEN                                /* strip quotes                 */
  54.   DO
  55.      string = STRIP( string )                   /* remove leading/trailing blanks */
  56.      quote  = LEFT( string, 1 )                 /* determine quote              */
  57.  
  58.      IF POS( quote, '"' || "'" ) > 0 THEN       /* check for quote              */
  59.      DO
  60.         IF RIGHT( string, 1 ) = quote THEN      /* closing quote present ?      */
  61.         DO
  62.            string = SUBSTR( string, 2, LENGTH( string ) - 2 )      /* remove surrounding quotes    */
  63.            string = CHANGESTR( quote || quote, string, quote )     /* take care of escaped quotes  */
  64.         END
  65.      END
  66.   END
  67.   ELSE                                          /* put surrounding quotes, double existing quotes */
  68.   DO
  69.      IF \ VAR( "quote" ) THEN quote = '"'       /* default quote                */
  70.      string = quote || CHANGESTR( quote, string, quote || quote ) || quote      /* escape quotes */
  71.   END
  72.   RETURN string
  73.  
  74. /******************************************************************************/
  75. /******************************************************************************/
  76.  
  77.