boost - C++ compare strings up to "%" char -


i implement string comparison in c++ comparing strings "%" sign.

i this:

std::equal(str1.begin(),             std::find(str1.begin(), str1.end(), l'%'),            str2.begin()); 

since i'm doing in loop on many strings, wonder if there method without 2 distinct string traversals find , equal (maybe predicate can abort comparison @ point). boost ok.

you can try std::mismatch.
the following code run c++14 (it requires template overload 2 iterator pairs), works quite similar in c++11 (or 03, without lambdas though):

auto iters = std::mismatch( str1.begin(), str1.end(), str2.begin(), str2.end(),                       [] (char lhs, char rhs) {return lhs != '%' && lhs == rhs;});   if (iters.first  == str1.end()  || iters.second == str2.end()  || *iters.first == '%')     // success […] 

demo.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -