diff --git a/mpeg/id3v2/frames/commentsframe.cpp b/mpeg/id3v2/frames/commentsframe.cpp index fcabbbc6..6abcb54e 100644 --- a/mpeg/id3v2/frames/commentsframe.cpp +++ b/mpeg/id3v2/frames/commentsframe.cpp @@ -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); diff --git a/toolkit/tbytevectorlist.cpp b/toolkit/tbytevectorlist.cpp index 3799f5e7..f2b2c128 100644 --- a/toolkit/tbytevectorlist.cpp +++ b/toolkit/tbytevectorlist.cpp @@ -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)); diff --git a/toolkit/tbytevectorlist.h b/toolkit/tbytevectorlist.h index ab5e2d62..13880a89 100644 --- a/toolkit/tbytevectorlist.h +++ b/toolkit/tbytevectorlist.h @@ -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;