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.

92 lines
2.0 KiB

  1. // Str.h: interface for the CStr class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_STR_H__A4F6F853_1CB0_4AE5_A195_25F1AC01E6CA__INCLUDED_)
  5. #define AFX_STR_H__A4F6F853_1CB0_4AE5_A195_25F1AC01E6CA__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. #include "precomp.h"
  10. #include "counted_ptr.h"
  11. //////////////////////////////////////////////////////////////////////
  12. /*
  13. struct sBinaryData
  14. {
  15. sBinaryData(DWORD count, LPBYTE BinData)
  16. :m_Count(count), m_pData(BinData) {}
  17. DWORD m_Count;
  18. LPBYTE m_pData;
  19. };
  20. class CBinaryData : public counted_ptr<sBinaryData>
  21. {};
  22. */
  23. //////////////////////////////////////////////////////////////////////
  24. #define MYSTRLEN(x) _tcsclen(x)
  25. #define MYSTRCPY(x,y) _tcscpy(x,y)
  26. #define MYSTRCMP(x,y) _tcscmp(x,y)
  27. class CStr : protected counted_ptrA<TCHAR>
  28. {
  29. public:
  30. void OverideBuffer(TCHAR* buf);
  31. bool IsPrefix(LPCTSTR str);
  32. void UseBuffer(TCHAR* buf);
  33. CStr(const TCHAR* str=NULL)
  34. {
  35. if (str != NULL)
  36. {
  37. int len = MYSTRLEN(str) + 1;
  38. TCHAR* temp = new TCHAR[len];
  39. MYSTRCPY(temp, str);
  40. itsCounter = new counter(temp);
  41. }
  42. }
  43. void SplitString(CStr& first, CStr& last, TCHAR separator);
  44. bool IsEmpty() const {return (itsCounter == 0);}
  45. operator LPCTSTR() const
  46. {return get();}
  47. void operator +=(const CStr& str)
  48. {
  49. int len1 = IsEmpty() ? 0 : MYSTRLEN(get());
  50. int len2 = str.IsEmpty() ? 0 : MYSTRLEN(str.get());
  51. if ((len1 + len2) == 0)
  52. return;
  53. TCHAR* temp=new TCHAR[len1+len2+1];
  54. if (len1) MYSTRCPY(temp, get());
  55. if (len2) MYSTRCPY(temp+len1, str.get());
  56. release();
  57. itsCounter = new counter(temp);
  58. }
  59. friend bool operator==(const CStr& s1, const CStr& s2);
  60. friend bool operator==(const CStr& s1, LPCTSTR s2);
  61. friend bool operator==(LPCTSTR s1, const CStr& s2);
  62. protected:
  63. CStr GetCopy();
  64. };
  65. #endif // !defined(AFX_STR_H__A4F6F853_1CB0_4AE5_A195_25F1AC01E6CA__INCLUDED_)