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.

87 lines
1.7 KiB

  1. // Str.cpp: implementation of the CStr class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "Str.h"
  5. //////////////////////////////////////////////////////////////////////
  6. // Construction/Destruction
  7. //////////////////////////////////////////////////////////////////////
  8. bool operator==(const CStr& s1, const CStr& s2)
  9. {
  10. if ((s1.IsEmpty() == true) && (s2.IsEmpty() == true))
  11. return true;
  12. if (s1.IsEmpty() != s2.IsEmpty())
  13. return false;
  14. return (MYSTRCMP(s1, s2) == 0);
  15. }
  16. bool operator==(const CStr& s1, LPCTSTR s2) {return s1 == CStr(s2);}
  17. bool operator==(LPCTSTR s1, const CStr& s2) {return CStr(s1) == s2;}
  18. void CStr::SplitString(CStr &first, CStr &last, TCHAR separator)
  19. {
  20. for (int i=0; get()[i] != NULL; i++)
  21. {
  22. if (get()[i] == separator)
  23. break;
  24. }
  25. if (get()[i] == separator)
  26. {
  27. last = (LPCTSTR)(get()+i+1);
  28. }
  29. else
  30. {
  31. last = CStr(); //a null string, since there is no
  32. //separator char
  33. }
  34. first = GetCopy();
  35. first.get()[i] = NULL;
  36. }
  37. CStr CStr::GetCopy()
  38. {
  39. CStr temp((LPCTSTR)*this);
  40. return temp;
  41. }
  42. void CStr::UseBuffer(TCHAR *buf)
  43. {
  44. release();
  45. itsCounter = new counter(buf);
  46. }
  47. bool CStr::IsPrefix(LPCTSTR str)
  48. {
  49. TCHAR* p1 = get();
  50. TCHAR* p2 = (TCHAR*)str;
  51. while ((*p1 == *p2) && (*p1 != NULL))
  52. {
  53. p1++;
  54. p2++;
  55. }
  56. return (*p2 == NULL);
  57. }
  58. void CStr::OverideBuffer(TCHAR *buf)
  59. {
  60. if (itsCounter) {
  61. if (--itsCounter->count == 0) {
  62. // delete [] itsCounter->ptr;
  63. delete itsCounter;
  64. }
  65. itsCounter = 0;
  66. }
  67. itsCounter = new counter(buf);
  68. }