HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Regex Class Reference

#include <UT_Regex.h>

Classes

struct  FromBundleGlobTag
 
struct  FromGlobTag
 

Public Member Functions

 UT_Regex ()
 
 UT_Regex (const char *expr)
 
 UT_Regex (const char *pattern, FromGlobTag)
 
 UT_Regex (const char *pattern, FromBundleGlobTag)
 
bool init (const char *expr, bool case_sensitive=true)
 
bool initFromGlob (const char *pattern, bool case_sensitive=true, bool is_bundle_glob=false)
 
bool isValid () const
 
const char * getErrorString () const
 
bool search (const char *string, exint start=0, exint end=-1) const
 
bool search (const char *string, UT_StringArray &captured, exint start=0, exint end=-1) const
 
bool search (const char *string, UT_Array< std::pair< exint, exint >> &indicies, exint start=0, exint end=-1) const
 
bool searchall (const char *string, UT_StringArray &results, exint start=0, exint end=-1) const
 
bool split (const char *string, UT_StringArray &results, exint maxsplits=0) const
 
bool split (const UT_StringView &str, UT_StringViewArray &results, exint maxsplits=0) const
 
bool replace (UT_WorkBuffer &result, const char *string, const char *replace, bool replace_all=false, bool copy_on_fail=true) const
 
bool replace (UT_WorkBuffer &result, const char *string, const char *replace, exint num_replacements, bool copy_on_fail=true) const
 
bool match (const char *string) const
 
bool match (const UT_StringView &str) const
 
bool match (const UT_String &str) const
 
bool match (const UT_StringRef &str) const
 
bool match (const char *string, UT_StringArray &captured) const
 
bool match (const UT_StringView &string, UT_StringViewArray &captured) const
 

Static Public Member Functions

static bool convertGlobToExpr (UT_WorkBuffer &expr, const char *glob, bool is_bundle_glob=false)
 

Static Public Attributes

static FromGlobTag FromGlob
 
static FromBundleGlobTag FromBundleGlob
 

Detailed Description

Definition at line 37 of file UT_Regex.h.

Constructor & Destructor Documentation

UT_Regex::UT_Regex ( )
inline

Constructs an empty regular expression. It will match nothing and isValid will return false.

Definition at line 47 of file UT_Regex.h.

UT_Regex::UT_Regex ( const char *  expr)
inlineexplicit

Initializes the regular expression from the expression string. Use isValid to test for validity.

Definition at line 51 of file UT_Regex.h.

UT_Regex::UT_Regex ( const char *  pattern,
FromGlobTag   
)
inline

Initializes the regular expression from a glob pattern. Use isValid to test for validity.

See Also
convertGlobToExpr() for exact accepted rules

Definition at line 59 of file UT_Regex.h.

UT_Regex::UT_Regex ( const char *  pattern,
FromBundleGlobTag   
)
inline

Initializes the regular expression from a glob pattern. Use isValid to test for validity.

See Also
convertGlobToExpr() for exact accepted rules

Definition at line 67 of file UT_Regex.h.

Member Function Documentation

static bool UT_Regex::convertGlobToExpr ( UT_WorkBuffer expr,
const char *  glob,
bool  is_bundle_glob = false 
)
static

The accepted glob pattern rules are as follows:

  • a '*' matches any path component, but it stops at slashes.
  • use '**' to match anything, including slashes.
  • a '?' matches any character except a slash (/).
  • '[',']' matches one of the enclosed characters, eg. [abc]
    • '-' within '[',']' denotes a character range, eg. [a-c]
  • If first character after '[' is ! or ^, then it matches anything except the enclosed characters.
  • '{','}' matches the any of the comma(',') separated patterns within
  • If is_bundle_glob is true, then the following rules apply as well:
  • '*' matches anything, including slashes.
  • '' to match any path component, but stops at slashes.
  • '(', '|', ')' for grouping.
    Returns
    false if glob is NULL or the empty string.
const char* UT_Regex::getErrorString ( ) const
bool UT_Regex::init ( const char *  expr,
bool  case_sensitive = true 
)

