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.

127 lines
2.7 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // Microsoft Forms
  4. // Copyright: (c) 1994-1995, Microsoft Corporation
  5. // All rights Reserved.
  6. // Information contained herein is Proprietary and Confidential.
  7. //
  8. // File CSTR.HXX
  9. //
  10. // Contents Class definition for length prefix string class
  11. //
  12. // Classes CStr
  13. //
  14. // Stolen from Trident
  15. //
  16. //-----------------------------------------------------------------------------
  17. class ANSIString
  18. {
  19. public:
  20. ANSIString(WCHAR *pchWide);
  21. ~ANSIString() { delete _pch; }
  22. void Set(WCHAR *pchWide);
  23. operator LPSTR () const { return _pch; }
  24. private:
  25. char *_pch;
  26. };
  27. /*
  28. Use this macro to avoid initialization of embedded
  29. objects when parent object zeros out the memory
  30. */
  31. #define CSTR_NOINIT ((float)0.0)
  32. /*
  33. This class defines a length prefix 0 terminated string object. It points
  34. to the beginning of the characters so the pointer returned can be used in
  35. normal string operations taking into account that of course that it can
  36. contain any binary value.
  37. */
  38. class CStr
  39. {
  40. public:
  41. DECLARE_MEMALLOC_NEW_DELETE()
  42. /*
  43. Default constructor
  44. */
  45. CStr()
  46. {
  47. _pch = 0;
  48. }
  49. /*
  50. Special constructor to AVOID construction for embedded
  51. objects...
  52. */
  53. CStr(float num)
  54. {
  55. Assert(_pch == 0);
  56. }
  57. /*
  58. Destructor will free data
  59. */
  60. ~CStr()
  61. {
  62. _Free();
  63. }
  64. operator LPTSTR () const { return _pch; }
  65. HRESULT Set(LPCTSTR pch);
  66. HRESULT Set(LPCTSTR pch, UINT uc);
  67. HRESULT SetMultiByte(LPCSTR pch);
  68. HRESULT GetMultiByte(LPSTR pch, UINT cch);
  69. HRESULT SetBSTR(const BSTR bstr);
  70. HRESULT Set(const CStr &cstr);
  71. void TakeOwnership(CStr &cstr);
  72. UINT Length() const;
  73. // Update the internal length indication without changing any allocation.
  74. HRESULT SetLengthNoAlloc( UINT uc );
  75. // Reallocate the string to a larger size, length unchanged.
  76. HRESULT ReAlloc( UINT uc );
  77. HRESULT Append(LPCTSTR pch);
  78. HRESULT Append(LPCTSTR pch, UINT uc);
  79. HRESULT AppendMultiByte(LPCSTR pch);
  80. void Free()
  81. {
  82. _Free();
  83. _pch = 0;
  84. }
  85. TCHAR * TakePch() { TCHAR * pch = _pch; _pch = NULL; return(pch); }
  86. HRESULT AllocBSTR(BSTR *pBSTR) const;
  87. HRESULT TrimTrailingWhitespace();
  88. private:
  89. void _Free();
  90. LPTSTR _pch;
  91. NO_COPY(CStr);
  92. public:
  93. HRESULT Clone(CStr **ppCStr) const;
  94. BOOL Compare (const CStr *pCStr) const;
  95. WORD ComputeCrc() const;
  96. BOOL IsNull(void) const { return _pch == NULL ? TRUE : FALSE; }
  97. HRESULT Save(IStream * pstm) const;
  98. HRESULT Load(IStream * pstm);
  99. ULONG GetSaveSize() const;
  100. };