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.

145 lines
4.0 KiB

  1. /*****************************************************************************
  2. * (C) COPYRIGHT MICROSOFT CORPORATION, 2002
  3. *
  4. * AUTHOR: ByronC
  5. *
  6. * DATE: 4/22/2002
  7. *
  8. * @doc INTERNAL
  9. *
  10. * @module SimpleTokenReplacement.h - Definitions for <c SimpleTokenReplacement> |
  11. *
  12. * This file contains the class definition for <c SimpleTokenReplacement>.
  13. *
  14. *****************************************************************************/
  15. /*****************************************************************************
  16. *
  17. * @doc INTERNAL
  18. *
  19. * @class SimpleTokenReplacement | This class can do simple replacement of tokens in a string
  20. *
  21. * @comm
  22. * The <c SimpleTokenReplacement> class is similar to sprintf. Basically,
  23. * an input string contains tokens that represent other values, and these
  24. * values must be substituted for the tokens (e.g. in sprintf, %s
  25. * means that a string value will be put in place of the %s).
  26. *
  27. *****************************************************************************/
  28. class SimpleTokenReplacement
  29. {
  30. //@access Public members
  31. public:
  32. class TokenValueList;
  33. // @cmember Constructor
  34. SimpleTokenReplacement(const CSimpleString &csOriginalString);
  35. // @cmember Destructor
  36. virtual ~SimpleTokenReplacement();
  37. // @cmember Replaces the first instance of a given token in our string (starting from dwStartIndex) with the token value
  38. int ExpandTokenIntoString(const CSimpleString &csToken,
  39. const CSimpleString &csTokenValue,
  40. const DWORD dwStartIndex = 0);
  41. // @cmember Replaces all instances of all tokens in our string with the token value
  42. VOID ExpandArrayOfTokensIntoString(TokenValueList &ListOfTokenValuePairs);
  43. // @cmember Returns the resulting string
  44. CSimpleStringWide getString();
  45. class TokenValuePair
  46. {
  47. public:
  48. TokenValuePair(const CSimpleString &csToken, const CSimpleString &csValue) :
  49. m_csToken(csToken),
  50. m_csValue(csValue)
  51. {
  52. }
  53. virtual ~TokenValuePair()
  54. {
  55. }
  56. CSimpleString getToken()
  57. {
  58. return m_csToken;
  59. }
  60. CSimpleString getValue()
  61. {
  62. return m_csValue;
  63. }
  64. private:
  65. CSimpleString m_csToken;
  66. CSimpleString m_csValue;
  67. };
  68. class TokenValueList
  69. {
  70. public:
  71. TokenValueList()
  72. {
  73. }
  74. virtual ~TokenValueList()
  75. {
  76. for (m_Iter = m_ListOfTokenValuePairs.Begin(); m_Iter != m_ListOfTokenValuePairs.End(); ++m_Iter)
  77. {
  78. TokenValuePair *pTokenValuePair = *m_Iter;
  79. if (pTokenValuePair)
  80. {
  81. delete pTokenValuePair;
  82. }
  83. }
  84. m_ListOfTokenValuePairs.Destroy();
  85. }
  86. void Add(const CSimpleString &csToken, const CSimpleString &csValue)
  87. {
  88. TokenValuePair *pTokenValuePair = new TokenValuePair(csToken, csValue);
  89. if (pTokenValuePair)
  90. {
  91. m_ListOfTokenValuePairs.Prepend(pTokenValuePair);
  92. }
  93. }
  94. TokenValuePair* getFirst()
  95. {
  96. m_Iter = m_ListOfTokenValuePairs.Begin();
  97. if (m_Iter == m_ListOfTokenValuePairs.End())
  98. {
  99. return NULL;
  100. }
  101. else
  102. {
  103. return *m_Iter;
  104. }
  105. }
  106. TokenValuePair* getNext()
  107. {
  108. ++m_Iter;
  109. if (m_Iter == m_ListOfTokenValuePairs.End())
  110. {
  111. return NULL;
  112. }
  113. else
  114. {
  115. return *m_Iter;
  116. }
  117. }
  118. private:
  119. CSimpleLinkedList<TokenValuePair*>::Iterator m_Iter;
  120. CSimpleLinkedList<TokenValuePair*> m_ListOfTokenValuePairs;
  121. };
  122. //@access Private members
  123. private:
  124. CSimpleString m_csResult;
  125. };