Mercurial > thymian
comparison common/url_breaker.cpp @ 0:a4671277546c tip
created the repository for the thymian project
| author | ferencd |
|---|---|
| date | Tue, 17 Aug 2021 11:19:54 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:a4671277546c |
|---|---|
| 1 #include "url_breaker.h" | |
| 2 | |
| 3 #include "log.h" | |
| 4 | |
| 5 #include <boost/tokenizer.hpp> | |
| 6 #include <vector> | |
| 7 | |
| 8 url_breaker::url_breaker(const std::string &components, const std::string &url) | |
| 9 { | |
| 10 std::vector<std::string> tempcomps; | |
| 11 boost::char_separator<char> sep("/"); | |
| 12 | |
| 13 // gather the mapping | |
| 14 { | |
| 15 boost::tokenizer<boost::char_separator<char>> tok(components, sep); | |
| 16 | |
| 17 for(boost::tokenizer<boost::char_separator<char>>::iterator beg=tok.begin(); ; ) | |
| 18 { | |
| 19 tempcomps.push_back(*beg); | |
| 20 ++ beg; | |
| 21 if(beg == tok.end()) | |
| 22 { | |
| 23 break; | |
| 24 } | |
| 25 } | |
| 26 | |
| 27 } | |
| 28 | |
| 29 // gather the varios url components | |
| 30 { | |
| 31 boost::tokenizer<boost::char_separator<char>> tok(url, sep); | |
| 32 auto vecit = tempcomps.begin(); | |
| 33 for(boost::tokenizer<boost::char_separator<char>>::iterator beg=tok.begin();; ) | |
| 34 { | |
| 35 comps[*vecit] = *beg; | |
| 36 ++vecit; | |
| 37 ++beg; | |
| 38 | |
| 39 if(vecit == tempcomps.end() && beg == tok.end()) | |
| 40 { | |
| 41 break; | |
| 42 } | |
| 43 | |
| 44 if(vecit == tempcomps.end()) | |
| 45 { | |
| 46 log_err() << "components map" << components << "contains less keys than" << url; | |
| 47 break; | |
| 48 } | |
| 49 | |
| 50 if(beg == tok.end()) | |
| 51 { | |
| 52 log_err() << "components map" << components << "contains more keys than" << url; | |
| 53 break; | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 } | |
| 58 | |
| 59 // debug part | |
| 60 // for(auto iterator = comps.begin(); iterator != comps.end(); ++ iterator) | |
| 61 // { | |
| 62 // debug() << "COMP[" << iterator->first << "] = " << iterator->second; | |
| 63 // } | |
| 64 } | |
| 65 | |
| 66 std::string url_breaker::operator [](const std::string &k) | |
| 67 { | |
| 68 if(comps.count(k)) | |
| 69 { | |
| 70 return comps[k]; | |
| 71 } | |
| 72 log_err() << "components map contains no value for " << k; | |
| 73 return ""; | |
| 74 } |
