Created
September 14, 2017 14:14
-
-
Save itarato/05516838e119539db3e326174f3a3e8b to your computer and use it in GitHub Desktop.
Diff inverter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <sstream> | |
using namespace std; | |
int main(int argc, char* argv[]) { | |
ifstream file(argv[1]); | |
string s; | |
ostringstream sbuf; | |
bool is_collect = false; | |
while (getline(file, s)) { | |
if (s[0] == '-' && (s.size() == 1 || s[1] == ' ')) { | |
s[0] = '+'; | |
if (!is_collect) { | |
is_collect = true; | |
sbuf.str(""); | |
} | |
sbuf << s << endl; | |
} else if (s[0] == '+' && (s.size() == 1 || s[1] == ' ')) { | |
s[0] = '-'; | |
cout << s << endl; | |
} else { | |
if (is_collect) { | |
is_collect = false; | |
cout << sbuf.str(); | |
} | |
cout << s << endl; | |
} | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment