Process regex string only when dirty
| 78 | |
| 79 | // Process regex string only when dirty |
| 80 | void Caption::process_regex() { |
| 81 | if (is_dirty) { |
| 82 | is_dirty = false; |
| 83 | |
| 84 | // Clear existing matches |
| 85 | matchedCaptions.clear(); |
| 86 | |
| 87 | QString caption_prepared = QString(caption_text.c_str()); |
| 88 | if (caption_prepared.endsWith("\n\n") == false) { |
| 89 | // We need a couple line ends at the end of the caption string (for our regex to work correctly) |
| 90 | caption_prepared.append("\n\n"); |
| 91 | } |
| 92 | |
| 93 | // Parse regex and find all matches (i.e. 00:00.000 --> 00:10.000\ncaption-text) |
| 94 | QRegularExpression allPathsRegex(QStringLiteral("(\\d{2})?:*(\\d{2}):(\\d{2}).(\\d{2,3})\\s*-->\\s*(\\d{2})?:*(\\d{2}):(\\d{2}).(\\d{2,3})([\\s\\S]*?)(.*?)(?=\\d{2}:\\d{2,3}|\\Z)"), QRegularExpression::MultilineOption); |
| 95 | QRegularExpressionMatchIterator i = allPathsRegex.globalMatch(caption_prepared); |
| 96 | while (i.hasNext()) { |
| 97 | QRegularExpressionMatch match = i.next(); |
| 98 | if (match.hasMatch()) { |
| 99 | // Push all match objects into a vector (so we can reverse them later) |
| 100 | matchedCaptions.push_back(match); |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // This method is required for all derived classes of EffectBase, and returns a |
| 107 | // modified openshot::Frame object |