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.

194 lines
6.2 KiB

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (c) 1992-2001 Microsoft Corporation, All Rights Reserved
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #ifndef _SNMPSTR_H_
  11. #define _SNMPSTR_H_
  12. #include "snmpstd.h"
  13. #include <tchar.h>
  14. struct CStringData
  15. {
  16. long nRefs; // reference count
  17. int nDataLength;
  18. int nAllocLength;
  19. // TCHAR data[nAllocLength]
  20. TCHAR* data()
  21. { return (TCHAR*)(this+1); }
  22. };
  23. class CString
  24. {
  25. public:
  26. // Constructors
  27. CString();
  28. CString(const CString& stringSrc);
  29. CString(TCHAR ch, int nRepeat = 1);
  30. CString(LPCSTR lpsz);
  31. CString(LPCWSTR lpsz);
  32. CString(LPCTSTR lpch, int nLength);
  33. CString(const unsigned char* psz);
  34. // Attributes & Operations
  35. // as an array of characters
  36. int GetLength() const;
  37. BOOL IsEmpty() const;
  38. void Empty(); // free up the data
  39. TCHAR GetAt(int nIndex) const; // 0 based
  40. TCHAR operator[](int nIndex) const; // same as GetAt
  41. void SetAt(int nIndex, TCHAR ch);
  42. operator LPCTSTR() const; // as a C string
  43. // overloaded assignment
  44. const CString& operator=(const CString& stringSrc);
  45. const CString& operator=(TCHAR ch);
  46. #ifdef _UNICODE
  47. const CString& operator=(char ch);
  48. #endif
  49. const CString& operator=(LPCSTR lpsz);
  50. const CString& operator=(LPCWSTR lpsz);
  51. const CString& operator=(const unsigned char* psz);
  52. // string concatenation
  53. const CString& operator+=(const CString& string);
  54. const CString& operator+=(TCHAR ch);
  55. #ifdef _UNICODE
  56. const CString& operator+=(char ch);
  57. #endif
  58. const CString& operator+=(LPCTSTR lpsz);
  59. friend CString AFXAPI operator+(const CString& string1,
  60. const CString& string2);
  61. friend CString AFXAPI operator+(const CString& string, TCHAR ch);
  62. friend CString AFXAPI operator+(TCHAR ch, const CString& string);
  63. #ifdef _UNICODE
  64. friend CString AFXAPI operator+(const CString& string, char ch);
  65. friend CString AFXAPI operator+(char ch, const CString& string);
  66. #endif
  67. friend CString AFXAPI operator+(const CString& string, LPCTSTR lpsz);
  68. friend CString AFXAPI operator+(LPCTSTR lpsz, const CString& string);
  69. // string comparison
  70. int Compare(LPCTSTR lpsz) const; // straight character
  71. int CompareNoCase(LPCTSTR lpsz) const; // ignore case
  72. int Collate(LPCTSTR lpsz) const; // NLS aware
  73. // simple sub-string extraction
  74. CString Mid(int nFirst, int nCount) const;
  75. CString Mid(int nFirst) const;
  76. CString Left(int nCount) const;
  77. CString Right(int nCount) const;
  78. CString SpanIncluding(LPCTSTR lpszCharSet) const;
  79. CString SpanExcluding(LPCTSTR lpszCharSet) const;
  80. // upper/lower/reverse conversion
  81. void MakeUpper();
  82. void MakeLower();
  83. void MakeReverse();
  84. // trimming whitespace (either side)
  85. void TrimRight();
  86. void TrimLeft();
  87. // searching (return starting index, or -1 if not found)
  88. // look for a single character match
  89. int Find(TCHAR ch) const; // like "C" strchr
  90. int ReverseFind(TCHAR ch) const;
  91. int FindOneOf(LPCTSTR lpszCharSet) const;
  92. // look for a specific sub-string
  93. int Find(LPCTSTR lpszSub) const; // like "C" strstr
  94. // simple formatting
  95. void AFX_CDECL Format(LPCTSTR lpszFormat, ...);
  96. #ifndef _MAC
  97. // formatting for localization (uses FormatMessage API)
  98. void AFX_CDECL FormatMessage(LPCTSTR lpszFormat, ...);
  99. #endif
  100. #ifndef _UNICODE
  101. // ANSI <-> OEM support (convert string in place)
  102. void AnsiToOem();
  103. void OemToAnsi();
  104. #endif
  105. // OLE BSTR support (use for OLE automation)
  106. BSTR AllocSysString() const;
  107. BSTR SetSysString(BSTR* pbstr) const;
  108. // Access to string implementation buffer as "C" character array
  109. LPTSTR GetBuffer(int nMinBufLength);
  110. void ReleaseBuffer(int nNewLength = -1);
  111. LPTSTR GetBufferSetLength(int nNewLength);
  112. void FreeExtra();
  113. // Use LockBuffer/UnlockBuffer to turn refcounting off
  114. LPTSTR LockBuffer();
  115. void UnlockBuffer();
  116. // Implementation
  117. public:
  118. ~CString();
  119. int GetAllocLength() const;
  120. protected:
  121. LPTSTR m_pchData; // pointer to ref counted string data
  122. // implementation helpers
  123. CStringData* GetData() const;
  124. void Init();
  125. void AllocCopy(CString& dest, int nCopyLen, int nCopyIndex, int nExtraLen) const;
  126. void AllocBuffer(int nLen);
  127. void AssignCopy(int nSrcLen, LPCTSTR lpszSrcData);
  128. void ConcatCopy(int nSrc1Len, LPCTSTR lpszSrc1Data, int nSrc2Len, LPCTSTR lpszSrc2Data);
  129. void ConcatInPlace(int nSrcLen, LPCTSTR lpszSrcData);
  130. void FormatV(LPCTSTR lpszFormat, va_list argList);
  131. void CopyBeforeWrite();
  132. void AllocBeforeWrite(int nLen);
  133. void Release();
  134. static void PASCAL Release(CStringData* pData);
  135. static int PASCAL SafeStrlen(LPCTSTR lpsz);
  136. };
  137. // Compare helpers
  138. bool AFXAPI operator==(const CString& s1, const CString& s2);
  139. bool AFXAPI operator==(const CString& s1, LPCTSTR s2);
  140. bool AFXAPI operator==(LPCTSTR s1, const CString& s2);
  141. bool AFXAPI operator!=(const CString& s1, const CString& s2);
  142. bool AFXAPI operator!=(const CString& s1, LPCTSTR s2);
  143. bool AFXAPI operator!=(LPCTSTR s1, const CString& s2);
  144. bool AFXAPI operator<(const CString& s1, const CString& s2);
  145. bool AFXAPI operator<(const CString& s1, LPCTSTR s2);
  146. bool AFXAPI operator<(LPCTSTR s1, const CString& s2);
  147. bool AFXAPI operator>(const CString& s1, const CString& s2);
  148. bool AFXAPI operator>(const CString& s1, LPCTSTR s2);
  149. bool AFXAPI operator>(LPCTSTR s1, const CString& s2);
  150. bool AFXAPI operator<=(const CString& s1, const CString& s2);
  151. bool AFXAPI operator<=(const CString& s1, LPCTSTR s2);
  152. bool AFXAPI operator<=(LPCTSTR s1, const CString& s2);
  153. bool AFXAPI operator>=(const CString& s1, const CString& s2);
  154. bool AFXAPI operator>=(const CString& s1, LPCTSTR s2);
  155. bool AFXAPI operator>=(LPCTSTR s1, const CString& s2);
  156. // conversion helpers
  157. int AFX_CDECL _wcstombsz(char* mbstr, const wchar_t* wcstr, size_t count);
  158. int AFX_CDECL _mbstowcsz(wchar_t* wcstr, const char* mbstr, size_t count);
  159. // Globals
  160. extern TCHAR afxChNil;
  161. const CString& AFXAPI AfxGetEmptyString();
  162. #define afxEmptyString AfxGetEmptyString()
  163. #endif