Skip to content

Commit

Permalink
Rename WildcardExpressionView::m_search_string_ptr -> m_expression.
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkrodrigues committed Sep 10, 2024
1 parent a44e50c commit db2e14f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
30 changes: 14 additions & 16 deletions components/core/src/clp/WildcardExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ WildcardExpressionView::WildcardExpressionView(
size_t const begin_idx,
size_t const end_idx
)
: m_search_string_ptr{&wildcard_expression},
: m_expression{&wildcard_expression},
m_begin_idx{begin_idx},
m_end_idx{end_idx} {
m_end_idx = std::min(m_end_idx, wildcard_expression.length());
Expand All @@ -68,13 +68,12 @@ WildcardExpressionView::WildcardExpressionView(
auto WildcardExpressionView::extend_to_adjacent_greedy_wildcards() const -> WildcardExpressionView {
auto extended_view = *this;
bool const prev_char_is_greedy_wildcard
= m_begin_idx > 0 && m_search_string_ptr->char_is_greedy_wildcard(m_begin_idx - 1);
= m_begin_idx > 0 && m_expression->char_is_greedy_wildcard(m_begin_idx - 1);
if (prev_char_is_greedy_wildcard) {
extended_view.m_begin_idx--;
}
bool const next_char_is_greedy_wildcard
= m_end_idx < m_search_string_ptr->length()
&& m_search_string_ptr->char_is_greedy_wildcard(m_end_idx);
bool const next_char_is_greedy_wildcard = m_end_idx < m_expression->length()
&& m_expression->char_is_greedy_wildcard(m_end_idx);
if (next_char_is_greedy_wildcard) {
++extended_view.m_end_idx;
}
Expand All @@ -89,31 +88,30 @@ auto WildcardExpressionView::surrounded_by_delims_or_wildcards(
has_preceding_delim = true;
} else {
bool const preceded_by_greedy_wildcard
= m_search_string_ptr->char_is_greedy_wildcard(m_begin_idx - 1);
= m_expression->char_is_greedy_wildcard(m_begin_idx - 1);
bool const preceded_by_non_greedy_wildcard
= m_search_string_ptr->char_is_non_greedy_wildcard(m_begin_idx - 1);
= m_expression->char_is_non_greedy_wildcard(m_begin_idx - 1);
bool const preceded_by_delimiter
= lexer.is_delimiter(m_search_string_ptr->get_char(m_begin_idx - 1));
= lexer.is_delimiter(m_expression->get_char(m_begin_idx - 1));
has_preceding_delim = preceded_by_greedy_wildcard || preceded_by_non_greedy_wildcard
|| preceded_by_delimiter;
}

bool has_succeeding_delim{};
if (m_search_string_ptr->length() == m_end_idx) {
if (m_expression->length() == m_end_idx) {
has_succeeding_delim = true;
} else {
bool const succeeded_by_greedy_wildcard
= m_search_string_ptr->char_is_greedy_wildcard(m_end_idx);
bool const succeeded_by_greedy_wildcard = m_expression->char_is_greedy_wildcard(m_end_idx);
bool const succeeded_by_non_greedy_wildcard
= m_search_string_ptr->char_is_non_greedy_wildcard(m_end_idx);
= m_expression->char_is_non_greedy_wildcard(m_end_idx);
// E.g. "foo:", where ':' is a delimiter
bool const succeeded_by_unescaped_delim
= false == m_search_string_ptr->char_is_escape(m_end_idx)
&& lexer.is_delimiter(m_search_string_ptr->get_char(m_end_idx));
= false == m_expression->char_is_escape(m_end_idx)
&& lexer.is_delimiter(m_expression->get_char(m_end_idx));
// E.g. "foo\\", where '\' is a delimiter
bool const succeeded_by_escaped_delim
= m_search_string_ptr->char_is_escape(m_end_idx)
&& lexer.is_delimiter(m_search_string_ptr->get_char(m_end_idx + 1));
= m_expression->char_is_escape(m_end_idx)
&& lexer.is_delimiter(m_expression->get_char(m_end_idx + 1));
has_succeeding_delim = succeeded_by_greedy_wildcard || succeeded_by_non_greedy_wildcard
|| succeeded_by_unescaped_delim || succeeded_by_escaped_delim;
}
Expand Down
20 changes: 10 additions & 10 deletions components/core/src/clp/WildcardExpression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ class WildcardExpressionView {
[[nodiscard]] auto extend_to_adjacent_greedy_wildcards() const -> WildcardExpressionView;

[[nodiscard]] auto is_greedy_wildcard() const -> bool {
return 1 == length() && m_search_string_ptr->char_is_greedy_wildcard(m_begin_idx);
return 1 == length() && m_expression->char_is_greedy_wildcard(m_begin_idx);
}

[[nodiscard]] auto is_non_greedy_wildcard() const -> bool {
return 1 == length() && m_search_string_ptr->char_is_non_greedy_wildcard(m_begin_idx);
return 1 == length() && m_expression->char_is_non_greedy_wildcard(m_begin_idx);
}

[[nodiscard]] auto starts_or_ends_with_greedy_wildcard() const -> bool {
return length() > 0
&& (m_search_string_ptr->char_is_greedy_wildcard(m_begin_idx)
|| m_search_string_ptr->char_is_greedy_wildcard(m_end_idx - 1));
&& (m_expression->char_is_greedy_wildcard(m_begin_idx)
|| m_expression->char_is_greedy_wildcard(m_end_idx - 1));
}

/**
Expand All @@ -96,27 +96,27 @@ class WildcardExpressionView {
[[nodiscard]] auto length() const -> size_t { return m_end_idx - m_begin_idx; }

[[nodiscard]] auto char_is_greedy_wildcard(size_t const idx) const -> bool {
return m_search_string_ptr->char_is_greedy_wildcard(m_begin_idx + idx);
return m_expression->char_is_greedy_wildcard(m_begin_idx + idx);
}

[[nodiscard]] auto char_is_non_greedy_wildcard(size_t const idx) const -> bool {
return m_search_string_ptr->char_is_non_greedy_wildcard(m_begin_idx + idx);
return m_expression->char_is_non_greedy_wildcard(m_begin_idx + idx);
}

[[nodiscard]] auto char_is_escape(size_t const idx) const -> bool {
return m_search_string_ptr->char_is_escape(m_begin_idx + idx);
return m_expression->char_is_escape(m_begin_idx + idx);
}

[[nodiscard]] auto get_char(size_t const idx) const -> char {
return m_search_string_ptr->get_char(m_begin_idx + idx);
return m_expression->get_char(m_begin_idx + idx);
}

[[nodiscard]] auto get_value() const -> std::string {
return m_search_string_ptr->substr(m_begin_idx, m_end_idx - m_begin_idx);
return m_expression->substr(m_begin_idx, m_end_idx - m_begin_idx);
}

private:
WildcardExpression const* m_search_string_ptr;
WildcardExpression const* m_expression;
size_t m_begin_idx;
size_t m_end_idx;
};
Expand Down

0 comments on commit db2e14f

Please sign in to comment.