MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / createFragment_

Method createFragment_

src/topp/GenericWrapper.cpp:194–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192
193
194 void createFragment_(String & fragment, const Param & param, const std::map<int, std::string>& optional_mappings = (std::map<int, std::string>()))
195 {
196
197 //std::cerr << "FRAGMENT: " << fragment << "\n\n";
198
199 // e.g.: -input %BASENAME[%%in].mzML
200
201 // we have to make this little detour param -> vector<String>
202 // to sort the param names by length, otherwise we have a
203 // problem with parameter substitution
204 // i.e., if A is a prefix of B and gets replaced first, the
205 // suffix of B remains and will cause trouble, e.g.: "%%out" vs. "%%out_fm"
206 vector<String> param_names;
207 param_names.reserve(param.size());
208 for (Param::ParamIterator it = param.begin(); it != param.end(); ++it)
209 {
210 param_names.push_back(it->name);
211 }
212 // sort by length
213 std::sort(param_names.begin(), param_names.end(), [](auto &left, auto &right) {StringSizeLess cmp; return cmp(right, left);});
214
215 // iterate through all input params and replace with values:
216 SignedSize allowed_percent(0); // filenames might contain '%', which are allowed to remain there (and even must remain)
217 for (vector<String>::iterator it = param_names.begin(); it != param_names.end(); ++it)
218 {
219 if (!fragment.hasSubstring("%%" + *it)) continue;
220
221 String s_new = paramToString_(param.getEntry(*it));
222 allowed_percent += s_new.length() - String(s_new).substitute("%", "").length();
223 //std::cerr << "IN: " << s_new << "(" << allowed_percent << "\n";
224 fragment.substitute("%%" + *it, s_new);
225 }
226 if (fragment.hasSubstring("%%"))
227 {
228 throw Exception::InvalidValue(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Invalid '%%' found in '" + fragment + "' after replacing all parameters!", fragment);
229 }
230 // mapping replace> e.g.: %2
231 // do it reverse, since %10 should precede %1
232 for (std::map<int, std::string>::const_reverse_iterator it = optional_mappings.rbegin(); it != optional_mappings.rend(); ++it)
233 {
234 String m = String("%") + it->first;
235 if (fragment.hasSubstring(m)) {
236 writeDebug_(String("Replacing '") + m + "' in '" + fragment + "' by '" + it->second + "'\n", 10);
237 fragment.substitute(m, it->second);
238 }
239 }
240
241 // %TMP replace:
242 fragment.substitute("%TMP", File::getTempDirectory());
243
244 // %RND replace:
245 fragment.substitute("%RND", String(UniqueIdGenerator::getUniqueId()));
246
247 // %WORKINGDIR replace:
248 fragment.substitute("%WORKINGDIR", tde_.working_directory);
249
250 // %DIR% replace
251 {

Callers

nothing calls this directly

Calls 13

sortFunction · 0.85
getUniqueIdFunction · 0.85
hasSubstringMethod · 0.80
StringClass · 0.50
reserveMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45
rbeginMethod · 0.45
rendMethod · 0.45
toQStringMethod · 0.45

Tested by

no test coverage detected