Skip to content

Cast ranges to the character type #342

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

Alcaro
Copy link

@Alcaro Alcaro commented Apr 11, 2025

Fixes #330

Fixes \x80-\xFF not matching high-ascii bytes

#include <ctre.hpp>
#include <regex>
#include <iostream>

int main()
{
    const char * b = "knäckebröd";

    auto k = ctre::search<R"([\x00-\x7F\x80-\xFF]*)">(b);
    std::cout << k.get<0>().to_view() << std::endl;

    auto k2 = ctre::search<R"(.*)">(b);
    std::cout << k2.get<0>().to_view() << std::endl;

    std::regex r{R"([\x00-\x7F\x80-\xFF]*)"};
    std::cmatch m;
    std::regex_search(b, m, r);
    std::cout << m[0] << std::endl;
}

https://godbolt.org/z/h4vxWajxb

@Alcaro
Copy link
Author

Alcaro commented Apr 11, 2025

Version 2: Also fixes \x00-\xFF matching wrong things (there are few bytes <= -1 && >= 0)

@Alcaro
Copy link
Author

Alcaro commented Apr 11, 2025

Version 3: Also fixes non-range chars in classes, so [a-zñ]+ will match piñata

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[\x80-\xBF] - warning: comparison of integer expressions of different signedness
1 participant