Leaked source code of windows server 2003
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.

101 lines
4.2 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // File: StringTokenizer.h
  4. // Copyright (C) 1997 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This file declares the CStringTokenizer class, which implements simple
  8. // linear tokenization of a String. The set of delimiters, which defaults
  9. // to common whitespace characters, may be specified at creation time or on a
  10. // per-token basis.
  11. // Example usage:
  12. // CString s = "a test string";
  13. // CStringTokenizer st = new CStringTokenizer(s);
  14. // while (st.hasMoreTokens())
  15. // {
  16. // cout << st.nextToken() << endl;
  17. // }
  18. //-----------------------------------------------------------------------------
  19. #pragma once
  20. #ifndef StringTokenizer_h
  21. #define StringTokenizer_h
  22. class LTAPIENTRY CStringTokenizer
  23. {
  24. public:
  25. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  26. // constructs a tokenizer with default delimiters
  27. //-----------------------------------------------------------------------------
  28. CStringTokenizer();
  29. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  30. // constructs a tokenizer with default delimiters
  31. // str - in, the string to be tokenized
  32. //-----------------------------------------------------------------------------
  33. CStringTokenizer(const WCHAR* str);
  34. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  35. // constructs a tokenizer
  36. // str - in, the string to be tokenized
  37. // delimiters - in, the delimiters; null terminated
  38. //-----------------------------------------------------------------------------
  39. CStringTokenizer(const WCHAR* str, const WCHAR* delimiters);
  40. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  41. // constructs a tokenizer
  42. // str - in, the string to be tokenized
  43. // delimiters - in, the delimiters; null terminated
  44. // returnTokens - in, TRUE indicates return delimiter as token
  45. //-----------------------------------------------------------------------------
  46. CStringTokenizer(const WCHAR* str,
  47. const WCHAR* delimiters,
  48. BOOL returnTokens);
  49. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  50. // destructs this tokenizer
  51. //-----------------------------------------------------------------------------
  52. virtual ~CStringTokenizer();
  53. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  54. // configure whether return delimiter as token
  55. // returnTokens - in, TRUE indicates return delimiter as token
  56. //-----------------------------------------------------------------------------
  57. void setReturnTokens(BOOL returnTokens);
  58. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  59. // sets delimiters
  60. // delimiters - in, the delimiters; null terminated
  61. //-----------------------------------------------------------------------------
  62. void setDelimiters(const WCHAR* delimiters);
  63. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  64. // parse a string to be tokenized
  65. // str - in, the null terminated string
  66. //-----------------------------------------------------------------------------
  67. void parse(const WCHAR* str);
  68. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  69. // checks whether there are more tokens
  70. //-----------------------------------------------------------------------------
  71. BOOL hasMoreTokens();
  72. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  73. // get next token
  74. // length - out, the length of the token
  75. // return the pointer to the begining of the token
  76. //-----------------------------------------------------------------------------
  77. const WCHAR* nextToken(unsigned int & length);
  78. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  79. // count total number of tokens
  80. //-----------------------------------------------------------------------------
  81. int countTokens();
  82. private:
  83. void skipDelimiters();
  84. int IsDelimiter(WCHAR ch) const;
  85. int m_currentPosition;
  86. int m_maxPosition;
  87. const WCHAR* m_str;
  88. WCHAR* m_delimiters;
  89. int m_lenDelimiters;
  90. BOOL m_retTokens;
  91. };
  92. #endif