summaryrefslogtreecommitdiffstats
path: root/src/pcrepp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-07 04:48:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-07 04:48:35 +0000
commit207df6fc406e81bfeebdff7f404bd242ff3f099f (patch)
treea1a796b056909dd0a04ffec163db9363a8757808 /src/pcrepp
parentReleasing progress-linux version 0.11.2-1~progress7.99u1. (diff)
downloadlnav-207df6fc406e81bfeebdff7f404bd242ff3f099f.tar.xz
lnav-207df6fc406e81bfeebdff7f404bd242ff3f099f.zip
Merging upstream version 0.12.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/pcrepp/CMakeLists.txt1
-rw-r--r--src/pcrepp/Makefile.am3
-rw-r--r--src/pcrepp/pcre2pp.cc25
-rw-r--r--src/pcrepp/pcre2pp.hh21
-rw-r--r--src/pcrepp/pcre2pp_fwd.hh41
5 files changed, 71 insertions, 20 deletions
diff --git a/src/pcrepp/CMakeLists.txt b/src/pcrepp/CMakeLists.txt
index 1af8845..b85ca4c 100644
--- a/src/pcrepp/CMakeLists.txt
+++ b/src/pcrepp/CMakeLists.txt
@@ -1,6 +1,7 @@
add_library(pcrepp STATIC
../config.h.in
pcre2pp.hh
+ pcre2pp_fwd.hh
pcre2pp.cc)
target_include_directories(pcrepp PUBLIC . .. ../third-party/scnlib/include
diff --git a/src/pcrepp/Makefile.am b/src/pcrepp/Makefile.am
index 72e8319..d3f3feb 100644
--- a/src/pcrepp/Makefile.am
+++ b/src/pcrepp/Makefile.am
@@ -16,7 +16,8 @@ AM_CXXFLAGS = $(CODE_COVERAGE_CXXFLAGS)
noinst_LIBRARIES = libpcrepp.a
noinst_HEADERS = \
- pcre2pp.hh
+ pcre2pp.hh \
+ pcre2pp_fwd.hh
libpcrepp_a_SOURCES = \
pcre2pp.cc
diff --git a/src/pcrepp/pcre2pp.cc b/src/pcrepp/pcre2pp.cc
index c7429d1..1249876 100644
--- a/src/pcrepp/pcre2pp.cc
+++ b/src/pcrepp/pcre2pp.cc
@@ -32,23 +32,28 @@
#include "pcre2pp.hh"
#include "config.h"
+#include "ww898/cp_utf8.hpp"
namespace lnav {
namespace pcre2pp {
std::string
-quote(const char* unquoted)
+match_data::to_string() const
{
std::string retval;
- for (int lpc = 0; unquoted[lpc]; lpc++) {
- if (isalnum(unquoted[lpc]) || unquoted[lpc] == '_'
- || unquoted[lpc] & 0x80)
- {
- retval.push_back(unquoted[lpc]);
- } else {
- retval.push_back('\\');
- retval.push_back(unquoted[lpc]);
+ if (this->get_count() == 1) {
+ auto cap = (*this)[0];
+ retval.append(cap->data(), cap->length());
+ } else {
+ for (size_t lpc = 1; lpc < this->get_count(); lpc++) {
+ auto cap = (*this)[lpc];
+
+ if (!cap) {
+ continue;
+ }
+
+ retval.append(cap->data(), cap->length());
}
}
@@ -321,7 +326,7 @@ code::replace(string_fragment str, const char* repl) const
}
}
if (remaining.is_valid()) {
- retval.append(str.data(), remaining.sf_begin, std::string::npos);
+ retval.append(remaining.data(), 0, remaining.length());
}
return retval;
diff --git a/src/pcrepp/pcre2pp.hh b/src/pcrepp/pcre2pp.hh
index 59a2cf1..ae39871 100644
--- a/src/pcrepp/pcre2pp.hh
+++ b/src/pcrepp/pcre2pp.hh
@@ -46,14 +46,6 @@
namespace lnav {
namespace pcre2pp {
-std::string quote(const char* unquoted);
-
-inline std::string
-quote(const std::string& unquoted)
-{
- return quote(unquoted.c_str());
-}
-
class code;
struct capture_builder;
class matcher;
@@ -108,6 +100,8 @@ public:
uint32_t get_capacity() const { return this->md_ovector_count; }
+ std::string to_string() const;
+
private:
friend matcher;
friend code;
@@ -254,11 +248,20 @@ public:
template<typename T, std::size_t N>
static code from_const(const T (&str)[N], int options = 0)
{
- return from(string_fragment::from_const(str), options).unwrap();
+ auto res = from(string_fragment::from_const(str), options);
+
+ if (res.isErr()) {
+ fprintf(stderr, "failed to compile constant regex: %s\n", str);
+ fprintf(stderr, " %s\n", res.unwrapErr().get_message().c_str());
+ }
+
+ return res.unwrap();
}
const std::string& get_pattern() const { return this->p_pattern; }
+ std::string to_string() const { return this->p_pattern; }
+
named_captures get_named_captures() const;
const char* get_name_for_capture(size_t index) const;
diff --git a/src/pcrepp/pcre2pp_fwd.hh b/src/pcrepp/pcre2pp_fwd.hh
new file mode 100644
index 0000000..91a6122
--- /dev/null
+++ b/src/pcrepp/pcre2pp_fwd.hh
@@ -0,0 +1,41 @@
+/**
+ * Copyright (c) 2023, Timothy Stack
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of Timothy Stack nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef lnav_pcre2pp_fwd_hh
+#define lnav_pcre2pp_fwd_hh
+
+namespace lnav {
+namespace pcre2pp {
+
+class code;
+
+}
+} // namespace lnav
+
+#endif