( !compile_flags &&
72 "Bad regular expression compilation flags");
99 "Bad regular expression match flags");
133(*pcre_free)(m_Extra);
157x_flags, &err_num, &err_offset,
NULL);
160 m_PReg= pcre_compile(pattern.
data(), x_flags, &err, &err_offset,
NULL);
162 m_PReg= pcre_compile(
string(pattern).c_str(), x_flags, &err, &err_offset,
NULL);
171 string(pattern) +
"' failed: "+ err);
181(*pcre_free)(m_Extra);
183m_Extra = pcre_study((pcre*)
m_PReg, 0, &err);
195dst.assign(sub.data(), sub.size());
208 static const intkNotFound = -1;
212 if(start == kNotFound || end == kNotFound) {
279}
while(pos !=
NPOS);
302 if(
mask[pos] ==
'*') {
305}
else if(
mask[pos] ==
'?') {
315}
while(pos !=
NPOS);
330: m_Delimiter(
"\n")
356 if( search.
empty() ) {
359 size_tn_replace = 0;
365 CRegexpre(search, compile_flags);
366 size_tstart_pos = 0;
368 for(
size_t count= 0; !(max_replace &&
count>= max_replace);
count++) {
373 if(num_found <= 0) {
379 stringx_replace(replace.
data(), replace.
length());
384pos = x_replace.find(
"$", pos);
390 const char* startptr = x_replace.c_str() + pos + 1;
392 long value= strtol(startptr, &endptr, 10);
394 if( errno || endptr == startptr || !endptr ||
395value < kMin_Int || value >
kMax_Int) {
405 if(
n> 0 &&
n< num_found ) {
419 size_tsp_start = pos;
420 size_tsp_end = endptr - x_replace.c_str();
421 if( sp_start > 0 && x_replace[sp_start-1] ==
'{') {
423 if( sp_end < x_replace.length() &&
424x_replace[sp_end] ==
'}') {
432x_replace.replace(sp_start, sp_end - sp_start, subpattern.
data(), subpattern.
length());
433pos += subpattern.
length();
440start_pos =
result[0] + x_replace.length();
459 if( search.
empty() ) {
464 size_tn_replace = 0;
471 boolclose_inside =
false;
492close_inside = (re.
NumFound() > 0);
495close_inside =
true;
499 if( (inside && process_inside ==
eInside) ||
500(!inside && process_inside ==
eOutside) ) {
502n_replace += re.
Replace(search, replace,
503compile_flags, match_flags, max_replace);
508 if( close_inside ) {
529 size_tstart_pos = 0;
ncbi::TMaskedQueryRegions mask
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
std::ofstream out("events_result.xml")
main entry point for tests
static DLIST_TYPE *DLIST_NAME() prev(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
static const char * str(char *buf, int n)
constexpr size_t ArraySize(const Element(&)[Size])
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
TErrCode GetErrCode(void) const
Get error code.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
const TOffset * GetResults(size_t idx) const
Get location of pattern/subpattern for the last GetMatch().
void SetRange(CTempStringEx addr_start=kEmptyStr, CTempStringEx addr_end=kEmptyStr, CTempString delimiter="\n")
Set new range for range-dependent functions.
virtual ~CRegexp()
Destructor.
bool IsMatch(CTempString str, TMatch flags=fMatch_default)
Check existence substring which match a specified pattern.
ERange
Range processing type.
void x_Join(void)
Join substrings back to entire string.
CTempString GetSub(CTempString str, size_t idx=0) const
Get pattern/subpattern from previous GetMatch().
void Reset(CTempString str)
Reset the content of the string to process.
CTempString m_Delimiter
Delimiter used to split m_Content.
const size_t kRegexpMaxSubPatterns
Specifies the maximum number of subpatterns that can be found.
CTempString GetMatch(CTempString str, size_t offset=0, size_t idx=0, TMatch flags=fMatch_default, bool noreturn=false)
Get matching pattern and subpatterns.
size_t Replace(CTempStringEx search, CTempString replace, CRegexp::TCompile compile_flags=CRegexp::fCompile_default, CRegexp::TMatch match_flags=CRegexp::fMatch_default, size_t max_replace=0)
Replace occurrences of a substring within a string by pattern.
CRegexp(CTempStringEx pattern, TCompile flags=fCompile_default)
Constructor.
CTempStringEx m_RangeEnd
Regexp to determine end of range.
void x_Match(CTempString str, size_t offset, TMatch flags)
static string Escape(CTempString str)
Escape all regular expression meta characters in the string.
int NumFound() const
Get number of patterns + subpatterns.
unsigned int TMatch
Match options.
size_t ReplaceRange(CTempStringEx search, CTempString replace, CRegexp::TCompile compile_flags=CRegexp::fCompile_default, CRegexp::TMatch match_flags=CRegexp::fMatch_default, CRegexpUtil::ERange process_within=eInside, size_t max_replace=0)
Replace all occurrences of a substring within a string by pattern.
static string WildcardToRegexp(CTempString mask)
Convert wildcard mask to regular expression.
CTempStringEx m_RangeStart
Regexp to determine start of range.
string m_Content
Content string.
list< string > m_ContentList
Content list.
int m_NumFound
The total number of pattern + subpatterns resulting from the last call to GetMatch.
unsigned int TCompile
Type definitions used for code clarity.
CRegexpUtil(CTempString str=kEmptyStr)
Constructor.
virtual const char * GetErrCodeString(void) const override
Get error code interpreted as text.
void Set(CTempStringEx pattern, TCompile flags=fCompile_default)
Set and compile PCRE.
void * m_MatchData
Pointer to compiled PCRE pattern.
size_t TOffset
Element type for GetResults().
bool m_IsDivided
TRUE if m_ContentList is newer than m_Content, and FALSE otherwise.
@ eOutside
Process substrings outside range.
@ eInside
Process substrings inside range.
@ fMatch_not_begin
^ won't match string begin.
@ fMatch_not_end
$ won't match string end.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
NCBI_NS_STD::string::size_type SIZE_TYPE
CTempString & assign(const char *src_str, size_type len)
Assign new values to the content of the a string.
static string Join(const TContainer &arr, const CTempString &delim)
Join strings using the specified delimiter.
const char * data(void) const
Return a pointer to the array represented.
bool empty(void) const
Return true if the represented string is empty (i.e., the length is zero)
size_type length(void) const
Return the length of the represented array.
bool HasZeroAtEnd(void) const
size_type size(void) const
Return the length of the represented array.
unsigned int
A callback function used to compare two keys in a database.
const GenericPointer< typename T::ValueType > T2 value
The NCBI C++/STL use hints.
#define PCRE2_ERROR_UNSET
PCRE2_EXPORT pcre2_code *PCRE2_CALL_CONVENTION pcre2_compile(PCRE2_SPTR pattern, PCRE2_SIZE patlen, uint32_t options, int *errorptr, PCRE2_SIZE *erroroffset, pcre2_compile_context *ccontext)
PCRE2_EXPORT void PCRE2_CALL_CONVENTION pcre2_code_free(pcre2_code *code)
PCRE2_EXPORT int PCRE2_CALL_CONVENTION pcre2_get_error_message(int enumber, PCRE2_UCHAR *buffer, PCRE2_SIZE size)
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION pcre2_jit_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, PCRE2_SIZE start_offset, uint32_t options, pcre2_match_data *match_data, pcre2_match_context *mcontext)
PCRE2_EXPORT int PCRE2_CALL_CONVENTION pcre2_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, PCRE2_SIZE start_offset, uint32_t options, pcre2_match_data *match_data, pcre2_match_context *mcontext)
PCRE2_EXPORT pcre2_match_data *PCRE2_CALL_CONVENTION pcre2_match_data_create_from_pattern(const pcre2_code *code, pcre2_general_context *gcontext)
PCRE2_EXPORT PCRE2_SIZE *PCRE2_CALL_CONVENTION pcre2_get_ovector_pointer(pcre2_match_data *match_data)
PCRE2_EXPORT void PCRE2_CALL_CONVENTION pcre2_match_data_free(pcre2_match_data *match_data)
static pcre2_match_data * match_data
#define F_ISSET(flags, mask)
static int s_GetRealMatchFlags(CRegexp::TMatch match_flags)
static int s_GetRealCompileFlags(CRegexp::TCompile compile_flags)
static const char delimiter[]
C++ wrappers for the Perl-compatible regular expression (PCRE) library.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4