comparison Core/HttpServer/StringMatcher.cpp @ 3403:630fc934597f

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 07 Jun 2019 17:24:26 +0200
parents 4acd1431e603
children 8de071691d13
comparison
equal deleted inserted replaced
3402:cf31b5bacce3 3403:630fc934597f
49 //typedef boost::algorithm::boyer_moore_horspool<std::string::const_iterator> Algorithm; 49 //typedef boost::algorithm::boyer_moore_horspool<std::string::const_iterator> Algorithm;
50 50
51 Algorithm algorithm_; 51 Algorithm algorithm_;
52 52
53 public: 53 public:
54 // WARNING - The lifetime of "pattern_" must be larger than
55 // "search_", as the latter internally keeps a pointer to "pattern" (*)
54 Search(const std::string& pattern) : 56 Search(const std::string& pattern) :
55 algorithm_(pattern.begin(), pattern.end()) 57 algorithm_(pattern.begin(), pattern.end())
56 { 58 {
57 } 59 }
58 60
67 } 69 }
68 }; 70 };
69 71
70 72
71 StringMatcher::StringMatcher(const std::string& pattern) : 73 StringMatcher::StringMatcher(const std::string& pattern) :
72 search_(new Search(pattern)),
73 pattern_(pattern), 74 pattern_(pattern),
74 valid_(false) 75 valid_(false)
75 { 76 {
77 // WARNING - Don't use "pattern" (local variable, will be
78 // destroyed once exiting the constructor) but "pattern_"
79 // (variable member, will last as long as the algorithm),
80 // otherwise lifetime is bad! (*)
81 search_.reset(new Search(pattern_));
76 } 82 }
77 83
78 84
79 bool StringMatcher::Apply(Iterator start, 85 bool StringMatcher::Apply(Iterator start,
80 Iterator end) 86 Iterator end)