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.

105 lines
2.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: tfc.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _CSTRING_H_
  11. #define _CSTRING_H_
  12. class CString
  13. {
  14. public:
  15. // empty constructor
  16. CString();
  17. // copy constructor
  18. CString(const CString& stringSrc);
  19. // from an ANSI string (converts to WCHAR)
  20. CString(LPCSTR lpsz);
  21. // from a UNICODE string (converts to WCHAR)
  22. CString(LPCWSTR lpsz);
  23. ~CString();
  24. private:
  25. // data members
  26. LPWSTR szData;
  27. DWORD dwDataLen;
  28. public:
  29. void Init();
  30. void Empty();
  31. BOOL IsEmpty() const;
  32. LPWSTR GetBuffer(DWORD x=0);
  33. DWORD GetLength() const;
  34. void ReleaseBuffer() {}
  35. bool IsZeroTerminated()
  36. {
  37. if(dwDataLen)
  38. {
  39. if(L'\0' == szData[dwDataLen/sizeof(WCHAR)-1])
  40. return true;
  41. }
  42. return false;
  43. }
  44. // warning: insertion strings cannot exceed MAX_PATH chars
  45. void Format(LPCWSTR lpszFormat, ...);
  46. BSTR AllocSysString() const;
  47. // resource helpers
  48. BOOL LoadString(UINT iRsc);
  49. BOOL FromWindow(HWND hWnd);
  50. BOOL ToWindow(HWND hWnd);
  51. void SetAt(int nIndex, WCHAR ch);
  52. // operators
  53. operator LPCWSTR ( ) const
  54. {
  55. if (szData)
  56. return (LPCWSTR)szData;
  57. else
  58. return (LPCWSTR)L"";
  59. }
  60. // test
  61. BOOL IsEqual(LPCWSTR sz);
  62. // assignmt
  63. const CString& operator=(const CString& stringSrc) ;
  64. // W
  65. const CString& operator=(LPCWSTR lpsz);
  66. const CString& operator=(LPWSTR lpsz);
  67. // A
  68. const CString& operator=(LPCSTR lpsz);
  69. const CString& operator=(LPSTR lpsz);
  70. // concat
  71. const CString& operator+=(LPCWSTR lpsz);
  72. const CString& operator+=(const CString& string);
  73. bool operator==(const CString& string) const { return 0==_wcsicmp(*this, string);}
  74. bool operator!=(const CString& string) const { return !operator==(string); }
  75. bool operator==(WCHAR const * pcwsz) const { return 0==_wcsicmp(*this, pcwsz);}
  76. bool operator!=(WCHAR const * pcwsz) const { return !operator==(pcwsz); }
  77. void Attach(LPWSTR pwszSrc);
  78. LPWSTR Detach() { LPWSTR pwszRet = szData; Init(); return pwszRet; }
  79. };
  80. #endif // #ifndef _CSTRING_H_