mardi 1 mai 2018

C++ match (CR) LF

So i want to count lines in C++ code and i use

    std::regex lineEnds("[\\r?\\n]");
    std::ptrdiff_t const match_count(std::distance(
        std::sregex_iterator(str.begin(), str.end(), lineEnds),
        std::sregex_iterator()));

which is not bad, but out-of the blue it counts

"res = (!var1 && ? var2) && action(2);\n"

as two lines.

Should I somehow escape or replace ?(question mark) in the regex itself?

Aucun commentaire:

Enregistrer un commentaire