[vte] regex: Use string_view



commit 61e41f1fab719c0d288dc4fe4f43798bd93eb8bd
Author: Christian Persch <chpe src gnome org>
Date:   Wed Nov 27 19:16:57 2019 +0100

    regex: Use string_view

 src/regex.cc    |  8 +++-----
 src/regex.hh    |  4 ++--
 src/vteregex.cc | 11 ++++++-----
 3 files changed, 11 insertions(+), 12 deletions(-)
---
diff --git a/src/regex.cc b/src/regex.cc
index b583c790..cf99a1b1 100644
--- a/src/regex.cc
+++ b/src/regex.cc
@@ -84,12 +84,10 @@ Regex::check_pcre_config_jit(void)
 
 Regex*
 Regex::compile(Regex::Purpose purpose,
-               char const* pattern,
-               ssize_t pattern_length,
+               std::string_view const& pattern,
                uint32_t flags,
                GError** error)
 {
-        assert(pattern != nullptr || pattern_length == 0);
         assert(error == nullptr || *error == nullptr);
 
         if (!check_pcre_config_unicode(error))
@@ -97,8 +95,8 @@ Regex::compile(Regex::Purpose purpose,
 
         int errcode;
         PCRE2_SIZE erroffset;
-        auto code = pcre2_compile_8((PCRE2_SPTR8)pattern,
-                                    pattern_length >= 0 ? pattern_length : PCRE2_ZERO_TERMINATED,
+        auto code = pcre2_compile_8((PCRE2_SPTR8)pattern.data(),
+                                    pattern.size(),
                                     (uint32_t)flags |
                                     PCRE2_UTF |
                                     (flags & PCRE2_UTF ? PCRE2_NO_UTF_CHECK : 0) |
diff --git a/src/regex.hh b/src/regex.hh
index 4cb92a04..d99bf0e6 100644
--- a/src/regex.hh
+++ b/src/regex.hh
@@ -18,6 +18,7 @@
 #pragma once
 
 #include <memory>
+#include <string>
 
 #include <glib.h>
 
@@ -37,8 +38,7 @@ public:
         static bool check_pcre_config_unicode(GError** error);
         static bool check_pcre_config_jit(void);
         static Regex* compile(Purpose purpose,
-                              char const* pattern,
-                              ssize_t pattern_length,
+                              std::string_view const& pattern,
                               uint32_t flags,
                               GError** error);
 
diff --git a/src/vteregex.cc b/src/vteregex.cc
index 6e336335..4bff1c36 100644
--- a/src/vteregex.cc
+++ b/src/vteregex.cc
@@ -82,12 +82,11 @@ vte_regex_unref(VteRegex* regex)
 
 static VteRegex*
 vte_regex_new(vte::base::Regex::Purpose purpose,
-              char const* pattern,
-              ssize_t pattern_length,
+              std::string_view const& pattern,
               uint32_t flags,
               GError** error)
 {
-        return wrapper_from_regex(vte::base::Regex::compile(purpose, pattern, pattern_length, flags, error));
+        return wrapper_from_regex(vte::base::Regex::compile(purpose, pattern, flags, error));
 }
 
 /**
@@ -116,8 +115,9 @@ vte_regex_new_for_match(const char *pattern,
                         guint32     flags,
                         GError    **error)
 {
+        auto const len = size_t{pattern_length == -1 ? strlen(pattern) : size_t(pattern_length)};
         return vte_regex_new(vte::base::Regex::Purpose::eMatch,
-                             pattern, pattern_length,
+                             {pattern, len},
                              flags,
                              error);
 }
@@ -147,8 +147,9 @@ vte_regex_new_for_search(const char *pattern,
                          guint32     flags,
                          GError    **error)
 {
+        auto const len = size_t{pattern_length == -1 ? strlen(pattern) : size_t(pattern_length)};
         return vte_regex_new(vte::base::Regex::Purpose::eSearch,
-                             pattern, pattern_length,
+                             {pattern, len},
                              flags,
                              error);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]