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.

79 lines
2.0 KiB

  1. /*++
  2. Copyright (C) 1992-2001 Microsoft Corporation
  3. Module Name:
  4. STRCORE2.CPP
  5. Abstract:
  6. History:
  7. --*/
  8. // This is a part of the Microsoft Foundation Classes C++ library.
  9. // Copyright (C) 1992-1993 Microsoft Corporation
  10. // All rights reserved.
  11. //
  12. // This source code is only intended as a supplement to the
  13. // Microsoft Foundation Classes Reference and Microsoft
  14. // QuickHelp and/or WinHelp documentation provided with the library.
  15. // See these sources for detailed information regarding the
  16. // Microsoft Foundation Classes product.
  17. #include "precomp.h"
  18. #define ASSERT(x)
  19. #define ASSERT_VALID(x)
  20. #define SafeStrlen strlen
  21. //////////////////////////////////////////////////////////////////////////////
  22. // concatenate in place
  23. void CString::ConcatInPlace(int nSrcLen, const char* pszSrcData)
  24. {
  25. // -- the main routine for += operators
  26. // if the buffer is too small, or we have a width mis-match, just
  27. // allocate a new buffer (slow but sure)
  28. if (m_nDataLength + nSrcLen > m_nAllocLength)
  29. {
  30. // we have to grow the buffer, use the Concat in place routine
  31. char* pszOldData = m_pchData;
  32. ConcatCopy(m_nDataLength, pszOldData, nSrcLen, pszSrcData);
  33. ASSERT(pszOldData != NULL);
  34. SafeDelete(pszOldData);
  35. }
  36. else
  37. {
  38. // fast concatenation when buffer big enough
  39. memcpy(&m_pchData[m_nDataLength], pszSrcData, nSrcLen);
  40. m_nDataLength += nSrcLen;
  41. }
  42. ASSERT(m_nDataLength <= m_nAllocLength);
  43. m_pchData[m_nDataLength] = '\0';
  44. }
  45. const CString& CString::operator +=(const char* psz)
  46. {
  47. ConcatInPlace(SafeStrlen(psz), psz);
  48. return *this;
  49. }
  50. const CString& CString::operator +=(char ch)
  51. {
  52. ConcatInPlace(1, &ch);
  53. return *this;
  54. }
  55. const CString& CString::operator +=(const CString& string)
  56. {
  57. ConcatInPlace(string.m_nDataLength, string.m_pchData);
  58. return *this;
  59. }
  60. ///////////////////////////////////////////////////////////////////////////////