X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fcollect.h;fp=src%2Fcollect.h;h=ff43ce044bade20c7610322a23d2cc32b7d8eb92;hb=4ada3e7583dfdc658dbebca3c3603be1e3477c12;hp=62e872ff4ee757c78a3f826a0108fe2b7c4482a4;hpb=86440b2afe0a2b83a7e810f37b1f65dbddee90e8;p=libsub.git diff --git a/src/collect.h b/src/collect.h index 62e872f..ff43ce0 100644 --- a/src/collect.h +++ b/src/collect.h @@ -22,6 +22,39 @@ namespace sub { -std::list collect (std::list); +template +T +collect (std::list raw) +{ + raw.sort (); + + T out; + + boost::optional current; + for (std::list::const_iterator i = raw.begin (); i != raw.end(); ++i) { + if (current && current->same_metadata (*i)) { + /* This RawSubtitle can be added to current... */ + if (!current->lines.empty() && current->lines.back().same_metadata (*i)) { + /* ... and indeed to its last line */ + current->lines.back().blocks.push_back (Block (*i)); + } else { + /* ... as a new line */ + current->lines.push_back (Line (*i)); + } + } else { + /* We must start a new Subtitle */ + if (current) { + out.push_back (current.get ()); + } + current = Subtitle (*i); + } + } + + if (current) { + out.push_back (current.get ()); + } + + return out; +} }