deferred class REGULAR_EXPRESSION

All features

Regular expression matching and substitution capabilities. Use REGULAR_EXPRESSION_BUILDER to create REGULAR_EXPRESSION objects.

See tutorial/regular_expression for usage.

Direct parents

non-conformant parents

ANY

Known children

conformant children

BACKTRACKING_REGULAR_EXPRESSION

Summary

exported features

matching capabilities

substitution capabilities

Error informations

Details

match (text: STRING): BOOLEAN

Returns True if Current regular_expression can match the text.

See also match_next, match_from, last_match_succeeded, last_match_first_index.

require

  • text /= Void
  • save_matching_text(text)

ensure

  • Result = last_match_succeeded
  • Result implies valid_substrings(text)
  • Result implies last_match_first_index.in_range(text.lower, text.upper + 1)
  • Result implies last_match_first_index <= last_match_last_index + 1

deferred match_from (text: STRING, first_index: INTEGER): BOOLEAN

Returns True if Current regular_expression can match the text starting from first_index.

See also match, last_match_succeeded, last_match_first_index.

require

  • text /= Void
  • first_index.in_range(1, text.count + 1)
  • save_matching_text(text)

ensure

  • Result = last_match_succeeded
  • Result implies valid_substrings(text)
  • Result implies last_match_first_index >= first_index
  • Result implies last_match_first_index.in_range(text.lower, text.upper + 1)
  • Result implies last_match_first_index <= last_match_last_index + 1

match_next (text: STRING): BOOLEAN

Returns True if Current regular_expression can match the same text one more time. Must be called after a successful match or math_from or match_next using the same text.

See also match, match_from, last_match_succeeded.

require

  • text /= Void
  • last_match_succeeded
  • text.has_prefix(last_match_text)
  • save_matching_text(text)

ensure

  • Result = last_match_succeeded
  • Result implies valid_substrings(text)
  • Result implies last_match_first_index.in_range(text.lower, text.upper + 1)
  • Result implies last_match_first_index <= last_match_last_index + 1

last_match_succeeded: BOOLEAN

Does last match succedeed?

See also match, match_from.

last_match_first_index: INTEGER

The starting position in the text where starts the sub-string who is matching the whole pattern.

See also match, match_from.

require

  • last_match_succeeded

ensure

  • Result > 0

last_match_last_index: INTEGER

The last position in the text where starts the sub-string who is matching the whole pattern.

See also match, match_from.

require

  • last_match_succeeded

ensure

  • Result + 1 >= last_match_first_index

last_match_count: INTEGER

Length of the string matching the whole pattern.

See also last_match_first_index, last_match_last_index, match, match_from.

require

  • last_match_succeeded

ensure

  • Result >= 0
  • definition: Result = last_match_last_index - last_match_first_index + 1

group_count: INTEGER

Number of groups in Current regular expression.

See also ith_group_first_index.

ith_group_matched (i: INTEGER): BOOLEAN

Did the ith group matched during last match?

See also group_count, ith_group_first_index.

require

  • i.in_range(0, group_count)
  • last_match_succeeded

ith_group_first_index (i: INTEGER): INTEGER

First index in the last matching text of the ith group of Current.

See also group_count.

require

  • i.in_range(0, group_count)
  • last_match_succeeded
  • ith_group_matched(i)

ensure

  • Result.in_range(0, last_match_text.upper + 1)

ith_group_last_index (i: INTEGER): INTEGER

Last index in the last matching text of the ith group of Current.

See also ith_group_first_index, group_count.

require

  • i.in_range(0, group_count)
  • last_match_succeeded
  • ith_group_matched(i)

ensure

  • Result.in_range(ith_group_first_index(i) - 1, last_match_text.upper)

ith_group_count (i: INTEGER): INTEGER

Length of the ith group of Current in the last matching.

See also ith_group_first_index, append_ith_group, group_count.

require

  • i.in_range(0, group_count)
  • last_match_succeeded
  • ith_group_matched(i)

ensure

  • Result >= 0
  • Result = ith_group_last_index(i) - ith_group_first_index(i) + 1

append_heading_text (text: STRING, buffer: STRING)

Append in buffer the text before the matching area. text is the same as used in last matching.

See also append_pattern_text, append_tailing_text, append_ith_group.

require

  • text /= Void
  • buffer /= Void
  • last_match_succeeded
  • text.has_prefix(last_match_text)

ensure

  • buffer.count = old buffer.count + last_match_first_index - 1

append_pattern_text (text: STRING, buffer: STRING)

Append in buffer the text matching the pattern. text is the same as used in last matching.

See also append_heading_text, append_tailing_text, append_ith_group.

require

  • text /= Void
  • buffer /= Void
  • last_match_succeeded
  • text.has_prefix(last_match_text)

ensure

  • buffer.count = old buffer.count + last_match_count

append_tailing_text (text: STRING, buffer: STRING)

