Advertisement
sebbu

stl cleaner

Jun 24th, 2011
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 5.39 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. while (<>)
  7. {
  8.     $\="\n";
  9.     s/^\s+//;
  10.     s/\s+$//;
  11.     my $count=0;
  12.     my $black="\e[1;30m",my $red="\e[1;31m",my $green="\e[1;32m",my $yellow="\e[1;33m",my $blue="\e[1;34m",my $magenta="\e[1;35m",my $cyan="\e[1;36m",my $white="\e[1;37m";
  13.     my $nc="\e[0m";
  14.     s#([a-zA-Z]:|)([^:]+):([0-9]+):([0-9]+):#$cyan$1$2$nc:$magenta$3$nc:$yellow$4$nc:#g;
  15.     # s#([^:]+): #$cyan$1$nc: #g;
  16.     my $safechar='a-zA-z0-9_-';
  17.     for ($count = 0; $count < 10; $count++) {
  18.         #print("iter n°", $count, "=", $_, "\n");
  19.         #string
  20.         s/std::basic_string<char, std::char_traits<char>, std::allocator<char> >\s*/std::string/g;
  21.         #set
  22.         s/std::set<(.+?), std::less<\1>, std::allocator<\1> >/std::set<$red$1$nc>/g;
  23.         s/std::set<(.+?), std::less<\1 >, std::allocator<\1 > >/std::set<$1 >/g;
  24.         #multiset
  25.         s/std::multiset<(.+?), std::less<\1>, std::allocator<\1> >/std::multiset<$red$1$nc>/g;
  26.         s/std::multiset<(.+?), std::less<\1 >, std::allocator<\1 > >/std::multiset<$1 >/g;
  27.         #vector
  28.         s/std::vector<(.+?), std::allocator<\1> >/std::vector<$red$1$nc>/g;
  29.         s/std::vector<(.+?), std::allocator<\1 > >/std::vector<$1 >/g;
  30.         #list
  31.         s/std::list<(.+?), std::allocator<\1> >/std::list<$red$1$nc>/g;
  32.         s/std::list<(.+?), std::allocator<\1 > >/std::list<$1 >/g;
  33.         #forward_list
  34.         s/std::forward_list<(.+?), std::allocator<\1> >/std::forward_list<$red$1$nc>/g;
  35.         s/std::forward_list<(.+?), std::allocator<\1 > >/std::forward_list<$1 >/g;
  36.         #deque
  37.         s/std::deque<(.+?), std::allocator<\1> >/std::deque<$red$1$nc>/g;
  38.         s/std::deque<(.+?), std::allocator<\1 > >/std::deque<$1 >/g;
  39.         #stack
  40.         s/std::stack<(.+?), std::deque<\1> >/std::stack<$red$1$nc>/g;
  41.         s/std::stack<(.+?), std::deque<\1 > >/std::stack<$1 >/g;
  42.         #queue
  43.         s/std::queue<(.+?), std::deque<\1> >/std::queue<$red$1$nc>/g;
  44.         s/std::queue<(.+?), std::deque<\1 > >/std::queue<$1 >/g;
  45.         #priority_queue
  46.         s/std::priority_queue<(.+?), std::deque<\1>, std::less<typename std::deque<\1>::value_type >/std::priority_queue<$red$1$nc>/g;
  47.         s/std::priority_queue<(.+?), std::deque<\1 >, std::less<typename std::deque<\1 >::value_type >/std::priority_queue<$1 >/g;
  48.         #priority_queue #without typename
  49.         s/std::priority_queue<(.+?), std::deque<\1>, std::less<std::deque<\1>::value_type >/std::priority_queue<$red$1$nc>/g;
  50.         s/std::priority_queue<(.+?), std::deque<\1 >, std::less<std::deque<\1 >::value_type >/std::priority_queue<$1 >/g;
  51.         #map
  52.         s/std::map<(.+?), (.+?), std::less<\1>, std::allocator<std::pair<const \1, \2> > >/std::map<$red$1$nc, $red$2$nc>/g;
  53.         s/std::map<(.+?), (.+?), std::less<\1 >, std::allocator<std::pair<const \1, \2 > > >/std::map<$1, $2 >/g;
  54.         #map #without const
  55.         s/std::map<(.+?), (.+?), std::less<\1>, std::allocator<std::pair<\1, \2> > >/std::map<$red$1$nc, $red$2$nc>/g;
  56.         s/std::map<(.+?), (.+?), std::less<\1 >, std::allocator<std::pair<\1, \2 > > >/std::map<$1, $2 >/g;
  57.         #unordored_set
  58.         s/std::unordored_set<(.+?), std::hash<\1>, std::equal_to<\1>, std::allocator<\1> >/std::unordored_set<$red$1$nc>/g;
  59.         s/std::unordored_set<(.+?), std::hash<\1 >, std::equal_to<\1 >, std::allocator<\1 > >/std::unordored_set<$1 >/g;
  60.         #unordored_multiset #probably error (second type ?)
  61.         s/std::unordored_multiset<(.+?), (.+?), std::hash<\1>, std::equal_to<\1>, std::allocator<\1> >/std::unordored_multiset<$red$1$nc, $red$2$nc>/g;
  62.         s/std::unordored_multiset<(.+?), (.+?), std::hash<\1 >, std::equal_to<\1 >, std::allocator<\1 > >/std::unordored_multiset<$1, $2 >/g;
  63.         #unordored_map
  64.         s/std::unordored_map<(.+?), (.+?), std::hash<\1>, std::equal_to<\1>, std::allocator<std::pair<const \1, \2> > >/std::unordored_map<$red$1$nc, $red$2$nc>/g;
  65.         s/std::unordored_map<(.+?), (.+?), std::hash<\1 >, std::equal_to<\1 >, std::allocator<std::pair<const \1, \2 > > >/std::unordored_map<$1, $2 >/g;
  66.         #unordored_map #without const
  67.         s/std::unordored_map<(.+?), (.+?), std::hash<\1>, std::equal_to<\1>, std::allocator<std::pair<\1, \2> > >/std::unordored_map<$red$1$nc, $red$2$nc>/g;
  68.         s/std::unordored_map<(.+?), (.+?), std::hash<\1 >, std::equal_to<\1 >, std::allocator<std::pair<\1, \2 > > >/std::unordored_map<$1, $2 >/g;
  69.         #unordored_multimap
  70.         s/std::unordored_multimap<(.+?), (.+?), std::hash<\1>, std::equal_to<\1>, std::allocator<std::pair<const \1, \2> > >/std::unordored_multimap<$red$1$nc, $red$2$nc>/g;
  71.         s/std::unordored_multimap<(.+?), (.+?), std::hash<\1 >, std::equal_to<\1 >, std::allocator<std::pair<const \1, \2 > > >/std::unordored_multimap<$1, $2 >/g;
  72.         #unordored_multimap #without const
  73.         s/std::unordored_multimap<(.+?), (.+?), std::hash<\1>, std::equal_to<\1>, std::allocator<std::pair<\1, \2> > >/std::unordored_multimap<$red$1$nc, $red$2$nc>/g;
  74.         s/std::unordored_multimap<(.+?), (.+?), std::hash<\1 >, std::equal_to<\1 >, std::allocator<std::pair<\1, \2 > > >/std::unordored_multimap<$1, $2 >/g;
  75.         #array
  76.         s/std::array<(.+?), ([0-9]+)>/std::array<$red$1$nc, $red$2$nc>/g;
  77.         #nothing needed for array (contains only class & size)
  78.        
  79.         #colorize native type
  80.         s/([^$safechar])unsigned(?=[^$safechar])/$1${red}unsigned$nc/g;
  81.         s/([^$safechar])long(?=[^$safechar])/$1${red}long$nc/g;
  82.         s/([^$safechar])int(?=[^$safechar])/$1${red}int$nc/g;
  83.         s/([^$safechar])short(?=[^$safechar])/$1${red}short$nc/g;
  84.         s/([^$safechar])char(?=[^$safechar])/$1${red}char$nc/g;
  85.         s/([^$safechar])double(?=[^$safechar])/$1${red}double$nc/g;
  86.         s/([^$safechar])float(?=[^$safechar])/$1${red}float$nc/g;
  87.         s/([^$safechar])void(?=[^$safechar])/$1${red}void$nc/g;
  88.     }
  89.     print;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement