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.

70 lines
1.5 KiB

  1. /*
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. */
  4. #include "sdppch.h"
  5. #include "sdpgen.h"
  6. // Isolates tokens by searching for one of the separators
  7. // and returns the first separator thats found
  8. CHAR *
  9. GetToken(
  10. IN CHAR *String,
  11. IN BYTE NumSeparators,
  12. IN const CHAR *SeparatorChars,
  13. OUT CHAR &Separator
  14. )
  15. {
  16. // validate the input parameters
  17. ASSERT(NULL != String);
  18. ASSERT(NULL != SeparatorChars);
  19. ASSERT(0 != NumSeparators);
  20. if ( (NULL == String) ||
  21. (NULL == SeparatorChars) ||
  22. (0 == NumSeparators) )
  23. {
  24. return NULL;
  25. }
  26. // advance character by character until the string ends or
  27. // one of the separators is found
  28. for ( UINT i=0; ; i++ )
  29. {
  30. // check each separator
  31. for ( UINT j=0; j < NumSeparators; j++ )
  32. {
  33. // if the separator matches the current string character
  34. if ( SeparatorChars[j] == String[i] )
  35. {
  36. // copy the separator character
  37. Separator = String[i];
  38. // terminate the token with an end of string character
  39. String[i] = EOS;
  40. // return the start of the token
  41. return String;
  42. }
  43. }
  44. // check if the end of string has been reached
  45. if ( EOS == String[i] )
  46. {
  47. return NULL;
  48. }
  49. }
  50. // should never reach here
  51. ASSERT(FALSE);
  52. return NULL;
  53. }