123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #pragma once
- #include <vector>
- #include "String.WString.hpp"
- #include "Iterator.tlh"
- //-----------------------------------------------------------------------------
- // WStringArray
- //-----------------------------------------------------------------------------
- class WStringArray : public std::vector <eSTR::WString>
- {
- using inherited = std::vector <eSTR::WString>;
- public:
- // using Iterator = Iterator <std::vector <WString>>;
- public:
- // Nothing different with Array <WString> but add some search functions
- // find string starting at left, -1 if not found
- int Find (const eSTR::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 eSTR::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 eSTR::WString & str) const
- {
- return (Find (str) >= 0);
- }
- bool IsEmpty () const
- {
- return empty ();
- }
- void Add (const eSTR::WString & str)
- {
- push_back (str);
- }
- void Add (eSTR::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 eSTR::WString ToString (void) const
- {
- return ToString (eSTR::WStringView ());
- }
- virtual eSTR::WString ToString (CV_WString & sep) const
- {
- // ·µ»Ø×Ö·ûÊý
- int seplen = sep.Length ();
- int length = 0;
- for (auto Iter = Iterator::From (*this); Iter; Iter++)
- {
- const auto & s = Iter ();
- length += s.GetLength () + 2;
- length += seplen + 2;
- }
- eSTR::WString rc;
- rc.GetBuffer (length); // ×Ö·ûÊý
- for (auto Iter = Iterator::From (*this); Iter; Iter++)
- {
- const auto & s = Iter ();
- rc += s;
- rc += sep;
- }
- return rc;
- }
- WStringArray & operator << (const eSTR::WString & string)
- {
- Add (string);
- return (*this);
- }
- WStringArray & operator << (CV_WString & lpsz)
- {
- Add (lpsz);
- return (*this);
- }
- };
|