Qore Programming Language  1.12.0
QoreRegex.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreRegex.h
4 
5  Copyright (C) 2003 - 2022 Qore Technologies, s.r.o.
6 
7  Permission is hereby granted, free of charge, to any person obtaining a
8  copy of this software and associated documentation files (the "Software"),
9  to deal in the Software without restriction, including without limitation
10  the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  and/or sell copies of the Software, and to permit persons to whom the
12  Software is furnished to do so, subject to the following conditions:
13 
14  The above copyright notice and this permission notice shall be included in
15  all copies or substantial portions of the Software.
16 
17  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23  DEALINGS IN THE SOFTWARE.
24 
25  Note that the Qore library is released under a choice of three open-source
26  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
27  information.
28 */
29 
30 /*
31  PCRE-based matching (Perl-compatible regular expression matching)
32  see: http://www.pcre.org for more information on this library
33 
34  NOTE: all regular expression matching is done with UTF-8 encoding, so character set
35  encodings are converted if necessary
36  */
37 
38 #ifndef _QORE_QOREREGEX_H
39 
40 #define _QORE_QOREREGEX_H
41 
42 #include "qore/intern/QoreRegexBase.h"
43 
44 #include <functional>
45 
46 hashdecl QoreProgramLocation;
47 
48 class QoreRegex : public QoreRegexBase, public QoreReferenceCounter {
49 public:
50  // function pointer to allow the parse location for parse errors to be generated on demand
51  typedef std::function<const QoreProgramLocation* ()> q_get_loc_t;
52 
53  DLLLOCAL QoreRegex();
54  // used at run-time, does not change str
55  DLLLOCAL QoreRegex(const QoreString& str, int64 options, ExceptionSink* xsink);
56 
57  DLLLOCAL ~QoreRegex();
58 
59  DLLLOCAL void concat(char c);
60  // called at parse time; the get_loc lambda is only called if an error occurs parsing the regular expression
61  // this allows the source location to only be created if it's needed due to the error
62  DLLLOCAL void parse(q_get_loc_t get_loc);
63  DLLLOCAL void parseRT(const QoreString* pattern, ExceptionSink* xsink);
64  DLLLOCAL bool exec(const QoreString* target, ExceptionSink* xsink) const;
65  DLLLOCAL bool exec(const char* str, size_t len) const;
66  DLLLOCAL QoreListNode* extractSubstrings(const QoreString* target, ExceptionSink* xsink) const;
67  DLLLOCAL QoreListNode* extractWithPattern(const QoreString& target, bool include_pattern,
68  ExceptionSink* xsink) const;
69  // caller owns QoreString returned
70  DLLLOCAL QoreString* getString();
71 
72  DLLLOCAL void setGlobal() {
73  global = true;
74  }
75 
76  DLLLOCAL void ref() const {
77  ROreference();
78  }
79 
80  DLLLOCAL void deref() {
81  if (ROdereference())
82  delete this;
83  }
84 
85  DLLLOCAL QoreRegex* refSelf() const {
86  ref();
87  return const_cast<QoreRegex*>(this);
88  }
89 
90 private:
91  bool global = false;
92 };
93 
94 #endif // _QORE_QOREREGEX_H
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
provides atomic reference counting to Qore objects
Definition: QoreReferenceCounter.h:44
DLLEXPORT void ROreference() const
atomically increments the reference count
DLLEXPORT bool ROdereference() const
atomically decrements the reference count
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260