WStringArray.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #pragma once
  2. #include <vector>
  3. #include "String.WString.hpp"
  4. #include "Iterator.tlh"
  5. //-----------------------------------------------------------------------------
  6. // WStringArray
  7. //-----------------------------------------------------------------------------
  8. class WStringArray : public std::vector <eSTR::WString>
  9. {
  10. using inherited = std::vector <eSTR::WString>;
  11. public:
  12. // using Iterator = Iterator <std::vector <WString>>;
  13. public:
  14. // Nothing different with Array <WString> but add some search functions
  15. // find string starting at left, -1 if not found
  16. int Find (const eSTR::WString & str) const
  17. {
  18. for (auto Iter = Iterator::From (*this); Iter; Iter++)
  19. {
  20. const auto & s = Iter ();
  21. if (s == str)
  22. return Iter.Index ();
  23. }
  24. return -1;
  25. }
  26. // find string starting at left, -1 if not found
  27. int NCFind (const eSTR::WString & str) const
  28. {
  29. for (auto Iter = Iterator::From (*this); Iter; Iter++)
  30. {
  31. const auto & s = Iter ();
  32. if (!s.CompareNoCase (str))
  33. return Iter.Index ();
  34. }
  35. return -1;
  36. }
  37. bool IsExist (const eSTR::WString & str) const
  38. {
  39. return (Find (str) >= 0);
  40. }
  41. bool IsEmpty () const
  42. {
  43. return empty ();
  44. }
  45. void Add (const eSTR::WString & str)
  46. {
  47. push_back (str);
  48. }
  49. void Add (eSTR::WString && str)
  50. {
  51. push_back (str);
  52. }
  53. int GetSize () const
  54. {
  55. return (int) size ();
  56. }
  57. void Reset ()
  58. {
  59. clear ();
  60. }
  61. int GetStringLength (void) const
  62. {
  63. int Length = 0;
  64. for (auto Iter = Iterator::From (*this); Iter; Iter++)
  65. {
  66. const auto & s = Iter ();
  67. Length += s.GetLength ();
  68. }
  69. return Length;
  70. }
  71. virtual eSTR::WString ToString (void) const
  72. {
  73. return ToString (eSTR::WStringView ());
  74. }
  75. virtual eSTR::WString ToString (CV_WString & sep) const
  76. {
  77. // ·µ»Ø×Ö·ûÊý
  78. int seplen = sep.Length ();
  79. int length = 0;
  80. for (auto Iter = Iterator::From (*this); Iter; Iter++)
  81. {
  82. const auto & s = Iter ();
  83. length += s.GetLength () + 2;
  84. length += seplen + 2;
  85. }
  86. eSTR::WString rc;
  87. rc.GetBuffer (length); // ×Ö·ûÊý
  88. for (auto Iter = Iterator::From (*this); Iter; Iter++)
  89. {
  90. const auto & s = Iter ();
  91. rc += s;
  92. rc += sep;
  93. }
  94. return rc;
  95. }
  96. WStringArray & operator << (const eSTR::WString & string)
  97. {
  98. Add (string);
  99. return (*this);
  100. }
  101. WStringArray & operator << (CV_WString & lpsz)
  102. {
  103. Add (lpsz);
  104. return (*this);
  105. }
  106. };