#pragma once #include #include "WString.hpp" #include "Iterator.tlh" //----------------------------------------------------------------------------- // WStringArray //----------------------------------------------------------------------------- class WStringArray : public std::vector { using inherited = std::vector ; public: // using Iterator = Iterator >; public: // Nothing different with Array but add some search functions // find string starting at left, -1 if not found int Find (const WString & str) const { for (auto Iter = Iterator::From (*this); Iter; Iter++) { const auto & s = Iter (); if (s == str) return Iter.Index (); } return -1; } // find string starting at left, -1 if not found int NCFind (const WString & str) const { for (auto Iter = Iterator::From (*this); Iter; Iter++) { const auto & s = Iter (); if (!s.CompareNoCase (str)) return Iter.Index (); } return -1; } bool IsExist (const WString & str) const { return (Find (str) >= 0); } bool IsEmpty () const { return empty (); } void Add (const WString & str) { push_back (str); } void Add (WString && str) { push_back (str); } int GetSize () const { return (int) size (); } void Reset () { clear (); } int GetStringLength (void) const { int Length = 0; for (auto Iter = Iterator::From (*this); Iter; Iter++) { const auto & s = Iter (); Length += s.GetLength (); } return Length; } virtual WString ToString (void) const { return ToString (NULL); } virtual WString ToString (const char * sep) const { int seplen = (int) strlen (sep); int length = 0; for (auto Iter = Iterator::From (*this); Iter; Iter++) { const auto & s = Iter (); length += s.GetLength () + 2; if (sep) length += seplen + 2; } WString rc; rc.GetBuffer (length); for (auto Iter = Iterator::From (*this); Iter; Iter++) { const auto & s = Iter (); rc += s; if (sep) rc += sep; } return rc; } };