| 35 | } |
| 36 | |
| 37 | SubFile SubRipSubtitleFormat::decode(const QStringList &lines) const { |
| 38 | SubFile sf; |
| 39 | |
| 40 | QRegExp r1( |
| 41 | "^(\\d+)\\s+(\\d{2}):(\\d{2}):(\\d{2})\\,(\\d{3})\\s+\\-\\->\\s+(\\d{2}):" |
| 42 | "(\\d{2}):(\\d{2})\\,(\\d{3})(.*)"); |
| 43 | QRegExp r2( |
| 44 | "^(\\d{2}):(\\d{2}):(\\d{2})\\,(\\d{3})\\s+\\-\\->\\s+(\\d{2}):(\\d{2}):(" |
| 45 | "\\d{2})\\,(\\d{3})(.*)"); |
| 46 | QRegExp rNumLine("^\\d+"); |
| 47 | |
| 48 | QString tokensBuff = "", numsBuff; |
| 49 | SrtTimestamps tss; |
| 50 | |
| 51 | foreach (QString line, lines) { |
| 52 | if (r1.exactMatch(line)) { |
| 53 | if (!tokensBuff.isEmpty()) addEntry(sf.entries, tokensBuff, tss); |
| 54 | tss.h1 = r1.cap(2).toInt(); |
| 55 | tss.m1 = r1.cap(3).toInt(); |
| 56 | tss.s1 = r1.cap(4).toInt(); |
| 57 | tss.ms1 = r1.cap(5).toInt(); |
| 58 | tss.h2 = r1.cap(6).toInt(); |
| 59 | tss.m2 = r1.cap(7).toInt(); |
| 60 | tss.s2 = r1.cap(8).toInt(); |
| 61 | tss.ms2 = r1.cap(9).toInt(); |
| 62 | numsBuff.clear(); |
| 63 | } else if (r2.exactMatch(line)) { |
| 64 | if (!tokensBuff.isEmpty()) addEntry(sf.entries, tokensBuff, tss); |
| 65 | tss.h1 = r2.cap(1).toInt(); |
| 66 | tss.m1 = r2.cap(2).toInt(); |
| 67 | tss.s1 = r2.cap(3).toInt(); |
| 68 | tss.ms1 = r2.cap(4).toInt(); |
| 69 | tss.h2 = r2.cap(5).toInt(); |
| 70 | tss.m2 = r2.cap(6).toInt(); |
| 71 | tss.s2 = r2.cap(7).toInt(); |
| 72 | tss.ms2 = r2.cap(8).toInt(); |
| 73 | numsBuff.clear(); |
| 74 | } else if (rNumLine.exactMatch(line)) { |
| 75 | numsBuff += line + "\n"; |
| 76 | } else if (!line.trimmed().isEmpty()) { |
| 77 | if (!numsBuff.isEmpty()) { |
| 78 | tokensBuff += numsBuff; |
| 79 | numsBuff.clear(); |
| 80 | } |
| 81 | tokensBuff += line + "\n"; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | if (!tokensBuff.isEmpty()) addEntry(sf.entries, tokensBuff, tss); |
| 86 | |
| 87 | return sf; |
| 88 | } |
| 89 | |
| 90 | QStringList SubRipSubtitleFormat::encode(const SubFile &subFile) const { |
| 91 | QStringList lines; |
nothing calls this directly
no outgoing calls
no test coverage detected