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.

75 lines
2.3 KiB

  1. /*
  2. * Copyright 1998 American Power Conversion, All Rights Reserved
  3. *
  4. * NAME: tokenstr.h
  5. *
  6. * PATH:
  7. *
  8. * REVISION:
  9. *
  10. * DESCRIPTION:
  11. * This file contains the class definition for the TokenString class. It
  12. * is designed to replace the strtok() function, because when using strtok
  13. * "if multiple or simultaneous calls are made ... a high potential for data
  14. * corruption and innacurate results exists." -- MSVC OnLine Help
  15. *
  16. * REFERENCES:
  17. * Initially created by Todd Giaquinto
  18. *
  19. * NOTES:
  20. * This function mimics the behavior of strtok in all aspects.
  21. * Examples:
  22. * String: ,,,,1,2,3 Sep: , Tokens: "1" "2" "3"
  23. * String: ,#1#2,3#4 Sep: ,# Tokens: "1" "2" "3" "4"
  24. *
  25. * Typical Usage:
  26. * TokenString token_str(string, sep);
  27. * PCHAR tok = token_str.GetCurrentToken();
  28. * while (tok) {
  29. * .....
  30. * tok = token_str.GetCurrentToken();
  31. * }
  32. *
  33. * The GetCurrentToken call will return a pointer to the current string token
  34. * and then move the internal pointer to the start of the next token. If
  35. * GetCurrentToken is called without an argument, the separator string passed
  36. * to the constructor is used to gather each token. However, GetCurrentToken
  37. * is overloaded so that one implementation can take a new separator string
  38. * as an argument. Once a new separator string is passed in, all subsequent
  39. * calls to the parameter-less GetCurrentToken will use the last passed in
  40. * separator.
  41. *
  42. * REVISIONS:
  43. * tjg19Jan98: Initial implementation
  44. * tjg29Jan98: Included formal code review comments
  45. */
  46. #ifndef __TOKENSTR_H
  47. #define __TOKENSTR_H
  48. #include "cdefine.h"
  49. #include "apcobj.h"
  50. class TokenString {
  51. private:
  52. PCHAR theString;
  53. PCHAR theSeparators;
  54. PCHAR theCurrentLocation;
  55. INT theSeparatorLength;
  56. VOID storeSeparatorString(PCHAR aString);
  57. BOOL isSeparator(CHAR aCharacter);
  58. // Declare a private copy constructor and operator = so
  59. // that any would-be users will get compilation errors
  60. TokenString(const TokenString &anExistingTokenString);
  61. TokenString& operator = (const TokenString &anExistingTokenString);
  62. public:
  63. TokenString(PCHAR aString, PCHAR aSeparatorString = NULL);
  64. virtual ~TokenString();
  65. PCHAR GetCurrentToken();
  66. PCHAR GetCurrentToken(PCHAR aSeparatorString);
  67. };
  68. #endif