home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / wcsspn.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  2KB  |  66 lines

  1. /***
  2. *wcsspn.c - find length of initial substring of chars from a control string
  3. *       (wide-character strings)
  4. *
  5. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  6. *
  7. *Purpose:
  8. *       defines wcsspn() - finds the length of the initial substring of
  9. *       a string consisting entirely of characters from a control string
  10. *       (wide-character strings).
  11. *
  12. *******************************************************************************/
  13.  
  14.  
  15. #include <cruntime.h>
  16. #include <string.h>
  17.  
  18. /***
  19. *int wcsspn(string, control) - find init substring of control chars
  20. *
  21. *Purpose:
  22. *       Finds the index of the first character in string that does belong
  23. *       to the set of characters specified by control.  This is
  24. *       equivalent to the length of the initial substring of string that
  25. *       consists entirely of characters from control.  The L'\0' character
  26. *       that terminates control is not considered in the matching process
  27. *       (wide-character strings).
  28. *
  29. *Entry:
  30. *       wchar_t *string - string to search
  31. *       wchar_t *control - string containing characters not to search for
  32. *
  33. *Exit:
  34. *       returns index of first wchar_t in string not in control
  35. *
  36. *Exceptions:
  37. *
  38. *******************************************************************************/
  39.  
  40. size_t __cdecl wcsspn (
  41.         const wchar_t * string,
  42.         const wchar_t * control
  43.         )
  44. {
  45.         wchar_t *str = (wchar_t *) string;
  46.         wchar_t *ctl;
  47.  
  48.         /* 1st char not in control string stops search */
  49.         while (*str) {
  50.             for (ctl = (wchar_t *)control; *ctl != *str; ctl++) {
  51.                 if (*ctl == (wchar_t)0) {
  52.                     /*
  53.                      * reached end of control string without finding a match
  54.                      */
  55.                     return str - string;
  56.                 }
  57.             }
  58.             str++;
  59.         }
  60.         /*
  61.          * The whole string consisted of characters from control
  62.          */
  63.         return str - string;
  64. }
  65.  
  66.