I am clearing a large C ++ code base where I need all the variables of type "vector" that need to be changed to "std :: vector". Skipping #include and comments in code. And most importantly, if the expression is already written as "std :: vector", do not convert it to "std :: std :: vector"
I.e:
#include <vector> vector<Foo> foolist; typedef vector<Foo> FooListType; std::vector<Foo> otherfoolist; int main() { // this vector is for iteration for (vector <Foo>::iterator itor = foo.begin...)
Converts to
#include <vector> std::vector<Foo> foolist; typedef std::vector<Foo> FooListType; std::vector<Foo> otherfoolist; int main() { // this vector is for iteration for (std::vector<Foo>::iterator itor = foo.begin...)
So far I have narrowed down to two sed commands
sed -r 's/vector\s{0,1}</std::vector</g' < codefile > tmpfile sed 's/std::std/std/' < tmpfile > codefile
The first sed matches the vector <and "vector <" and converts to either "std :: vector <".
The second sed captures the side effect of converting "std :: vector <" to "std :: std :: vector <".
How can I combine two different regular expression expressions so that I can have a single sed command that corrects the code correctly.
I tried reading online about lookahead and lookbehind, but my eyes start to burn.
source share