DStringArray.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /***************************************************************************
  2. * E-Com Technology Ltd.
  3. *
  4. * ECOMPACS DICOM Network Transport Libraries * Version 0.1 Beta
  5. ***************************************************************************/
  6. #ifndef _DICOM_DSTRING_ARRAY_
  7. #define _DICOM_DSTRING_ARRAY_
  8. class DStringArray : public Array <DString>
  9. {
  10. public:
  11. // Nothing different with Array <DString> but add some search functions
  12. // find string starting at left, -1 if not found
  13. int Find (const DString & str) const
  14. {
  15. ArrayIterator <DString> Iter (this);
  16. while (Iter)
  17. {
  18. DString & s = Iter ();
  19. if (s == str)
  20. return Iter.GetLastIndex ();
  21. }
  22. return -1;
  23. }
  24. // find character starting at right
  25. int ReverseFind (const DString & str) const
  26. {
  27. for (int Index=GetSize (); Index; Index--)
  28. {
  29. DString s = GetAt (Index-1);
  30. if (s == str)
  31. return Index-1;
  32. }
  33. return -1;
  34. }
  35. // find character starting at zero-based index and going right
  36. int Find (const DString & str, int nStart) const
  37. {
  38. if (nStart >= GetSize ())
  39. return -1;
  40. for (int Index = nStart; Index<GetSize (); Index++)
  41. {
  42. DString s = GetAt (Index);
  43. if (s == str)
  44. return Index;
  45. }
  46. return -1;
  47. }
  48. // find string starting at left, -1 if not found
  49. int NCFind (const DString & str) const
  50. {
  51. ArrayIterator <DString> Iter (this);
  52. while (Iter)
  53. {
  54. DString & s = Iter ();
  55. if (! s.CompareNoCase (str))
  56. return Iter.GetLastIndex ();
  57. }
  58. return -1;
  59. }
  60. // find character starting at right
  61. int NCReverseFind (const DString & str) const
  62. {
  63. for (int Index=GetSize (); Index; Index--)
  64. {
  65. DString s = GetAt (Index-1);
  66. if (! s.CompareNoCase (str))
  67. return Index-1;
  68. }
  69. return -1;
  70. }
  71. // find character starting at zero-based index and going right
  72. int NCFind (const DString & str, int nStart) const
  73. {
  74. if (nStart >= GetSize ())
  75. return -1;
  76. for (int Index = nStart; Index<GetSize (); Index++)
  77. {
  78. DString s = GetAt (Index);
  79. if (! s.CompareNoCase (str))
  80. return Index;
  81. }
  82. return -1;
  83. }
  84. int GetStringLength (void) const
  85. {
  86. int Length = 0;
  87. ArrayIterator <DString> Iter (this);
  88. while (Iter)
  89. {
  90. DString & str = Iter ();
  91. Length += str.GetLength ();
  92. }
  93. return Length;
  94. }
  95. virtual DString ToString (void) const
  96. {
  97. return ToString (NULL);
  98. }
  99. virtual DString ToString (const char * sep) const
  100. {
  101. int seplen = strlen (sep);
  102. int length = 0;
  103. for (Array <DString>::Iterator Iter (this); Iter; Iter++)
  104. {
  105. DString & str = Iter ();
  106. length += str.GetLength () + 2;
  107. if (sep)
  108. length += seplen + 2;
  109. }
  110. DString rc;
  111. rc.GetBuffer (length);
  112. for (Array <DString>::Iterator Iter (this); Iter; Iter++)
  113. {
  114. DString & str = Iter ();
  115. rc += str;
  116. if (sep)
  117. rc += sep;
  118. }
  119. return rc;
  120. }
  121. };
  122. #endif