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.

90 lines
1.7 KiB

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