Header lexy/dsl/case_folding.hpp

Rules for case-insensitive parsing.

Literal rule lexy::dsl::ascii::case_folding

lexy/dsl/case_folding.hpp
namespace lexy::dsl::ascii
{
    constexpr literal-rule auto case_folding(literal-rule lit);
}

case_folding is a literal rule that matches another literal rule but performing case folding of ASCII characters.

Requires

lit is not a rule that is already case folded.

Matching

Matches and consumes lit on an input where uppercase ASCII characters are converted to lowercase first. As such, lit is matched case-insensitively.

Errors

All errors raised by lit when it fails.

Parse tree

The single token node created by lit; its content is the input as it was before the case folding.

Example 1. Match a literal case-insensitively
struct production
{
    static constexpr auto rule = dsl::ascii::case_folding(LEXY_LIT("hello world!"));
};
Caution
As all uppercase characters of the input are converted to lowercase, but lit itself is unchanged, lit must not match uppercase characters: case_folding(LEXY_LIT("ABC")) will never match.

Literal rule lexy::dsl::unicode::simple_case_folding

lexy/dsl/case_folding.hpp
namespace lexy::dsl::unicode
{
    constexpr literal-rule auto simple_case_folding(literal-rule lit);
}

simple_case_folding is a literal rule that matches another literal rule but performing simple case folding of Unicode characters.

It requires the Unicode database.

Requires

lit is not a rule that is already case folded.

Matching

Matches and consumes lit on an input where all code points are transformed using lexy::simple_case_fold . As such, lit is matched case-insensitively.

Errors

All errors raised by lit when it fails.

Parse tree

The single token node created by lit; its content is the input as it was before the case folding.

Caution
As all uppercase characters of the input are converted to lowercase, but lit itself is unchanged, lit must not match uppercase characters: simple_case_folding(LEXY_LIT("ABC")) will never match.

See also