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

  1. /***
  2. *wcscspn.c - find length of initial substring of wide characters
  3. *        not in a control string
  4. *
  5. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  6. *
  7. *Purpose:
  8. *       defines wcscspn()- finds the length of the initial substring of
  9. *       a string consisting entirely of characters not in a control string
  10. *       (wide-character strings).
  11. *
  12. *******************************************************************************/
  13.  
  14.  
  15. #include <cruntime.h>
  16. #include <string.h>
  17.  
  18. /***
  19. *size_t wcscspn(string, control) - search for init substring w/o control wchars
  20. *
  21. *Purpose:
  22. *       returns the index of the first character in string that belongs
  23. *       to the set of characters specified by control.  This is equivalent
  24. *       to the length of the length of the initial substring of string
  25. *       composed entirely of characters not in control.  Null chars not
  26. *       considered (wide-character strings).
  27. *
  28. *Entry:
  29. *       wchar_t *string - string to search
  30. *       wchar_t *control - set of characters not allowed in init substring
  31. *
  32. *Exit:
  33. *       returns the index of the first wchar_t in string
  34. *       that is in the set of characters specified by control.
  35. *
  36. *Exceptions:
  37. *
  38. *******************************************************************************/
  39.  
  40. size_t __cdecl wcscspn (
  41.         const wchar_t * string,
  42.         const wchar_t * control
  43.         )
  44. {
  45.         wchar_t *str = (wchar_t *) string;
  46.         wchar_t *wcset;
  47.  
  48.         /* 1st char in control string stops search */
  49.         while (*str) {
  50.             for (wcset = (wchar_t *)control; *wcset; wcset++) {
  51.                 if (*wcset == *str) {
  52.                     return str - string;
  53.                 }
  54.             }
  55.             str++;
  56.         }
  57.         return str - string;
  58. }
  59.  
  60.