Mercurial > hg > orthanc
comparison Core/Toolbox.cpp @ 2920:ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 07 Nov 2018 11:13:30 +0100 |
parents | 0204af4ece6a |
children | 0a4428aad512 |
comparison
equal
deleted
inserted
replaced
2919:2ca9cd064b15 | 2920:ad0e7def3338 |
---|---|
1488 char s[37]; | 1488 char s[37]; |
1489 uuid_unparse ( uuid, s ); | 1489 uuid_unparse ( uuid, s ); |
1490 #endif | 1490 #endif |
1491 return s; | 1491 return s; |
1492 } | 1492 } |
1493 | |
1494 | |
1495 namespace | |
1496 { | |
1497 // Anonymous namespace to avoid clashes between compilation modules | |
1498 | |
1499 class VariableFormatter | |
1500 { | |
1501 public: | |
1502 typedef std::map<std::string, std::string> Dictionary; | |
1503 | |
1504 private: | |
1505 const Dictionary& dictionary_; | |
1506 | |
1507 public: | |
1508 VariableFormatter(const Dictionary& dictionary) : | |
1509 dictionary_(dictionary) | |
1510 { | |
1511 } | |
1512 | |
1513 template<typename Out> | |
1514 Out operator()(const boost::smatch& what, | |
1515 Out out) const | |
1516 { | |
1517 Dictionary::const_iterator found = dictionary_.find(what[1]); | |
1518 | |
1519 if (found != dictionary_.end()) | |
1520 { | |
1521 const std::string& value = found->second; | |
1522 out = std::copy(value.begin(), value.end(), out); | |
1523 } | |
1524 | |
1525 return out; | |
1526 } | |
1527 }; | |
1528 } | |
1529 | |
1530 | |
1531 std::string Toolbox::SubstituteVariables(const std::string& source, | |
1532 const std::map<std::string, std::string>& dictionary) | |
1533 { | |
1534 const boost::regex pattern("\\${(.*?)}"); | |
1535 | |
1536 VariableFormatter formatter(dictionary); | |
1537 | |
1538 return boost::regex_replace(source, pattern, formatter); | |
1539 } | |
1493 } | 1540 } |
1494 | 1541 |
1495 | 1542 |
1496 | 1543 |
1497 OrthancLinesIterator* OrthancLinesIterator_Create(const std::string& content) | 1544 OrthancLinesIterator* OrthancLinesIterator_Create(const std::string& content) |