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.

108 lines
2.9 KiB

  1. /***
  2. *wcstok.c - tokenize a wide-character string with given delimiters
  3. *
  4. * Copyright (c) 1989-1993, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines wcstok() - breaks wide-character string into series of token
  8. * via repeated calls.
  9. *
  10. *Revision History:
  11. * 09-09-91 ETC Created from strtok.c.
  12. * 08-17-92 KRS Activate multithread support.
  13. * 02-17-93 GJF Changed for new _getptd().
  14. * 11-14-95 JAE Break dependence on C RTL's per-thread data
  15. *
  16. *******************************************************************************/
  17. #include <windows.h>
  18. #include <cruntime.h>
  19. #include <string.h>
  20. #include <ole2.h>
  21. #include <debnot.h>
  22. #include "tls.h"
  23. /***
  24. *wchar_t *wcstok(string, control) - tokenize string with delimiter in control
  25. * (wide-characters)
  26. *
  27. *Purpose:
  28. * wcstok considers the string to consist of a sequence of zero or more
  29. * text tokens separated by spans of one or more control chars. the first
  30. * call, with string specified, returns a pointer to the first wchar_t of
  31. * the first token, and will write a null wchar_t into string immediately
  32. * following the returned token. subsequent calls with zero for the first
  33. * argument (string) will work thru the string until no tokens remain. the
  34. * control string may be different from call to call. when no tokens remain
  35. * in string a NULL pointer is returned. remember the control chars with a
  36. * bit map, one bit per wchar_t. the null wchar_t is always a control char
  37. * (wide-characters).
  38. *
  39. *Entry:
  40. * wchar_t *string - wchar_t string to tokenize, or NULL to get next token
  41. * wchar_t *control - wchar_t string of characters to use as delimiters
  42. *
  43. *Exit:
  44. * returns pointer to first token in string, or if string
  45. * was NULL, to next token
  46. * returns NULL when no more tokens remain.
  47. *
  48. *Uses:
  49. *
  50. *Exceptions:
  51. *
  52. *******************************************************************************/
  53. wchar_t * __cdecl wcstok (
  54. wchar_t * string,
  55. const wchar_t * control
  56. )
  57. {
  58. COleTls TlsContext;
  59. wchar_t *token;
  60. const wchar_t *ctl;
  61. /* If string==NULL, continue with previous string */
  62. if (!string)
  63. string = (wchar_t *)TlsContext->pWcstokContext;
  64. /* Find beginning of token (skip over leading delimiters). Note that
  65. * there is no token iff this loop sets string to point to the terminal
  66. * null (*string == '\0') */
  67. while (*string) {
  68. for (ctl=control; *ctl && *ctl != *string; ctl++)
  69. ;
  70. if (!*ctl) break;
  71. string++;
  72. }
  73. token = string;
  74. /* Find the end of the token. If it is not the end of the string,
  75. * put a null there. */
  76. for ( ; *string ; string++ ) {
  77. for (ctl=control; *ctl && *ctl != *string; ctl++)
  78. ;
  79. if (*ctl) {
  80. *string++ = '\0';
  81. break;
  82. }
  83. }
  84. /* Update nextoken (or the corresponding field in the per-thread data
  85. * structure */
  86. TlsContext->pWcstokContext = string;
  87. /* Determine if a token has been found. */
  88. if ( token == string )
  89. return NULL;
  90. else
  91. return token;
  92. }