Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <regex>
- #include <vector>
- #include <map>
- #include <string>
- #include <fstream>
- #include <algorithm>
- class TimeLabel
- {
- int h, m, s;
- public:
- TimeLabel (std::string l)
- {
- //hh:mm:ss
- //01:34:67
- h = std::stoi(l.substr(0, 2));
- m = std::stoi(l.substr(3, 2));
- s = std::stoi(l.substr(6, 2));
- }
- std::string getTime()
- {
- return (std::to_string(h).size() == 2 ? std::to_string(h) : "0" + std::to_string(h) ) + ":" +
- (std::to_string(m).size() == 2 ? std::to_string(m) : "0" + std::to_string(m) ) + ":" +
- (std::to_string(s).size() == 2 ? std::to_string(s) : "0" + std::to_string(s) );
- }
- std::string addSeconds(int sec)
- {
- s += sec;
- m += s/60;
- s %= 60;
- h += m/60;
- m %= 60;
- return this->getTime();
- }
- };
- int main()
- {
- std::string line;
- std::string subtitles_all, subtitles_all_copy;
- std::vector<std::string> matches;
- std::fstream file;
- file.open("23.txt", std::ios_base::in);
- while(std::getline(file, line))
- subtitles_all += line + "\n";
- subtitles_all_copy = subtitles_all;
- std::smatch m;
- while (std::regex_search (subtitles_all_copy, m, std::regex("[0-9]{2}:[0-9]{2}:[0-9]{2}")))
- {
- for (auto x : m)
- matches.push_back(x);
- subtitles_all_copy = m.suffix().str();
- }
- std::reverse(matches.begin(), matches.end());
- std::cout << "Podaj o ile sekund przesunac (o ile sekund pozniej maja pokazac sie napisy):\n>";
- int p;
- std::cin >> p;
- for(auto mat : matches)
- {
- TimeLabel tl(mat);
- subtitles_all = std::regex_replace(subtitles_all, std::regex(mat), tl.addSeconds(p));
- }
- file.close();
- file.open("23.txt", std::ios_base::out | std::ios_base::trunc);
- file << subtitles_all;
- file.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement