Changeset 13667
- Timestamp:
- 05/12/12 12:29:54 (13 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/tools.cc
r13221 r13667 11 11 12 12 #include <stdarg.h> 13 14 #include <boost/tokenizer.hpp> 13 15 14 16 using namespace std; … … 140 142 return rc; 141 143 } 144 145 // -------------------------------------------------------------------------- 146 // 147 //! Splits a string into a filename and command line arguments, like: 148 //! 149 //! file.txt arg1=argument1 arg2="argument 2" arg3="argument \"3\"" 150 //! 151 //! 'file.txt' will be returned on opt, the arguments will be returned in 152 //! the returned map. 153 //! 154 //! If the returned file name is empty, an error has occured: 155 //! If the map is also empty the file name was empty, if the map has 156 //! one entry then for this entry the euqal sign was missing. 157 //! 158 map<string,string> Tools::Split(string &opt) 159 { 160 using namespace boost; 161 typedef escaped_list_separator<char> separator; 162 163 const string data(opt); 164 165 const tokenizer<separator> tok(data, separator('\\', ' ', '\"')); 166 167 auto it=tok.begin(); 168 if (it==tok.end()) 169 { 170 opt = ""; 171 return map<string,string>(); 172 } 173 174 opt = *it++; 175 176 map<string,string> rc; 177 178 for (; it!=tok.end(); it++) 179 { 180 const size_t pos = it->find_first_of('='); 181 if (pos==string::npos) 182 { 183 opt = ""; 184 rc.clear(); 185 rc[*it] = ""; 186 return rc; 187 } 188 189 rc[it->substr(0, pos)] = it->substr(pos+1); 190 } 191 192 return rc; 193 } -
trunk/FACT++/src/tools.h
r13221 r13667 2 2 #define FACT_Tools 3 3 4 #include <map> 4 5 #include <string> 5 6 … … 11 12 std::string TrimQuotes(const std::string &str); 12 13 std::string Wrap(std::string &str, size_t width=78); 14 15 std::map<std::string,std::string> Split(std::string &); 13 16 } 14 17
Note:
See TracChangeset
for help on using the changeset viewer.