123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- /***************************************************************************
- * E-Com Technology Ltd.
- *
- * ECOMPACS DICOM Network Transport Libraries * Version 0.1 Beta
- ***************************************************************************/
- #ifndef _DICOM_DSTRING_ARRAY_
- #define _DICOM_DSTRING_ARRAY_
- class DStringArray : public Array <DString>
- {
- public:
- // Nothing different with Array <DString> but add some search functions
- // find string starting at left, -1 if not found
- int Find (const DString & str) const
- {
- ArrayIterator <DString> Iter (this);
- while (Iter)
- {
- DString & s = Iter ();
- if (s == str)
- return Iter.GetLastIndex ();
- }
- return -1;
- }
- // find character starting at right
- int ReverseFind (const DString & str) const
- {
- for (int Index=GetSize (); Index; Index--)
- {
- DString s = GetAt (Index-1);
- if (s == str)
- return Index-1;
- }
- return -1;
- }
- // find character starting at zero-based index and going right
- int Find (const DString & str, int nStart) const
- {
- if (nStart >= GetSize ())
- return -1;
- for (int Index = nStart; Index<GetSize (); Index++)
- {
- DString s = GetAt (Index);
- if (s == str)
- return Index;
- }
- return -1;
- }
- // find string starting at left, -1 if not found
- int NCFind (const DString & str) const
- {
- ArrayIterator <DString> Iter (this);
- while (Iter)
- {
- DString & s = Iter ();
- if (! s.CompareNoCase (str))
- return Iter.GetLastIndex ();
- }
- return -1;
- }
- // find character starting at right
- int NCReverseFind (const DString & str) const
- {
- for (int Index=GetSize (); Index; Index--)
- {
- DString s = GetAt (Index-1);
- if (! s.CompareNoCase (str))
- return Index-1;
- }
- return -1;
- }
- // find character starting at zero-based index and going right
- int NCFind (const DString & str, int nStart) const
- {
- if (nStart >= GetSize ())
- return -1;
- for (int Index = nStart; Index<GetSize (); Index++)
- {
- DString s = GetAt (Index);
- if (! s.CompareNoCase (str))
- return Index;
- }
- return -1;
- }
- int GetStringLength (void) const
- {
- int Length = 0;
- ArrayIterator <DString> Iter (this);
- while (Iter)
- {
- DString & str = Iter ();
- Length += str.GetLength ();
- }
- return Length;
- }
- virtual DString ToString (void) const
- {
- return ToString (NULL);
- }
- virtual DString ToString (const char * sep) const
- {
- int seplen = strlen (sep);
- int length = 0;
- for (Array <DString>::Iterator Iter (this); Iter; Iter++)
- {
- DString & str = Iter ();
- length += str.GetLength () + 2;
- if (sep)
- length += seplen + 2;
- }
- DString rc;
- rc.GetBuffer (length);
- for (Array <DString>::Iterator Iter (this); Iter; Iter++)
- {
- DString & str = Iter ();
- rc += str;
- if (sep)
- rc += sep;
- }
- return rc;
- }
- };
- #endif
|