Initializes the regular expression from the expression string. If the expression parses correctly, this function returns true.

bool UT_Regex::initFromGlob ( const char *  pattern,
bool  case_sensitive = true,
bool  is_bundle_glob = false 
)

Initializes the regular expression from the glob pattern. If the expression parses correctly, this function returns true. See convertGlobToExpr() for syntax.

bool UT_Regex::isValid ( ) const

Returns true if the regular expression parses correctly. If the return value is false, use getErrorString to get a human readable error string.

bool UT_Regex::match ( const char *  string) const

Returns true if the entire input string matches the regular expression, false otherwise.

bool UT_Regex::match ( const UT_StringView str) const

Returns true if the entire input string matches the regular expression, false otherwise.

bool UT_Regex::match ( const UT_String str) const
inline

Returns true if the entire input string matches the regular expression, false otherwise.

Definition at line 112 of file UT_Regex.h.

bool UT_Regex::match ( const UT_StringRef str) const
inline

Returns true if the entire input string matches the regular expression, false otherwise.

Definition at line 114 of file UT_Regex.h.

bool UT_Regex::match ( const char *  string,
UT_StringArray captured 
) const

Returns true if the entire input string matches the regular expression, false otherwise. If successful, returns the list of the captured sub-strings through the captured string array, excluding the string itself.

bool UT_Regex::match ( const UT_StringView string,
UT_StringViewArray captured 
) const

Returns true if the entire input string matches the regular expression, false otherwise. If successful, returns the list of the captured sub-strings through the captured string array, excluding the string itself.

bool UT_Regex::replace ( UT_WorkBuffer result,
const char *  string,
const char *  replace,
bool  replace_all = false,
bool  copy_on_fail = true 
) const

Replaces the first occurence of the regular expression in the source string with the replacement value from replace, and writes out the result. If replace_all is set to true, all occurences are replaced. If there is no match, the result buffer is set to identical to the input string, unless copy_on_fail is false, in which case it is left untouched.

bool UT_Regex::replace ( UT_WorkBuffer result,
const char *  string,
const char *  replace,
exint  num_replacements,
bool  copy_on_fail = true 
) const

Same as above except a fixed number of replacements can be set instead of just all or just one. 0 means replace all.

bool UT_Regex::search ( const char *  string,
exint  start = 0,
exint  end = -1 
) const

Returns true if the regular expression is found somewhere in the input string, false otherwise.

bool UT_Regex::search ( const char *  string,
UT_StringArray captured,
exint  start = 0,
exint  end = -1 
) const

Returns true if the regular expression is found somewhere in the input string, false otherwise. If successful, returns the list of the captured sub-strings through the captured string array.

bool UT_Regex::search ( const char *  string,
UT_Array< std::pair< exint, exint >> &  indicies,
exint  start = 0,
exint  end = -1 
) const

Returns true if the regular expression is found somewhere in the input string, false otherwise. If successful, returns an array of pairs of start and end indicies the items where found at.

bool UT_Regex::searchall ( const char *  string,
UT_StringArray results,
exint  start = 0,
exint  end = -1 
) const

Returns true if the regular expression is found somewhere in the input string, false otherwise. If successful, fills results array with strings that match the entire regex expression (no capture groups)

bool UT_Regex::split ( const char *  string,
UT_StringArray results,
exint  maxsplits = 0 
) const

Splits the given string into substrings when the regular expression is found. Returns true if at least one split has occured. If no splits occur, results will contain one entry which is the original string. NOTE: Does not split empty trailing components, a,b, split by , will only generate two elements. This differs from standard split definitions, but results from how C++ standard has evolved. You can append |($(?!\s)) to your reg ex to get the python-style This will match end-of line ($) but also use the negative lookahead to not match embedded
and only the end-of-string.

bool UT_Regex::split ( const UT_StringView str,
UT_StringViewArray results,
exint  maxsplits = 0 
) const

Member Data Documentation

FromBundleGlobTag UT_Regex::FromBundleGlob
static

Definition at line 43 of file UT_Regex.h.

FromGlobTag UT_Regex::FromGlob
static

Definition at line 41 of file UT_Regex.h.


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