Source code of Windows XP (NT5)
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.

85 lines
1.6 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "dblnul.h"
  4. //
  5. // Use of Zero-initialized memory keeps us from having to add nul terminators.
  6. //
  7. bool
  8. DblNulTermList::AddString(
  9. LPCTSTR psz, // String to copy.
  10. int cch // Length of psz in chars (excl nul term).
  11. )
  12. {
  13. while((m_cchAlloc - m_cchUsed) < (cch + 2))
  14. {
  15. if (!Grow())
  16. return false;
  17. }
  18. DBGASSERT((NULL != m_psz));
  19. if (NULL != m_psz)
  20. {
  21. lstrcpy(m_psz + m_cchUsed, psz);
  22. m_cchUsed += cch + 1;
  23. m_cStrings++;
  24. return true;
  25. }
  26. return false;
  27. }
  28. bool
  29. DblNulTermList::Grow(
  30. void
  31. )
  32. {
  33. DBGASSERT((NULL != m_psz));
  34. DBGASSERT((m_cchGrow > 0));
  35. int cb = (m_cchAlloc + m_cchGrow) * sizeof(TCHAR);
  36. LPTSTR p = new TCHAR[cb];
  37. if (NULL != p)
  38. {
  39. ZeroMemory(p, cb);
  40. if (NULL != m_psz)
  41. {
  42. CopyMemory(p, m_psz, m_cchUsed * sizeof(TCHAR));
  43. delete[] m_psz;
  44. }
  45. m_psz = p;
  46. m_cchAlloc += m_cchGrow;
  47. }
  48. return NULL != m_psz;
  49. }
  50. #if DBG
  51. void
  52. DblNulTermList::Dump(
  53. void
  54. ) const
  55. {
  56. DBGERROR((TEXT("Dumping nul term list iter -------------")));
  57. DblNulTermListIter iter = CreateIterator();
  58. LPCTSTR psz;
  59. while(iter.Next(&psz))
  60. DBGERROR((TEXT("%s"), psz ? psz : TEXT("<null>")));
  61. }
  62. #endif
  63. bool
  64. DblNulTermListIter::Next(
  65. LPCTSTR *ppszItem
  66. )
  67. {
  68. if (*m_pszCurrent)
  69. {
  70. *ppszItem = m_pszCurrent;
  71. m_pszCurrent += lstrlen(m_pszCurrent) + 1;
  72. return true;
  73. }
  74. return false;
  75. }