From b69dd382c670b2b71f26e732f69647f11de1f7bf Mon Sep 17 00:00:00 2001 From: Scott Wheeler Date: Wed, 9 Jun 2004 13:33:05 +0000 Subject: [PATCH] Add iterators and operator[] to the string class. git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@319064 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- toolkit/tstring.cpp | 30 ++++++++++++++++++++++++++++++ toolkit/tstring.h | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/toolkit/tstring.cpp b/toolkit/tstring.cpp index 0d6b3cce..fe0588d3 100644 --- a/toolkit/tstring.cpp +++ b/toolkit/tstring.cpp @@ -252,6 +252,26 @@ const char *String::toCString(bool unicode) const return d->CString; } +String::Iterator String::begin() +{ + return d->data.begin(); +} + +String::ConstIterator String::begin() const +{ + return d->data.begin(); +} + +String::Iterator String::end() +{ + return d->data.end(); +} + +String::ConstIterator String::end() const +{ + return d->data.end(); +} + int String::find(const String &s, int offset) const { wstring::size_type position = d->data.find(s.d->data, offset); @@ -433,6 +453,16 @@ String String::number(int n) // static return s; } +TagLib::wchar &String::operator[](int i) +{ + return d->data[i]; +} + +const TagLib::wchar &String::operator[](int i) const +{ + return d->data[i]; +} + bool String::operator==(const String &s) const { return d == s.d || d->data == s.d->data; diff --git a/toolkit/tstring.h b/toolkit/tstring.h index d1b92039..6ffd6563 100644 --- a/toolkit/tstring.h +++ b/toolkit/tstring.h @@ -63,6 +63,12 @@ namespace TagLib { class String { public: + +#ifndef DO_NOT_DOCUMENT + typedef std::basic_string::iterator Iterator; + typedef std::basic_string::const_iterator ConstIterator; +#endif + /** * The four types of string encodings supported by the ID3v2 specification. * ID3v1 is assumed to be Latin1 and Ogg Vorbis comments use UTF8. @@ -176,6 +182,28 @@ namespace TagLib { */ const char *toCString(bool unicode = false) const; + /*! + * Returns an iterator pointing to the beginning of the string. + */ + Iterator begin(); + + /*! + * Returns a const iterator pointing to the beginning of the string. + */ + ConstIterator begin() const; + + /*! + * Returns an iterator pointing to the end of the string (the position + * after the last character). + */ + Iterator end(); + + /*! + * Returns a const iterator pointing to the end of the string (the position + * after the last character). + */ + ConstIterator end() const; + /*! * Finds the first occurance of pattern \a s in this string starting from * \a offset. If the pattern is not found, -1 is returned. @@ -244,6 +272,16 @@ namespace TagLib { */ static String number(int n); + /*! + * Returns a reference to the character at position \a i. + */ + wchar &operator[](int i); + + /*! + * Returns a const reference to the character at position \a i. + */ + const wchar &operator[](int i) const; + /*! * Compares each character of the String with each character of \a s and * returns true if the strings match.