Skip to content

lookahead fails to compile, when utf8 strings are used #338

@Bernhard-L

Description

@Bernhard-L

we use a small regex to check, if the string for the password is at least 8 chars, and includes at least one special char.

"^(?=.?[.<>()+\-&?;,%:"\\='])[[:alnum:][:punct:]À-ž]{8,}$"

this is working fine - as long as ascii chars are involved - as soon as we need to include german umlaut in utf8, we tried changing to the u8 string version.

EXPECT_TRUE(ctre::match<u8"[[:alnum:][:punct:]À-ž]+">(u8"Günter&Kastenfrosch"));

and this would work - but the positive lookahead, which checks for the special chars

-> this is not compiling
EXPECT_TRUE(ctre::match<u8"^(?=.*?[.<>()+\\-&?*;,%:\"\\\\='])[[:alnum:][:punct:]À-ž]{8,}$">(u8"Günter&Kastenfrosch"));
(tried with MSVC 17.12.4, with standard at c++23 )

error would be in
evaluation.hpp(143)

ctre::evaluate<R,BeginIterator,Iterator,EndIterator,ctre::set<ctre::character<46>,ctre::character<60>,ctre::character<62>,ctre::character<40>,ctre::character<41>,ctre::character<43>,ctre::character<45>,ctre::character<38>,ctre::character<63>,ctre::character<42>,ctre::character<59>,ctre::character<44>,ctre::character<37>,ctre::character<58>,ctre::character<34>,ctre::character<92>,ctre::character<61>,ctre::character<39>>,ctre::end_lookahead_mark,void>(const BeginIterator,Iterator,const EndIterator,const ctre::flags &,R,ctll::list<ctre::set<ctre::character<46>,ctre::character<60>,ctre::character<62>,ctre::character<40>,ctre::character<41>,ctre::character<43>,ctre::character<45>,ctre::character<38>,ctre::character<63>,ctre::character<42>,ctre::character<59>,ctre::character<44>,ctre::character<37>,ctre::character<58>,ctre::character<34>,ctre::character<92>,ctre::character<61>,ctre::character<39>>,ctre::end_lookahead_mark> with [ R=ctre::regex_results<ctre::match_method::exec::result_iterator>, BeginIterator=ctre::utf8_iterator, Iterator=ctre::match_method::exec::result_iterator, EndIterator=ctre::utf8_iterator::sentinel ]

by the way

std::string g{ "Günter" };
std::u8string u8s_from_string(g.cbegin(), g.cend());
EXPECT_TRUE(ctre::match<u8"[[:alnum:][:punct:]À-ž]+">(u8s_from_string));
EXPECT_TRUE(ctre::match<u8"[[:alnum:][:punct:]À-ž]+">(u8s_from_string.c_str()));

the first one fails, the second one works - and I don't get why.... but it compiles

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions