Loading...
Searching...
No Matches

Regular expressions on the values that arrive, with RE2. More...

Detailed Description

Regular expressions on the values that arrive, with RE2.

One outlet per capture group of the pattern, named after the group when it has a name: (?P<temp>\d+) makes a "temp" outlet. The outlets keep their cables when the pattern is edited, as long as the group keeps its name, or its number for unnamed groups.

RE2 matches in linear time, whatever the pattern: a pattern cannot stall the audio thread. It has no back-references inside the pattern, nor look-around. Compiling is not bounded that way: an edit of the pattern during playback is compiled by the worker, off the audio thread, within RE2's memory budget.

Classes

struct  capture_port
 
struct  Compiled
 A compiled pattern, or why there is none. More...
 
struct  Spec
 What the pattern is compiled from. More...
 
struct  worker
 

Public Types

enum  Mode {
  Search , Match , SearchAll , Replace ,
  Split
}
 
using tick = ossia::token_request
 

Public Member Functions

 halp_meta (name, "Regex") halp_meta(c_name
 
avnd_regex halp_meta (category, "Control/Mappings") halp_meta(author
 
avnd_regex ossia score halp_meta (description, "Match, search, replace or split text with a regular expression (RE2 syntax). " "Each capture group gets an outlet, named after the group for (?P<name>...). " "Numbers and lists are matched as their text.") halp_meta(uuid
 
void setError (std::string message)
 
void apply (Compiled &&c)
 
void compile ()
 
ossia::value groupValue (re2::StringPiece s) const
 A group as sent: its text, or the number it is when Numbers is on.
 
std::vector< ossia::value > sendGroups (int64_t ts)
 
void process (const ossia::value &input, int64_t ts)
 
void operator() (const tick &t)
 

Static Public Member Functions

static std::vector< std::string > captureGroups (const std::string &pattern)
 
static halp::string_list_value captureRows (const std::string &pattern)
 
static std::string toRE2Rewrite (std::string_view s)
 $1 and %1 as \1; $$ and %% as $ and %.
 
static Compiled build (const Spec &spec)
 
static void appendText (std::string &out, const ossia::value &v)
 
static void write (ossia::value_port *port, ossia::value v, int64_t ts)
 

Public Attributes

struct { 
 
   struct { 
 
      The text to process Numbers and lists are their   text 
 
      an impulse processes the last input again ossia::value_port *   value {} 
 
   }   input 
 
      pattern 
 
      mode 
 
      replacement 
 
      global 
 
      ignore_case 
 
      multiline 
 
      numbers 
 
} inputs 
 
struct { 
 
   struct { 
 
      The   match 
 
      Search   all: the list of matches 
 
      Replace   : " "the text replaced 
 
      Split   : the list of pieces") ossia::value_port* value{} 
 
   }   match 
 
   struct { 
 
      The groups of the   match 
 
      The groups of the as a   list 
 
      Search   all: a list " "per match") ossia::value_port* value{} 
 
   }   groups 
 
   struct { 
 
      true or   false 
 
      true or for every input ossia::value_port *   value {} 
 
   }   matched 
 
   struct { 
 
      The   input 
 
      The when it does not match ossia::value_port *   value {} 
 
   }   unmatched 
 
   struct { 
 
      Why the pattern or the replacement is not   valid 
 
      an empty string once they are ossia::value_port *   value {} 
 
   }   error 
 
   halp::keyed_dynamic_port< capture_port >   captures 
 
} outputs 
 
ossia::exec_state_facade ossia_state
 
struct ao::Regex::worker worker
 
std::unique_ptr< RE2 > re
 
std::string rewrite
 
std::string error_text
 
bool error_pending {}
 Error text not sent yet; a failure after success and the reverse.
 
bool had_error {}
 
std::vector< re2::StringPiece > submatches
 
std::string last_text
 
std::string text
 
uint64_t generation {}
 

Static Public Attributes

static constexpr int max_capture_outlets = 64
 

Member Enumeration Documentation

◆ Mode

Enumerator
Search 

The first match anywhere in the text.

Match 

The whole text must match.

SearchAll 

Every match, in order.

Replace 

The text with the matches replaced.

Split 

The pieces of text between the matches.

Member Function Documentation

◆ appendText()

static void ao::Regex::appendText ( std::string &  out,
const ossia::value &  v 
)
inlinestatic

The text of a value: strings as they are, numbers printed, lists as their elements separated by spaces.

◆ captureGroups()

static std::vector< std::string > ao::Regex::captureGroups ( const std::string &  pattern)
inlinestatic

The capture groups of a pattern, in order: their names ("" for unnamed ones). RE2's own list when the pattern compiles; otherwise read from the text, so that a typo (an unclosed parenthesis...) keeps the groups and their cables. Either way a function of the text alone: undo and reload find the same outlets.

◆ captureRows()

static halp::string_list_value ao::Regex::captureRows ( const std::string &  pattern)
inlinestatic

One row per capture group: its key and its name ("" for unnamed groups, which then take the port's "Group {}" name).

◆ compile()

void ao::Regex::compile ( )
inline

On the audio thread, the worker compiles; anywhere else (the node being set up, a host without a worker), right away.

◆ sendGroups()

std::vector< ossia::value > ao::Regex::sendGroups ( int64_t  ts)
inline

The groups of the match in submatches: in a list (empty strings for groups that did not take part) and each on its own outlet (nothing for those).

Member Data Documentation

◆ max_capture_outlets

constexpr int ao::Regex::max_capture_outlets = 64
staticconstexpr

Keys of the capture outlets: a pure function of the pattern, so that reloading a document or editing the pattern finds the same outlets.


The documentation for this struct was generated from the following file: