deferred class REGULAR_EXPRESSION

Features exported to INTERNALS_HANDLER

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

ensure

  • Result = last_match_succeeded
  • 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)

ensure

  • Result = last_match_succeeded
  • 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

ensure

  • Result = last_match_succeeded
  • 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

    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

      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

      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

      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

      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
      • 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 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

      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

      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.

      Class invariant