[gucharmap] all: Use PCRE2 instead of GRegex
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gucharmap] all: Use PCRE2 instead of GRegex
- Date: Wed, 15 Sep 2021 22:11:03 +0000 (UTC)
commit ad8325126ea2541969014279e32289923180830d
Author: Christian Persch <chpe src gnome org>
Date: Thu Sep 16 00:10:20 2021 +0200
all: Use PCRE2 instead of GRegex
gucharmap/gucharmap-charmap.c | 43 +++++++++++++++++++++++++++++++------------
gucharmap/meson.build | 1 +
meson.build | 8 +++++---
3 files changed, 37 insertions(+), 15 deletions(-)
---
diff --git a/gucharmap/gucharmap-charmap.c b/gucharmap/gucharmap-charmap.c
index daadd1ce..c9b7cc3f 100644
--- a/gucharmap/gucharmap-charmap.c
+++ b/gucharmap/gucharmap-charmap.c
@@ -29,6 +29,9 @@
#include "gucharmap-marshal.h"
#include "gucharmap-private.h"
+#define PCRE2_CODE_UNIT_WIDTH 0
+#include <pcre2.h>
+
struct _GucharmapCharmapPrivate {
GtkWidget *notebook;
GucharmapChaptersView *chapters_view;
@@ -367,18 +370,34 @@ insert_hanja_prop_detail (GucharmapCharmap *charmap,
gtk_text_buffer_insert (buffer, iter, name, -1);
gtk_text_buffer_insert (buffer, iter, " ", -1);
- GError *err = NULL;
- GRegex *regex = g_regex_new ("[\\w:\\w*]", 0, 0, &err);
- g_assert_no_error (err);
-
- GMatchInfo *match_info = NULL;
- g_regex_match (regex, value, 0, &match_info);
- gboolean matches = g_match_info_matches (match_info);
-
- g_regex_unref (regex);
- g_match_info_free (match_info);
-
- if (!matches) {
+ int errcode;
+ size_t erroffset;
+ pcre2_code_8* code = pcre2_compile_8 ((PCRE2_SPTR8)"[\\w:\\w*]",
+ PCRE2_ZERO_TERMINATED,
+ 0, /* compile flags */
+ &errcode,
+ &erroffset,
+ NULL /* general context */);
+ g_assert_nonnull (code);
+
+ pcre2_match_context_8* context = pcre2_match_context_create_8 (NULL);
+ pcre2_set_match_limit_8 (context, 256); /* plenty */
+
+ pcre2_match_data_8* data = pcre2_match_data_create_from_pattern_8 (code, NULL);
+
+ int matches = pcre2_match_8 (code,
+ (PCRE2_SPTR8)value,
+ PCRE2_ZERO_TERMINATED,
+ 0, /* start offset */
+ 0, /* match flags */
+ data,
+ context);
+
+ pcre2_match_context_free_8 (context);
+ pcre2_match_data_free_8 (data);
+ pcre2_code_free_8 (code);
+
+ if (matches <= 0) {
gtk_text_buffer_insert_with_tags_by_name (buffer, iter, value, -1,
"detail-value", NULL);
gtk_text_buffer_insert (buffer, iter, "\n", -1);
diff --git a/gucharmap/meson.build b/gucharmap/meson.build
index 873634fe..76e6f689 100644
--- a/gucharmap/meson.build
+++ b/gucharmap/meson.build
@@ -140,6 +140,7 @@ libgucharmap_gtk3_public_deps = [
gio_dep,
glib_dep,
gtk3_dep,
+ pcre2_dep,
]
libgucharmap_gtk3_deps = libgucharmap_gtk3_public_deps
diff --git a/meson.build b/meson.build
index 7f3f5ed4..9529f5d1 100644
--- a/meson.build
+++ b/meson.build
@@ -37,6 +37,7 @@ freetype2_req_version = '1.0'
gio_req_version = '2.32.0'
glib_req_version = '2.32.0'
gtk3_req_version = '3.4.0'
+pcre2_req_version = '10.21'
# NOTE! This is an exact requirement. Each gucharmap version (major.minor) is
# designed to work with, and only with, this unicode version. Upgrading to
@@ -231,9 +232,10 @@ endforeach
# Dependencies
-freetype2_dep = dependency('freetype2', version: '>=' + freetype2_req_version,)
-gio_dep = dependency('gio-2.0', version: '>=' + gio_req_version,)
-glib_dep = dependency('glib-2.0', version: '>=' + glib_req_version,)
+freetype2_dep = dependency('freetype2', version: '>=' + freetype2_req_version,)
+gio_dep = dependency('gio-2.0', version: '>=' + gio_req_version,)
+glib_dep = dependency('glib-2.0', version: '>=' + glib_req_version,)
+pcre2_dep = dependency('libpcre2-8', version: '>=' + pcre2_req_version)
if get_option('gtk3')
gtk3_dep = dependency('gtk+-3.0', version: '>=' + gtk3_req_version,)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]