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.

84 lines
2.3 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: DELIMSTR.H
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 5/4/1999
  12. *
  13. * DESCRIPTION: Simple string tokenizer class. Stores the strings parsed from
  14. * another string as an array of strings. Pass the legal delimiters
  15. * as the second argument to the second constructor. Whitespace is
  16. * preserved. To eliminate whitespace, use CSimpleStringBase::Trim()
  17. *
  18. *******************************************************************************/
  19. #ifndef __DELIMSTR_H_INCLUDED
  20. #define __DELIMSTR_H_INCLUDED
  21. #include "simarray.h"
  22. #include "simstr.h"
  23. #include "simtok.h"
  24. template <class T>
  25. class CDelimitedStringBase : public CSimpleDynamicArray<T>
  26. {
  27. private:
  28. T m_strOriginal;
  29. T m_strDelimiters;
  30. public:
  31. CDelimitedStringBase(void)
  32. {
  33. }
  34. CDelimitedStringBase( const T &strOriginal, const T &strDelimiters )
  35. : m_strOriginal(strOriginal),m_strDelimiters(strDelimiters)
  36. {
  37. Parse();
  38. }
  39. CDelimitedStringBase( const CDelimitedStringBase &other )
  40. : m_strOriginal(other.Original()),m_strDelimiters(other.Delimiters())
  41. {
  42. Parse();
  43. }
  44. CDelimitedStringBase &operator=( const CDelimitedStringBase &other )
  45. {
  46. if (this != &other)
  47. {
  48. m_strOriginal = other.Original();
  49. m_strDelimiters = other.Delimiters();
  50. Parse();
  51. }
  52. return *this;
  53. }
  54. T Original(void) const
  55. {
  56. return m_strOriginal;
  57. }
  58. T Delimiters(void) const
  59. {
  60. return m_strDelimiters;
  61. }
  62. void Parse(void)
  63. {
  64. Destroy();
  65. CSimpleStringToken<T> Token( m_strOriginal );
  66. while (true)
  67. {
  68. T strCurrToken = Token.Tokenize(m_strDelimiters);
  69. if (!strCurrToken.Length())
  70. break;
  71. Append(strCurrToken);
  72. }
  73. }
  74. };
  75. typedef CDelimitedStringBase<CSimpleStringWide> CDelimitedStringWide;
  76. typedef CDelimitedStringBase<CSimpleStringAnsi> CDelimitedStringAnsi;
  77. typedef CDelimitedStringBase<CSimpleString> CDelimitedString;
  78. #endif //__DELIMSTR_H_INCLUDED