Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.3 KiB

  1. /***
  2. *wcsspn.c - find length of initial substring of chars from a control string
  3. * (wide-character strings)
  4. *
  5. * Copyright (c) 1985-2001, 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. *Revision History:
  13. * 11-04-91 ETC Created with source from crtdll.
  14. * 04-07-92 KRS Updated and ripped out _INTL switches.
  15. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  16. * 02-07-94 CFW POSIXify.
  17. * 02-27-98 RKP Added 64 bit support.
  18. *
  19. *******************************************************************************/
  20. #ifndef _POSIX_
  21. #include <cruntime.h>
  22. #include <string.h>
  23. /***
  24. *int wcsspn(string, control) - find init substring of control chars
  25. *
  26. *Purpose:
  27. * Finds the index of the first character in string that does belong
  28. * to the set of characters specified by control. This is
  29. * equivalent to the length of the initial substring of string that
  30. * consists entirely of characters from control. The L'\0' character
  31. * that terminates control is not considered in the matching process
  32. * (wide-character strings).
  33. *
  34. *Entry:
  35. * wchar_t *string - string to search
  36. * wchar_t *control - string containing characters not to search for
  37. *
  38. *Exit:
  39. * returns index of first wchar_t in string not in control
  40. *
  41. *Exceptions:
  42. *
  43. *******************************************************************************/
  44. size_t __cdecl wcsspn (
  45. const wchar_t * string,
  46. const wchar_t * control
  47. )
  48. {
  49. wchar_t *str = (wchar_t *) string;
  50. wchar_t *ctl;
  51. /* 1st char not in control string stops search */
  52. while (*str) {
  53. for (ctl = (wchar_t *)control; *ctl != *str; ctl++) {
  54. if (*ctl == (wchar_t)0) {
  55. /*
  56. * reached end of control string without finding a match
  57. */
  58. return (size_t)(str - string);
  59. }
  60. }
  61. str++;
  62. }
  63. /*
  64. * The whole string consisted of characters from control
  65. */
  66. return (size_t)(str - string);
  67. }
  68. #endif /* _POSIX_ */