Append in buffer the text after the matching area. text is the same as used in last matching.

See also append_heading_text, append_pattern_text, append_ith_group.

require

  • text /= Void
  • buffer /= Void
  • last_match_succeeded
  • text.is_equal(last_match_text)

ensure

  • buffer.count = old buffer.count + text.count - last_match_last_index

append_ith_group (text: STRING, buffer: STRING, i: INTEGER)

Append in buffer the text of the ith group. text is the same as used in last matching.

See also append_pattern_text, group_count.

require

  • text /= Void
  • buffer /= Void
  • last_match_succeeded
  • text.is_equal(last_match_text)
  • i.in_range(0, group_count)
  • ith_group_matched(i)

ensure

  • buffer.count = old buffer.count + ith_group_count(i)

prepare_substitution (p: STRING)

Set pattern p for substitution. If pattern p is not compatible with the Current regular expression, the pattern_error_message is updated as well as pattern_error_position.

See also substitute_in, substitute_for, substitute_all_in, substitute_all_for.

require

  • p /= Void

ensure

  • substitution_pattern_ready implies valid_substitution
  • substitution_pattern_ready xor pattern_error_message /= Void

last_substitution: STRING

You need to copy this STRING if you want to keep it.

substitute_for (text: STRING)

This call has to be precedeed by a sucessful matching on the same text. Then the substitution is made on the matching part. The result is in last_substitution.

See also prepare_substitution, last_substitution, substitute_in.

require

  • can_substitute
  • text /= Void
  • text.is_equal(last_match_text)

ensure

  • last_substitution /= Void
  • substitution_pattern_ready
  • only_one_substitution_per_match: not can_substitute

substitute_in (text: STRING)

This call has to be precedeed by a sucessful matching on the same text. Then the substitution is made in text on the matching part (text is modified).

See also prepare_substitution, substitute_for.

require

  • can_substitute
  • text /= Void
  • text.is_equal(last_match_text)

ensure

  • substitution_pattern_ready
  • only_one_substitution_per_match: not can_substitute

substitute_all_for (text: STRING)

Every matching part is substituted. No preliminary matching is required. The result is in last_substitution.

See also prepare_substitution, last_substitution, substitute_all_in.

require

  • substitution_pattern_ready
  • text /= Void

ensure

  • last_substitution /= Void
  • substitution_pattern_ready

substitute_all_in (text: STRING)

Every matching part is substituted. No preliminary matching is required. text is modified according to the substitutions is any.

See also prepare_substitution, last_substitution, substitute_all_for.

require

  • substitution_pattern_ready
  • text /= Void

ensure

  • substitution_pattern_ready

can_substitute: BOOLEAN

Substitution is only allowed when some valid substitution pattern has been registered and after a sucessful pattern matching.

See also substitute_in, substitute_for.

ensure

  • definition: Result = (substitution_pattern_ready and last_match_succeeded)

substitution_pattern_ready: BOOLEAN

True if some valid substitution pattern has been registered.

pattern_error_message: STRING

Error message for the substitution pattern.

See also prepare_substitution.

pattern_error_position: INTEGER

Error position in the substitution pattern.

See also prepare_substitution.

save_matching_text (text: STRING): BOOLEAN

Used in assertion only. Side-effect: save the text

ensure

  • Result

    Assertion only feature

invalidate_last_match

Used to prevent 2 substitutions without intermediate matching.

require

  • last_match_succeeded

ensure

  • not last_match_succeeded
  • not can_substitute

valid_substrings (text: STRING): BOOLEAN

Used in assertion only.

require

  • last_match_succeeded

ensure

  • Result

    Method for assertion only (error position is element item i)

valid_substitution: BOOLEAN

Used in assertion only.

ensure

  • Result

    Method for assertion only

substitute_all_without_tail (text: STRING): INTEGER

Substitute all matching parts from text. The resulting text is in last_substitution, excepted the end. The part of text from Result up to the end is not copied.

require

  • substitution_pattern_ready
  • text /= Void

ensure

  • last_substitution /= Void
  • substitution_pattern_ready

substrings_first_indexes: ARRAY [E_][INTEGER]

Item(0) is the starting position in the text where starts the substring who is matching the whole pattern. Next elements are the starting positions in the text of substrings matching sub-elements of the pattern.

Elements before item(0) refers to positions in the substitution_pattern. They are stored in reverse order, the first verbatim string beeing at index -1, the second one at index -2...

substrings_last_indexes: ARRAY [E_][INTEGER]

The ending position of the string starting at position found in matching_position at the same index.

substitution_pattern: STRING
compiled_substitution_pattern: FAST_ARRAY [E_][INTEGER]

This array describe the substitution text as a suite of strings from substrings_first_indexes.

substitution_buffer: STRING
last_match_text: STRING

For assertion only.

last_match_text_memory: STRING

For assertion only.

Class invariant