Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef StringTokenizerH
00033 #define StringTokenizerH
00034
00035 #include <zeusbase/System/ZObject.h>
00036 #include <zeusbase/System/StringList.h>
00037
00038 BEGIN_NAMESPACE_Zeus
00039
00040
00041
00044
00045 zeusbase_class TStringTokenizer : public TZObject
00046 {
00047 public:
00048 TStringTokenizer(const IString& rData, const IString& rDelimiter , bool bRemoveEmptyTokens = false);
00049 TStringTokenizer(const IString& rData, const wchar_t* pwcDelimiter, bool bRemoveEmptyTokens = false);
00050
00051 virtual ~TStringTokenizer();
00052
00053 TString getNextToken() const;
00054 TString getToken(Int iTokenIndex) const;
00055 TString getFirstToken() const;
00056 TString getLastToken() const;
00057 void getTokens(IStringList& rList) const;
00058 Int getTokenCount() const;
00059 bool hasNextToken() const;
00060 bool hasToken(const IString& rToken) const;
00061 void removeEmptyTokens();
00062 void resetIterator();
00063 void setTokens(const IStringList& rList);
00064 TString toString() const;
00065 TString toString(TString strNewDelimiter) const;
00066 Retval removeTokens(Int iFirstIndex, Int iLastIndex);
00067 Retval removeToken(Int uiIndex);
00068 Retval removeFirstToken();
00069 Retval removeLastToken();
00070
00071 Retval getTokenIndex(const IString& strToken, Int& iIndex, bool bExactNotLike = true);
00072
00073 private:
00074 void tokenize(const IString& rData);
00075 void tokenizeWithoutEmptyTokens(const IString& rData);
00076 TString toString_internal(const IString& rDelimiter) const;
00077
00078 private:
00080 TStringList m_lstTokens;
00081
00083 const IStringListIterator* m_pListIterator;
00084
00086 TString m_strDelimiter;
00087 };
00088
00089
00090
00093
00094 inline TString TStringTokenizer::getNextToken() const
00095 {
00096 return m_pListIterator->getNextItem();
00097 }
00098
00099
00103
00104 inline TString TStringTokenizer::getFirstToken() const
00105 {
00106 return getToken(0);
00107 }
00108
00109
00113
00114 inline TString TStringTokenizer::getLastToken() const
00115 {
00116 return getToken(getTokenCount() - 1);
00117 }
00118
00119
00124
00125 inline TString TStringTokenizer::getToken(Int iTokenIndex) const
00126 {
00128
00129
00130
00131 if (iTokenIndex < getTokenCount())
00132 {
00133 return m_lstTokens.getItemConst(iTokenIndex);
00134 }
00135 else
00136 {
00137 return TString();
00138 }
00140 }
00141
00142
00147
00148 inline void TStringTokenizer::getTokens(IStringList& rList) const
00149 {
00150 m_lstTokens.copyToList(rList);
00151 }
00152
00153
00156
00157 inline Int TStringTokenizer::getTokenCount() const
00158 {
00159 return m_lstTokens.getCount();
00160 }
00161
00162
00165
00166 inline bool TStringTokenizer::hasNextToken() const
00167 {
00168 return m_pListIterator->hasNextItem();
00169 }
00170
00171
00174
00175 inline bool TStringTokenizer::hasToken(const IString& rToken) const
00176 {
00177 return m_lstTokens.hasItem(rToken);
00178 }
00179
00180
00183
00184 inline void TStringTokenizer::resetIterator()
00185 {
00186 m_pListIterator->reset();
00187 }
00188
00189
00194
00195 inline Retval TStringTokenizer::removeFirstToken()
00196 {
00197 return removeToken(0);
00198 }
00199
00200
00201
00205
00206 inline Retval TStringTokenizer::removeLastToken()
00207 {
00208 return removeToken(getTokenCount() - 1);
00209 }
00210
00211
00215
00216 inline void TStringTokenizer::setTokens(const IStringList& rList)
00217 {
00218 rList.copyToList(m_lstTokens);
00219 }
00220
00221
00225
00226 inline TString TStringTokenizer::toString() const
00227 {
00228 return toString_internal(m_strDelimiter);
00229 }
00230
00231
00236
00237 inline TString TStringTokenizer::toString(TString strNewDelimiter) const
00238 {
00239 return toString_internal(strNewDelimiter);
00240 }
00241
00242 END_NAMESPACE_Zeus
00243
00244 #endif
00245