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.

131 lines
2.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: K K S T L . C P P
  7. //
  8. // Contents:
  9. //
  10. // Notes:
  11. //
  12. // Author: kumarp
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "kkstl.h"
  18. void FormatTString(IN OUT tstring& str, IN PCWSTR pszFormat, va_list arglist)
  19. {
  20. const c_dwMaxFormatBufferLen = 511;
  21. //since there is no way to determine the size of the string
  22. //after applying the format, we must assume some arbitrary size
  23. static WCHAR pszTemp[c_dwMaxFormatBufferLen+1];
  24. _vsnwprintf(pszTemp, c_dwMaxFormatBufferLen, pszFormat, arglist);
  25. str = pszTemp;
  26. }
  27. void FormatTString(IN OUT tstring& str, IN PCWSTR pszFormat, ...)
  28. {
  29. va_list arglist;
  30. va_start (arglist, pszFormat);
  31. FormatTString(str, pszFormat, arglist);
  32. va_end(arglist);
  33. }
  34. BOOL FIsInStringList(IN const TStringList& sl, IN tstring& str,
  35. OUT TStringListIter* pos)
  36. {
  37. return FIsInStringList(sl, str.c_str(), pos);
  38. }
  39. BOOL FIsInStringList(IN const TStringList& sl, IN PCWSTR psz,
  40. OUT TStringListIter* pos)
  41. {
  42. TStringListIter i=sl.begin();
  43. while (i != sl.end())
  44. {
  45. if (!_wcsicmp((*i)->c_str(), psz))
  46. {
  47. if (pos != NULL)
  48. *pos = i;
  49. return TRUE;
  50. }
  51. ++i;
  52. }
  53. return FALSE;
  54. }
  55. tstring* GetNthItem(IN TStringList& sl, IN DWORD dwIndex)
  56. {
  57. TStringListIter sli=sl.begin();
  58. DWORD i;
  59. for (i=0; i<dwIndex; ++i, ++sli)
  60. ;
  61. return *sli;
  62. }
  63. void EraseAndDeleteAll(IN TPtrList& ppl)
  64. {
  65. EraseAndDeleteAll(&ppl);
  66. }
  67. void EraseAndDeleteAll(IN TPtrList* ppl)
  68. {
  69. TPtrListIter i=ppl->begin();
  70. while (i != ppl->end())
  71. {
  72. delete *i++;
  73. }
  74. ppl->erase(ppl->begin(), ppl->end());
  75. }
  76. void EraseAndDeleteAll(IN TStringList& ppl)
  77. {
  78. EraseAndDeleteAll(&ppl);
  79. }
  80. void EraseAndDeleteAll(IN TStringList* ppl)
  81. {
  82. TStringListIter i=ppl->begin();
  83. while (i != ppl->end())
  84. {
  85. delete *i++;
  86. }
  87. ppl->erase(ppl->begin(), ppl->end());
  88. }
  89. void GetDataFromByteArray(IN const TByteArray& ba, OUT BYTE*& pb)
  90. {
  91. DWORD dwSize = ba.size();
  92. if (dwSize == 0)
  93. {
  94. pb = NULL;
  95. return;
  96. }
  97. if (pb == NULL)
  98. {
  99. pb = new BYTE[dwSize];
  100. }
  101. if(pb) {
  102. for (DWORD i=0; i < dwSize; i++)
  103. {
  104. pb[i] = ba[i];
  105. }
  106. }
  107. }