]> granicus.if.org Git - taglib/commitdiff
Add iterators and operator[] to the string class.
authorScott Wheeler <wheeler@kde.org>
Wed, 9 Jun 2004 13:33:05 +0000 (13:33 +0000)
committerScott Wheeler <wheeler@kde.org>
Wed, 9 Jun 2004 13:33:05 +0000 (13:33 +0000)
git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@319064 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

toolkit/tstring.cpp
toolkit/tstring.h

index 0d6b3cce2b0cd87c9c6d08a18d19cf79378430b7..fe0588d3e8addd1c999c0b029704caa2d4e3c3cb 100644 (file)
@@ -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;
index d1b920393a979c92a1c14109fb99b4b36a0eb268..6ffd6563024565efc5ac58a7263c8a50157a957f 100644 (file)
@@ -63,6 +63,12 @@ namespace TagLib {
   class String
   {
   public:
+
+#ifndef DO_NOT_DOCUMENT
+    typedef std::basic_string<wchar>::iterator Iterator;
+    typedef std::basic_string<wchar>::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.