home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / DUTCH_FN.ZIP / STRIP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-10  |  4.7 KB  |  141 lines

  1. /*********
  2. *
  3. * STRIP.C
  4.  
  5. *   Author : Jean-Pierre van Melis
  6. * Compiled : with Microsoft C 5.1
  7. *   Object : can only be used in conjunction with Clipper summer '87
  8.  
  9. *  Syntax: STRIP( <expC> )
  10. *  Return: All non-alphanumeric characters are removed, and spaces
  11. *          are added to keep the initial length (for indexing purposes).
  12. *          and all characters are made uppercase to gain speed
  13. *          (otherwise you have to use the UPPER() function to do this).
  14. *
  15. *          As an addition, I also implemented foreign language support
  16. *          all extended characters are replaced by there ASCII-counterpart.
  17. *
  18. *          ü û ù Ü ú              replacement : U
  19. *          â ä à å Ä Å á          replacement : A
  20. *
  21. *
  22. *          INPUT                  RETURN
  23. *          ---------------------- ----------------------------------
  24. *           "van der Plas"        "VANDERPLAS  "
  25. *           "garçon"              "GARCON"
  26. *           "tête"                "TETE"
  27. *
  28. * With '#define UPPERCASING FALSE'
  29. *
  30. *          INPUT                  RETURN
  31. *          ---------------------- ----------------------------------
  32. *           "van der Plas"        "vanderPlas  "
  33. *           "garçon"              "garcon"
  34. *           "tête"                "tete"
  35. *
  36. * With '#define UPPERCASING FALSE' and "#define NOSPACE FALSE"
  37. *
  38. *          INPUT                  RETURN
  39. *          ---------------------- ----------------------------------
  40. *           "van der Plas"        "van der Plas"
  41. *           "garçon"              "garcon"
  42. *           "tête"                "tete"
  43. *
  44. *
  45. *        mNAAM = "v/d Broek BV      "
  46. *        USE namen
  47. *        INDEX ON STRIP(naam) TO naam
  48. *        SEEK TRIM(STRIP(mNAAM))
  49. *        IF FOUND()
  50. *           ? naam
  51. *        ENDIF
  52. *
  53. *
  54. *     output: "v/d Broek B.V.    "
  55. *********/
  56.  
  57. #include "jplib.h"
  58.  
  59. #define UPPERCASING TRUE
  60. #define NOSPACE     TRUE
  61.  
  62. #if (UPPERCASING)
  63. static byte convert[40] =
  64. { 'C','U','E','A','A','A','A','C','E','E','E','I','I','I','A','A','E',NULLC,NULLC
  65.  ,'O','O','O','U','U','Y','O','U',NULLC,NULLC,NULLC,NULLC,NULLC,'A','I','O','U'
  66.  ,'N','N','A','O'};
  67. #else
  68. static byte convert[40] =
  69. { 'C','u','e','a','a','a','a','c','e','e','e','i','i','i','A','A','E',NULLC,NULLC
  70.  ,'o','o','o','u','u',NULLC,'O','U',NULLC,NULLC,NULLC,NULLC,NULLC,'a','i','o','u'
  71.  ,'n','N','a','o'};
  72. #endif
  73.  
  74. /*
  75.    Ç   ü   é   â   ä   à   å   ç   ê   ë   è   ï   î   ì   Ä   Å   É    æ     Æ
  76.    ô   ö   ò   û   ù   ÿ   Ö   Ü   ¢      £     ¥     ₧     ƒ    á   í   ó   ú
  77.    ñ   Ñ   ª   º
  78. */
  79.  
  80. CLIPPER strip()
  81.  
  82. {
  83.  
  84.    byte *par;                                      /* pointer to input */
  85.    byte *retstr;                                   /* pointer to output */
  86.  
  87.    quant leng;                                     /* leng of string */
  88.    quant n1;                                       /* offset input */
  89.    quant n2;                                       /* offset output */
  90.  
  91.    Boolean error;
  92.  
  93.    error = TRUE;
  94.  
  95.    if(PCOUNT == 1 && ISCHAR(1))
  96.    {
  97.       par    = _parc(1);                           /* receive pointer from clipper */
  98.       leng   = (quant) _parclen(1);                /* receive leng from clipper */
  99.  
  100.       retstr = _exmgrab(leng+1);                   /* Allocate memory */
  101.  
  102.       if(retstr)                                   /* Enough memory available */
  103.       {
  104.          error = FALSE;                            /* No errors */
  105.          n2    = 0;                                /* point to first character */
  106.  
  107.          for(n1 = 0; n1 < leng; n1++)              /* parse input till end of input*/
  108.          {
  109.             if(islower(par[n1]))                   /* character is lowercase */
  110. #if (UPPERCASING)
  111.               retstr[n2++] = (par[n1] + ('A'-'a'));/* convert to uppercase */
  112. #else
  113.               retstr[n2++] = par[n1];              /* copy from input */
  114. #endif
  115. #if (NOSPACE)
  116.             else if(isdigit(par[n1]) || isupper(par[n1]))
  117. #else
  118.             else if(isdigit(par[n1]) || isupper(par[n1]) || par[n1]=SPACEC)
  119. #endif
  120.               retstr[n2++] = par[n1];              /* copy from input */
  121.             if((par[n1] >127) && (par[n1] < 168))
  122.                if( convert[par[n1]-128])
  123.                   retstr[n2++] = convert[par[n1]-128];
  124.  
  125.          }
  126.          while(n2 < leng)                          /* fill rest with spaces */
  127.             retstr[n2++] = SPACEC;
  128.  
  129.          retstr[n2] = NULLC;                       /* terminate with null */
  130.       }
  131.    }
  132.    if(error)
  133.       _retc(NULLS);                                /* return null string */
  134.    else
  135.    {
  136.       _retclen(retstr, leng);                      /* return string with length */
  137.       _exmback(retstr, leng+1);                    /* deallocate memory */
  138.    }
  139.    return;
  140. }
  141.