Namespace mata::applications::strings::replace

namespace replace

Enums

enum class ReplaceMode

How many occurrences of the regex to replace, in order from left to right?

Values:

enumerator Single

Replace only the first occurrence of the regex.

enumerator All

Replace all occurrences of the regex.

Functions

Nfa reluctant_nfa(Nfa nfa)

Modify nfa in-place to remove outgoing transitions from final states.

If nfa accepts empty string, returned NFA will accept only the empty string.

Parameters:

nfa – NFA to modify.

Returns:

The reluctant version of nfa.

Nft create_identity(Alphabet const *const alphabet, size_t num_of_levels = 2)

Create identity transducer over the alphabet with num_of_levels levels.

Nft create_identity_with_single_symbol_replace(Alphabet const *const alphabet, Symbol from_symbol, Symbol replacement, ReplaceMode replace_mode = ReplaceMode::All)

Create identity input/output transducer with 2 levels over the alphabet with level_cnt levels with single symbol from_symbol replaced with @to_symbol.

Nft create_identity_with_single_symbol_replace(Alphabet const *const alphabet, Symbol from_symbol, const Word &replacement, ReplaceMode replace_mode = ReplaceMode::All)

Create identity input/output transducer with 2 levels over the alphabet with level_cnt levels with single symbol from_symbol replaced with word replacement.

Nft replace_reluctant_regex(const std::string &regex, const Word &replacement, Alphabet const *const alphabet, ReplaceMode replace_mode = ReplaceMode::All, Symbol begin_marker = BEGIN_MARKER)

Create NFT modelling a reluctant leftmost replace of regex regex to replacement.

The most general replace operation, handling any regex as the part to be replaced.

Parameters:
  • regex – A string containing regex to be replaced.

  • replacement – Literal to be replaced with.

  • alphabetAlphabet over which to create the NFT.

  • replace_mode – Whether to replace all or just the single (the leftmost) occurrence of regex.

  • begin_markerSymbol to be used internally as a begin marker of replaced regex.

Returns:

The reluctant leftmost replace NFT.

Nft replace_reluctant_regex(nfa::Nfa aut, const Word &replacement, Alphabet const *const alphabet, ReplaceMode replace_mode = ReplaceMode::All, Symbol begin_marker = BEGIN_MARKER)

Create NFT modelling a reluctant leftmost replace of regex represented by deterministic automaton aut to replacement.

The most general replace operation, handling any regex as the part to be replaced.

Parameters:
  • aut – deterministic automaton representing regex to be replaced.

  • replacement – Literal to replace with.

  • alphabetAlphabet over which to create the NFT.

  • replace_mode – Whether to replace all or just the single (the leftmost) occurrence of regex.

  • begin_markerSymbol to be used internally as a begin marker of replaced regex.

Returns:

The reluctant leftmost replace NFT.

Nft replace_reluctant_literal(const Word &literal, const Word &replacement, Alphabet const *const alphabet, ReplaceMode replace_mode = ReplaceMode::All, Symbol end_marker = END_MARKER)

Create NFT modelling a reluctant leftmost replace of literal literal to replacement.

Parameters:
  • literal – Literal to replace.

  • replacement – Literal to replace with.

  • alphabetAlphabet over which to create the NFT.

  • replace_mode – Whether to replace all or just the single (the leftmost) occurrence of literal.

  • end_markerSymbol to be used internally as an end marker marking the end of the replaced literal.

Returns:

The reluctant leftmost replace NFT.

Nft replace_reluctant_single_symbol(Symbol from_symbol, Symbol replacement, Alphabet const *const alphabet, ReplaceMode replace_mode = ReplaceMode::All)

Create NFT modelling a reluctant leftmost replace of symbol from_symbol to replacement.

Parameters:
  • from_symbolSymbol to replace.

  • replacementSymbol to replace with.

  • alphabetAlphabet over which to create the NFT.

  • replace_mode – Whether to replace all or just the single (the leftmost) occurrence of from_symbol.

Returns:

The reluctant leftmost replace NFT.

Nft replace_reluctant_single_symbol(Symbol from_symbol, const Word &replacement, Alphabet const *const alphabet, ReplaceMode replace_mode = ReplaceMode::All)

Create NFT modelling a reluctant leftmost replace of symbol from_symbol to replacement.

Parameters:
  • from_symbolSymbol to replace.

  • replacement – Literal to replace with.

  • alphabetAlphabet over which to create the NFT.

  • replace_mode – Whether to replace all or just the single (the leftmost) occurrence of from_symbol.

Returns:

The reluctant leftmost replace NFT.

Variables

Symbol BEGIN_MARKER = {mata::nft::EPSILON - 100}

Marker marking the beginning of the regex to be replaced.

Symbol END_MARKER = {mata::nft::EPSILON - 99}

Marker marking the end of the regex to be replaced.

class ReluctantReplace
#include <strings.hh>

Implementation of all reluctant replace versions.

Public Static Functions

static Nft replace_regex(nfa::Nfa aut, const Word &replacement, Alphabet const *const alphabet, ReplaceMode replace_mode = ReplaceMode::All, Symbol begin_marker = BEGIN_MARKER)

Create NFT modelling a reluctant leftmost replace of regex represented by deterministic automaton aut to replacement.

The most general replace operation, handling any regex as the part to be replaced.

Parameters:
  • aut – Deterministic automaton representing regex to be replaced.

  • replacement – Literal to replace with.

  • alphabetAlphabet over which to create the NFT.

  • replace_mode – Whether to replace all or just the single (the leftmost) occurrence of regex.

  • begin_markerSymbol to be used internally as a begin marker of replaced regex.

Returns:

The reluctant leftmost replace NFT.

static Nft replace_literal(const Word &literal, const Word &replacement, Alphabet const *const alphabet, ReplaceMode replace_mode = ReplaceMode::All, Symbol end_marker = END_MARKER)

Create NFT modelling a reluctant leftmost replace of literal literal to replacement.

Parameters:
  • literal – Literal to replace.

  • replacement – Literal to replace with.

  • alphabetAlphabet over which to create the NFT.

  • replace_mode – Whether to replace all or just the single (the leftmost) occurrence of literal.

  • end_markerSymbol to be used internally as an end marker marking the end of the replaced literal.

Returns:

The reluctant leftmost replace NFT.

static Nft replace_symbol(Symbol from_symbol, Symbol replacement, Alphabet const *const alphabet, ReplaceMode replace_mode = ReplaceMode::All)

Create NFT modelling a reluctant leftmost replace of symbol from_symbol to replacement.

Parameters:
  • from_symbolSymbol to replace.

  • replacementSymbol to replace with.

  • alphabetAlphabet over which to create the NFT.

  • replace_mode – Whether to replace all or just the single (the leftmost) occurrence of from_symbol.

Returns:

The reluctant leftmost replace NFT.

static Nft replace_symbol(Symbol from_symbol, const Word &replacement, Alphabet const *const alphabet, ReplaceMode replace_mode = ReplaceMode::All)

Create NFT modelling a reluctant leftmost replace of symbol from_symbol to replacement.

Parameters:
  • from_symbolSymbol to replace.

  • replacement – Literal to replace with.

  • alphabetAlphabet over which to create the NFT.

  • replace_mode – Whether to replace all or just the single (the leftmost) occurrence of from_symbol.

Returns:

The reluctant leftmost replace NFT.