123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- #pragma once
- #include <vector>
- #include "String.DString.hpp"
- #include "Iterator.tlh"
- #include "ReverseIterator.tlh"
- //-----------------------------------------------------------------------------
- // DStringArray
- // Nothing different with Array <DString> but add some search functions
- //-----------------------------------------------------------------------------
- class DStringArray : public std::vector <eSTR::DString>
- {
- using inherited = std::vector <eSTR::DString>;
- public:
- // using Iterator = Iterator <std::vector <DString>>;
- DStringArray () = default;
- DStringArray (const DStringArray &) = default;
- DStringArray (DStringArray && ) = default;
- DStringArray & operator = (const DStringArray &) = default;
- DStringArray & operator = (DStringArray &&) = default;
- public:
- // find string starting at left, -1 if not found
- int Find (const eSTR::DString & 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::DString & str) const
- {
- for (auto Iter = Iterator::From (*this); Iter; Iter++)
- {
- const auto & s = Iter ();
- if (!s.CompareNoCase (str))
- return Iter.Index ();
- }
- return -1;
- }
- int ReverseFind (const eSTR::DString & str) const
- {
- for (auto Iter = ReverseIterator::From (*this); Iter; Iter++)
- {
- const auto & s = Iter ();
- if (s == str)
- return Iter.Index ();
- }
- return -1;
- }
- bool IsExist (const eSTR::DString & str) const
- {
- return (Find (str) >= 0);
- }
- bool IsEmpty () const
- {
- return empty ();
- }
- void Add (const eSTR::DString & str)
- {
- push_back (str);
- }
- void Add (eSTR::DString && str)
- {
- push_back (std::move (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::DString ToString (void) const
- {
- return ToString (eSTR::StringView ());
- }
- virtual eSTR::DString ToString (CV_String & 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::DString rc;
- rc.GetBuffer (length);
- for (auto Iter = Iterator::From (*this); Iter; Iter++)
- {
- const auto & s = Iter ();
- rc += s;
- if (Iter.Index () < this->size () - 1)
- rc += sep;
- }
- return rc;
- }
- DStringArray & operator << (const eSTR::DString & string)
- {
- Add (string);
- return (*this);
- }
- DStringArray & operator << (CV_String & lpsz)
- {
- Add (eSTR::DString (lpsz));
- return (*this);
- }
- };
|