Finally took Tommi's suggestion here and introduced a version of the ByteVectorList...
authorScott Wheeler <wheeler@kde.org>
Sat, 23 Jul 2005 23:11:20 +0000 (23:11 +0000)
committerScott Wheeler <wheeler@kde.org>
Sat, 23 Jul 2005 23:11:20 +0000 (23:11 +0000)
that takes a maximum number of values.  This should probably be used more widely in
places where the max is known ahead of time for this to be a more useful fix than nailing
just this special case.  Anyway, fixes the bug.

BUG:103622

git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@438030 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

mpeg/id3v2/frames/commentsframe.cpp
toolkit/tbytevectorlist.cpp
toolkit/tbytevectorlist.h

index fcabbbc6c66a48329ee0b78ad1e752080e068af0..6abcb54ea59465f77ad0026c77d8e4ca02dfc218 100644 (file)
@@ -120,7 +120,7 @@ void CommentsFrame::parseFields(const ByteVector &data)
 
   int byteAlign = d->textEncoding == String::Latin1 || d->textEncoding == String::UTF8 ? 1 : 2;
 
-  ByteVectorList l = ByteVectorList::split(data.mid(4), textDelimiter(d->textEncoding), byteAlign);
+  ByteVectorList l = ByteVectorList::split(data.mid(4), textDelimiter(d->textEncoding), byteAlign, 2);
 
   if(l.size() == 2) {
     d->description = String(l.front(), d->textEncoding);
index 3799f5e7ae0febddbf5f9908bc4854b9837a5e2f..f2b2c128f61c85e094429b3dd0e86826f4723693 100644 (file)
@@ -34,12 +34,18 @@ class ByteVectorListPrivate
 
 ByteVectorList ByteVectorList::split(const ByteVector &v, const ByteVector &pattern,
                                      int byteAlign)
+{
+  return split(v, pattern, byteAlign, 0);
+}
+
+ByteVectorList ByteVectorList::split(const ByteVector &v, const ByteVector &pattern,
+                                     int byteAlign, int max)
 {
   ByteVectorList l;
 
   uint previousOffset = 0;
   for(int offset = v.find(pattern, 0, byteAlign);
-      offset != -1;
+      offset != -1 && (max == 0 || max > int(l.size()) + 1);
       offset = v.find(pattern, offset + pattern.size(), byteAlign))
   {
     l.append(v.mid(previousOffset, offset - previousOffset));
index ab5e2d625bb028292f2c43ad921fc4ec1ba053a1..13880a8984ce71e55477c1bbbb0b8d50e9121075 100644 (file)
@@ -66,7 +66,16 @@ namespace TagLib {
      */
     static ByteVectorList split(const ByteVector &v, const ByteVector &pattern,
                                 int byteAlign = 1);
-
+    /*!
+     * Splits the ByteVector \a v into several strings at \a pattern.  This will
+     * not include the pattern in the returned ByteVectors.  \a max is the
+     * maximum number of entries that will be separated.  If \a max for instance
+     * is 2 then a maximum of 1 match will be found and the vector will be split
+     * on that match.
+     */
+    // BIC: merge with the function above
+    static ByteVectorList split(const ByteVector &v, const ByteVector &pattern,
+                                int byteAlign, int max);
   private:
     class ByteVectorListPrivate;
     ByteVectorListPrivate *d;