home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / actlib12.zip / STRINGS.ZIP / REDUCE.C < prev    next >
C/C++ Source or Header  |  1993-02-25  |  1KB  |  54 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #include "strings.h"
  4. #include <ctype.h>
  5.  
  6. /***
  7.  *  Function    :  strreduce
  8.  *
  9.  *
  10.  *  Description :  Parse a string to suppress blanks, tabs and newlines
  11.  *                 and transform it in uppercase.
  12.  *
  13.  *
  14.  *  Decisions   :  - Portions of string between double quotes are unmodified
  15.  *                   (quotes are removed).
  16.  *
  17.  *                 - '\' is used to quote the next character.
  18.  *
  19.  *                 - Characters with accent are also transformed to uppercase.
  20.  *
  21.  *  Parameters  :  in/out   char *string
  22.  *
  23.  *  Return      :  pointer to end of string ( '\0' ).
  24.  *
  25.  *  OS/Compiler :  All
  26.  ***/
  27.  
  28. char *strreduce( char *string )
  29.  
  30. { char *ptr;
  31.  
  32.                 /*   Suppress quotes and put in uppercase   */
  33.   for ( ptr = string; *string; string ++ )
  34.       switch( *string )
  35.             {
  36.               case '"' : string ++;
  37.                          while ( *string && *string != '"' ) *ptr++ = *string++;
  38.                      if ( *string == '"' && *(++string) == '"' ) *ptr++ = '"';
  39.                      break;
  40.  
  41.               case ' ' :
  42.               case '\t':
  43.               case '\n': break;
  44.  
  45.               case '\\': *ptr++ = *string;
  46.  
  47.               default  : *ptr++ = chcase( *string, UPPER );
  48.                          break;
  49.             }
  50.  
  51.   *ptr = '\0';
  52.   return --ptr;
  53. }
  54.