This class handles.
More...
#include <regexp_facade.h>
|
bool | SetPattern (Item *pattern_expr, uint32_t flags) |
| Sets the pattern if called for the first time or the pattern_expr is non-constant. More...
|
|
std::optional< bool > | Matches (Item *subject_expr, int start, int occurrence) |
| Tries to match the subject against the compiled regular expression. More...
|
|
std::optional< int > | Find (Item *subject_expr, int start, int occurrence, bool after_match) |
| Searches the subject for a match of the compiled regular expression and returns a position. More...
|
|
String * | Replace (Item *subject_expr, Item *replacement_expr, int start, int occurrence, String *result) |
|
String * | Substr (Item *subject_expr, int start, int occurrence, String *result) |
|
void | cleanup () |
| Delete the "engine" data structure after execution. More...
|
|
bool | EngineHasWarning () const |
| Did any operation return a warning? For unit testing. More...
|
|
This class handles.
- Conversion to the regexp library's character set, and buffers the converted strings during matching.
- Re-compilation of the regular expression in case the pattern is a field reference or otherwise non-constant.
NULL
handling.
- Conversion between indexing conventions. Clients of this class can use one-based indexing, while the classes used by this class use zero-based indexing.
◆ AssignResult()
String * regexp::Regexp_facade::AssignResult |
( |
const char * |
str, |
|
|
size_t |
length, |
|
|
String * |
result |
|
) |
| |
|
private |
Helper function for setting the result from SQL regular expression functions that return a string value.
Depending on character sets used by arguments and result, this function may copy, convert or just set the result. In particular, it handles the special case of the BINARY character set being interpreted as CP-1252.
- Parameters
-
| str | The result string from the regexp function. |
| length | Length in bytes. |
[out] | result | The result string. |
- Returns
- A pointer to the same string as the argument, or nullptr in case of failure.
◆ cleanup()
void regexp::Regexp_facade::cleanup |
( |
| ) |
|
|
inline |
Delete the "engine" data structure after execution.
◆ ConvertCodePointToLibPosition()
int regexp::Regexp_facade::ConvertCodePointToLibPosition |
( |
int |
position | ) |
const |
|
private |
Converts a string position in m_current_subject.
- Parameters
-
position | One-based code point position. |
- Returns
- Zero-based byte position.
◆ ConvertLibPositionToCodePoint()
int regexp::Regexp_facade::ConvertLibPositionToCodePoint |
( |
int |
position | ) |
const |
|
private |
Converts a string position in m_current_subject.
- Parameters
-
position | Zero-based UTF-16 position. |
- Returns
- Zero-based code point position.
◆ EngineHasWarning()
bool regexp::Regexp_facade::EngineHasWarning |
( |
| ) |
const |
|
inline |
Did any operation return a warning? For unit testing.
◆ Find()
std::optional< int > regexp::Regexp_facade::Find |
( |
Item * |
subject_expr, |
|
|
int |
start, |
|
|
int |
occurrence, |
|
|
bool |
after_match |
|
) |
| |
Searches the subject for a match of the compiled regular expression and returns a position.
- Parameters
-
subject_expr | The string to search. |
start | Start position, 1-based. |
occurrence | Which occurrence of the pattern should be searched for. |
after_match | If true, the position following the end of the match is returned. If false, the position before the match is returned. |
- Returns
- The first character of the match, or a null value if not found.
◆ Matches()
std::optional< bool > regexp::Regexp_facade::Matches |
( |
Item * |
subject_expr, |
|
|
int |
start, |
|
|
int |
occurrence |
|
) |
| |
Tries to match the subject against the compiled regular expression.
- Parameters
-
subject_expr | Is evaluated into a string to search. |
start | Start position, 1-based. |
occurrence | Which occurrence of the pattern should be searched for. |
- Return values
-
true | A match was found. |
false | A match was not found. |
nullptr | Either the engine was not compiled, or subject_expr evaluates to NULL. This is useful for the Item_func_regexp object, since it doesn't have to make a special case for when the regular expression is NULL. Instead, the case is handled here in the facade. |
◆ Replace()
String * regexp::Regexp_facade::Replace |
( |
Item * |
subject_expr, |
|
|
Item * |
replacement_expr, |
|
|
int |
start, |
|
|
int |
occurrence, |
|
|
String * |
result |
|
) |
| |
- Parameters
-
| subject_expr | The string to search. |
| replacement_expr | The string to replace the match with. |
| start | Start position, 1-based. |
| occurrence | Which occurrence of the pattern should be searched for. |
[in,out] | result | Holds the buffer for writing the result. |
◆ Reset()
bool regexp::Regexp_facade::Reset |
( |
Item * |
subject_expr, |
|
|
int |
start = 1 |
|
) |
| |
|
private |
Resets the compiled regular expression with a new string.
- Parameters
-
subject_expr | The new string to search. |
start | If present, start on this code point. |
- Return values
-
false | OK. |
true | Either there is no compiled regular expression, or the expression evaluated to NULL . |
◆ SetPattern()
bool regexp::Regexp_facade::SetPattern |
( |
Item * |
pattern_expr, |
|
|
uint32_t |
flags |
|
) |
| |
Sets the pattern if called for the first time or the pattern_expr is non-constant.
This function is meant to be called for every row in a command such as
SELECT regexp_like( column, 'a+' ) FROM table;
In this case, the client of this class may call SetPattern() for every row without paying any penalty, as this becomes a no-op for all consecutive calls. In cases such as
SELECT regexp_like( column, regexp_column ) FROM table;
The regexp_column
expression is non-constant and hence we have to recompile the regular expression for each row.
◆ SetupEngine()
bool regexp::Regexp_facade::SetupEngine |
( |
Item * |
pattern_expr, |
|
|
uint |
flags |
|
) |
| |
|
private |
Actually compiles the regular expression.
◆ Substr()
String * regexp::Regexp_facade::Substr |
( |
Item * |
subject_expr, |
|
|
int |
start, |
|
|
int |
occurrence, |
|
|
String * |
result |
|
) |
| |
◆ m_current_subject
std::u16string regexp::Regexp_facade::m_current_subject |
|
private |
ICU does not copy the subject string, so we keep the subject buffer here.
A call to Reset() causes it to be overwritten.
- See also
- Regexp_engine::reset()
◆ m_engine
Used for all the actual regular expression matching, search-and-replace, and positional and string information.
If either the regular expression pattern or the subject is NULL
, this pointer is empty.
The documentation for this class was generated from the following files: