Qore Programming Language  1.12.0
QoreRegexSubst.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreRegexSubst.h
4 
5  regular expression substitution node definition
6 
7  Qore Programming Language
8 
9  Copyright (C) 2003 - 2022 Qore Technologies, s.r.o.
10 
11  Permission is hereby granted, free of charge, to any person obtaining a
12  copy of this software and associated documentation files (the "Software"),
13  to deal in the Software without restriction, including without limitation
14  the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  and/or sell copies of the Software, and to permit persons to whom the
16  Software is furnished to do so, subject to the following conditions:
17 
18  The above copyright notice and this permission notice shall be included in
19  all copies or substantial portions of the Software.
20 
21  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  DEALINGS IN THE SOFTWARE.
28 
29  Note that the Qore library is released under a choice of three open-source
30  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
31  information.
32 */
33 
34 #ifndef _QORE_QOREREGEXSUBST_H
35 
36 #define _QORE_QOREREGEXSUBST_H
37 
38 #include "qore/intern/QoreRegexBase.h"
39 #include <sys/types.h>
40 
41 class QoreRegexSubst : public QoreRegexBase, public QoreReferenceCounter {
42 public:
43  DLLLOCAL QoreRegexSubst();
44 
45  // used at run-time
46  DLLLOCAL QoreRegexSubst(const QoreString* pstr, int opts, ExceptionSink* xsink);
47 
48  DLLLOCAL ~QoreRegexSubst();
49 
50  DLLLOCAL int parseRT(const QoreString* pstr, ExceptionSink* xsink);
51  DLLLOCAL int parse();
52  DLLLOCAL QoreStringNode* exec(const QoreString* target, ExceptionSink* xsink) const;
53  DLLLOCAL QoreStringNode* exec(const QoreString* target, const QoreString* newstr, ExceptionSink* xsink) const;
54  DLLLOCAL void concatSource(char c);
55  DLLLOCAL void concatTarget(char c);
56  DLLLOCAL void setGlobal();
57  DLLLOCAL QoreString* getPattern() const;
58 
59  DLLLOCAL void ref() const {
60  ROreference();
61  }
62 
63  DLLLOCAL void deref() {
64  if (ROdereference()) {
65  delete this;
66  }
67  }
68 
69  DLLLOCAL QoreRegexSubst* refSelf() const {
70  ref();
71  return const_cast<QoreRegexSubst*>(this);
72  }
73 
74 protected:
75 private:
76  bool global = false;
77  QoreString* newstr = nullptr;
78 
79  DLLLOCAL static int concat(ExceptionSink& xsink, QoreString* str, int* ovector, int olen, const char* ptr,
80  const char* target, int rc);
81 };
82 
83 #endif // _QORE_QOREREGEXSUBST_H
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
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
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50