Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <string>
00029 #include <vector>
00030 #include <boost/algorithm/string.hpp>
00031 #include <boost/tr1/unordered_set.hpp>
00032
00033 #include "utils.h"
00034
00035 namespace rospack
00036 {
00037
00038 void
00039 deduplicate_tokens(const std::string& instring,
00040 bool last,
00041 std::string& outstring)
00042 {
00043 std::vector<std::string> vec;
00044 std::tr1::unordered_set<std::string> set;
00045 boost::split(vec, instring,
00046 boost::is_any_of("\t "),
00047 boost::token_compress_on);
00048 if(last)
00049 std::reverse(vec.begin(), vec.end());
00050 std::vector<std::string> vec_out;
00051 for(std::vector<std::string>::const_iterator it = vec.begin();
00052 it != vec.end();
00053 ++it)
00054 {
00055 if(set.find(*it) == set.end())
00056 {
00057 vec_out.push_back(*it);
00058 set.insert(*it);
00059 }
00060 }
00061 if(last)
00062 std::reverse(vec_out.begin(), vec_out.end());
00063 for(std::vector<std::string>::const_iterator it = vec_out.begin();
00064 it != vec_out.end();
00065 ++it)
00066 {
00067 if(it == vec_out.begin())
00068 outstring.append(*it);
00069 else
00070 outstring.append(std::string(" ") + *it);
00071 }
00072 }
00073
00074 void
00075 parse_compiler_flags(const std::string& instring,
00076 const std::string& token,
00077 bool select,
00078 bool last,
00079 std::string& outstring)
00080 {
00081 std::string intermediate;
00082 std::vector<std::string> result_vec;
00083 boost::split(result_vec, instring,
00084 boost::is_any_of("\t "),
00085 boost::token_compress_on);
00086 for(std::vector<std::string>::const_iterator it = result_vec.begin();
00087 it != result_vec.end();
00088 ++it)
00089 {
00090
00091 if(it->size() > token.size() && it->substr(0,token.size()) == token)
00092 {
00093 if(select)
00094 {
00095 if(intermediate.size())
00096 intermediate.append(" ");
00097 intermediate.append(it->substr(token.size()));
00098 }
00099 }
00100
00101 else if((*it) == token)
00102 {
00103 std::vector<std::string>::const_iterator iit = it;
00104 if(++iit != result_vec.end())
00105 {
00106 if(it->size() >= token.size() && it->substr(0,token.size()) == token)
00107 {
00108
00109 }
00110 else
00111 {
00112 if(select)
00113 {
00114 if(intermediate.size())
00115 intermediate.append(" ");
00116 intermediate.append((*iit));
00117 }
00118 it = iit;
00119 }
00120 }
00121 }
00122
00123 else if(it->size() > 2 &&
00124 (*it)[0] == '/' &&
00125 it->substr(it->size()-2) == ".a")
00126 {
00127 if(select)
00128 {
00129 if(intermediate.size())
00130 intermediate.append(" ");
00131 intermediate.append((*it));
00132 }
00133 }
00134 else if(!select)
00135 {
00136 if(intermediate.size())
00137 intermediate.append(" ");
00138 intermediate.append((*it));
00139 }
00140 }
00141 if(select)
00142 deduplicate_tokens(intermediate, last, outstring);
00143 else
00144 outstring = intermediate;
00145 }
00146
00147 }
00148