Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add smartcase to the regex engine. #5208

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/regex_impl.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "regex_impl.hh"

#include "exception.hh"
#include "string.hh"
#include "unicode.hh"
Expand All @@ -9,7 +8,6 @@
#include "string_utils.hh"
#include "vector.hh"
#include "utils.hh"

jamiedsmith95 marked this conversation as resolved.
Show resolved Hide resolved
#include <cstdio>
#include <cstring>
#include <limits>
Expand Down Expand Up @@ -153,6 +151,7 @@ struct RegexParser
None = 0,
IgnoreCase = 1 << 0,
DotMatchesNewLine = 1 << 1,
SmartCase = 1 << 2,
};
friend constexpr bool with_bit_ops(Meta::Type<Flags>) { return true; }

Expand Down Expand Up @@ -212,6 +211,7 @@ struct RegexParser
case 'I': m_flags &= ~Flags::IgnoreCase; break;
case 's': m_flags |= Flags::DotMatchesNewLine; break;
case 'S': m_flags &= ~Flags::DotMatchesNewLine; break;
case 'c': m_flags |= Flags::SmartCase; m_flags |= Flags::IgnoreCase; break;
jamiedsmith95 marked this conversation as resolved.
Show resolved Hide resolved
case ')':
m_pos = Iterator{it, m_regex};
return true;
Expand Down Expand Up @@ -328,6 +328,14 @@ struct RegexParser
if (contains(StringView{"^$.*+?[]{}"}, cp) or (cp >= 0xF0000 and cp <= 0xFFFFF))
parse_error(format("unexpected '{}'", cp));
++m_pos;
if (is_upper(cp) && (m_flags & Flags::SmartCase)) {
m_flags &= ~Flags::IgnoreCase;
jamiedsmith95 marked this conversation as resolved.
Show resolved Hide resolved
for (ParsedRegex::Node &node : m_parsed_regex.nodes)
{
node.ignore_case = false;
}
jamiedsmith95 marked this conversation as resolved.
Show resolved Hide resolved

}
return add_node(ParsedRegex::Literal, cp);
}
}
Expand Down