[gnote] Drop dependency on libpcrecpp
- From: Aurimas Äernius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Drop dependency on libpcrecpp
- Date: Mon, 6 Aug 2012 18:24:55 +0000 (UTC)
commit b0615a81b3579cbea2f905227161618950d680aa
Author: Aurimas Äernius <aurisc4 gmail com>
Date: Mon Aug 6 21:23:31 2012 +0300
Drop dependency on libpcrecpp
Replace it's usage by Glib equivalents.
configure.ac | 1 -
src/Makefile.am | 8 +--
src/addins/bugzilla/bugzillanoteaddin.cpp | 25 +++++----
src/sharp/string.cpp | 18 ++++---
src/synchronization/syncutils.cpp | 5 +-
src/test/stringtest.cpp | 3 +-
src/watchers.cpp | 80 +++++++++++++----------------
src/watchers.hpp | 10 ++--
8 files changed, 69 insertions(+), 81 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 67ff37f..0ea6a75 100644
--- a/configure.ac
+++ b/configure.ac
@@ -73,7 +73,6 @@ PKG_CHECK_EXISTS(glib-2.0 >= 2.32,
])
PKG_CHECK_MODULES(LIBXML, [libxml-2.0])
PKG_CHECK_MODULES(LIBXSLT, [libxslt])
-PKG_CHECK_MODULES(PCRE, [libpcrecpp])
PKG_CHECK_MODULES(UUID, [uuid])
#GtkSpell disabled until GTK 3.0 is supported
diff --git a/src/Makefile.am b/src/Makefile.am
index 03020bb..e43469c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,7 +7,6 @@ AM_CPPFLAGS= LIBGTKMM_CFLAGS@ @LIBGLIBMM_CFLAGS@ \
@GTK_CFLAGS@ \
@GTKSPELL_CFLAGS@ @LIBXML_CFLAGS@ \
@LIBXSLT_CFLAGS@ \
- @PCRE_CFLAGS@ \
@UUID_CFLAGS@ \
@GNOME_KEYRING_CFLAGS@ \
-DGNOTE_LOCALEDIR=\"@GNOTE_LOCALEDIR \" \
@@ -18,7 +17,6 @@ AM_LDFLAGS=-export-dynamic
LIBGNOTE_LIBS = $(top_builddir)/libtomboy/libtomboy.la \
@LIBGLIBMM_LIBS@ @LIBGTKMM_LIBS@ \
@LIBXSLT_LIBS@ \
- @PCRE_LIBS@ \
@GTKSPELL_LIBS@ @GTK_LIBS@ \
@UUID_LIBS@ \
@GNOME_KEYRING_LIBS@
@@ -33,13 +31,13 @@ TESTS = trietest stringtest notetest dttest uritest filestest \
trietest_SOURCES = test/trietest.cpp
-trietest_LDADD = libgnote.la @PCRE_LIBS@ @LIBGLIBMM_LIBS@
+trietest_LDADD = libgnote.la @LIBGLIBMM_LIBS@
dttest_SOURCES = test/dttest.cpp
dttest_LDADD = libgnote.la @LIBGLIBMM_LIBS@
stringtest_SOURCES = test/stringtest.cpp
-stringtest_LDADD = libgnote.la @PCRE_LIBS@ @LIBGLIBMM_LIBS@
+stringtest_LDADD = libgnote.la @LIBGLIBMM_LIBS@
filestest_SOURCES = test/filestest.cpp
filestest_LDADD = libgnote.la @LIBGLIBMM_LIBS@ -lgiomm-2.4
@@ -48,7 +46,7 @@ fileinfotest_SOURCES = test/fileinfotest.cpp
fileinfotest_LDADD = libgnote.la @LIBGLIBMM_LIBS@ -lgiomm-2.4
uritest_SOURCES = test/uritest.cpp
-uritest_LDADD = libgnote.la @PCRE_LIBS@ @LIBGLIBMM_LIBS@
+uritest_LDADD = libgnote.la @LIBGLIBMM_LIBS@
xmlreadertest_SOURCES = test/xmlreadertest.cpp
xmlreadertest_LDADD = libgnote.la @LIBXML_LIBS@
diff --git a/src/addins/bugzilla/bugzillanoteaddin.cpp b/src/addins/bugzilla/bugzillanoteaddin.cpp
index c398a13..77dd718 100644
--- a/src/addins/bugzilla/bugzillanoteaddin.cpp
+++ b/src/addins/bugzilla/bugzillanoteaddin.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2010 Aurimas Cernius
+ * Copyright (C) 2010,2012 Aurimas Cernius
* Copyright (C) 2010 Debarshi Ray
* Copyright (C) 2009 Hubert Figuiere
*
@@ -23,8 +23,6 @@
#include <boost/lexical_cast.hpp>
-#include <pcrecpp.h>
-
#include <glib.h>
#include <glibmm/i18n.h>
@@ -163,18 +161,21 @@ namespace bugzilla {
const char * regexString = "\\bhttps?://.*/show_bug\\.cgi\\?(\\S+\\&){0,1}id=(\\d{1,})";
- pcrecpp::RE re(regexString, pcrecpp::RE_Options(PCRE_CASELESS|PCRE_UTF8));
- int m;
-
- if(re.FullMatch(uriString, (void*)NULL, &m)) {
+ Glib::RefPtr<Glib::Regex> re = Glib::Regex::create(regexString, Glib::REGEX_CASELESS);
+ Glib::MatchInfo match_info;
- int bugId = m;
+ if(re->match(uriString, match_info) && match_info.get_match_count() >= 3) {
+ try {
+ int bugId = boost::lexical_cast<int>(match_info.fetch(2));
- if (insert_bug (x, y, uriString, bugId)) {
- context->drag_finish(true, false, time);
- g_signal_stop_emission_by_name(get_window()->editor()->gobj(),
- "drag_data_received");
+ if (insert_bug (x, y, uriString, bugId)) {
+ context->drag_finish(true, false, time);
+ g_signal_stop_emission_by_name(get_window()->editor()->gobj(),
+ "drag_data_received");
+ }
}
+ catch(std::bad_cast&)
+ {}
}
}
diff --git a/src/sharp/string.cpp b/src/sharp/string.cpp
index 92244d9..f2c9cf6 100644
--- a/src/sharp/string.cpp
+++ b/src/sharp/string.cpp
@@ -1,6 +1,7 @@
/*
* gnote
*
+ * Copyright (C) 2012 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -28,6 +29,7 @@
#include "sharp/string.hpp"
+#include <glibmm.h>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/predicate.hpp>
@@ -35,8 +37,6 @@
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/trim.hpp>
-#include <pcrecpp.h>
-
#include "debug.hpp"
namespace sharp {
@@ -58,16 +58,18 @@ namespace sharp {
const std::string & regex,
const std::string & with)
{
- pcrecpp::RE re(regex);
- std::string result = source;
- re.Replace(with, &result);
- return result;
+ Glib::RefPtr<Glib::Regex> re = Glib::Regex::create(regex);
+ return re->replace(source, 0, with, static_cast<Glib::RegexMatchFlags>(0));
}
bool string_match_iregex(const std::string & source, const std::string & regex)
{
- pcrecpp::RE re(regex, pcrecpp::RE_Options(PCRE_CASELESS|PCRE_UTF8));
- return re.FullMatch(source);
+ Glib::RefPtr<Glib::Regex> re = Glib::Regex::create(regex, Glib::REGEX_CASELESS);
+ Glib::MatchInfo match_info;
+ if(re->match(source)) {
+ return match_info.fetch(0) == source;
+ }
+ return false;
}
void string_split(std::vector<std::string> & split, const std::string & source,
diff --git a/src/synchronization/syncutils.cpp b/src/synchronization/syncutils.cpp
index a4a1486..1cf2c25 100644
--- a/src/synchronization/syncutils.cpp
+++ b/src/synchronization/syncutils.cpp
@@ -24,7 +24,6 @@
#include <glibmm.h>
#include <glibmm/i18n.h>
-#include <pcrecpp.h>
#include "debug.hpp"
#include "syncutils.hpp"
@@ -121,8 +120,8 @@ namespace sync {
fsOutput += "\n" + line;
}
file.close();
- pcrecpp::RE re("\\s+fuse\\s+", pcrecpp::RE_Options(PCRE_MULTILINE|PCRE_UTF8));
- return re.PartialMatch(fsOutput);
+ Glib::RefPtr<Glib::Regex> re = Glib::Regex::create("\\s+fuse\\s+", Glib::REGEX_MULTILINE);
+ return re->match(fsOutput);
}
}
catch(...) {}
diff --git a/src/test/stringtest.cpp b/src/test/stringtest.cpp
index 5a05e01..ba1242a 100644
--- a/src/test/stringtest.cpp
+++ b/src/test/stringtest.cpp
@@ -1,6 +1,7 @@
/*
* gnote
*
+ * Copyright (C) 2012 Aurimas Cernius
* Copyright (C) 2010 Debarshi Ray
* Copyright (C) 2009 Hubert Figuiere
*
@@ -40,7 +41,7 @@ int test_main(int /*argc*/, char ** /*argv*/)
#if 0
BOOST_CHECK(string_match_iregex(test4, "^Camel"));
#endif
- BOOST_CHECK(string_replace_regex(test4, "([aem])", "Xx") == "CXxmelCase");
+ BOOST_CHECK(string_replace_regex(test4, "([aem])", "Xx") == "CXxXxXxlCXxsXx");
std::cout << string_replace_regex(test4, "([aem])", "Xx") << std::endl;
BOOST_CHECK(string_replace_regex(test4, "ame", "Xx") == "CXxlCase");
std::cout << string_replace_regex(test4, "ame", "Xx") << std::endl;
diff --git a/src/watchers.cpp b/src/watchers.cpp
index 8c37419..16fdc68 100644
--- a/src/watchers.cpp
+++ b/src/watchers.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2010-2011 Aurimas Cernius
+ * Copyright (C) 2010-2012 Aurimas Cernius
* Copyright (C) 2010 Debarshi Ray
* Copyright (C) 2009 Hubert Figuiere
*
@@ -393,7 +393,7 @@ namespace gnote {
NoteUrlWatcher::NoteUrlWatcher()
- : m_regex(URL_REGEX, pcrecpp::RE_Options(PCRE_CASELESS|PCRE_UTF8))
+ : m_regex(Glib::Regex::create(URL_REGEX, Glib::REGEX_CASELESS))
{
}
@@ -507,29 +507,23 @@ namespace gnote {
get_buffer()->remove_tag (m_url_tag, start, end);
- std::string s(start.get_slice(end));
- std::string match1;
+ Glib::ustring s(start.get_slice(end));
+ Glib::MatchInfo match_info;
+ while(m_regex->match(s, match_info)) {
+ Glib::ustring match = match_info.fetch(0);
+ Glib::ustring::size_type start_pos = s.find(match);
- const char *p = s.c_str();
- pcrecpp::StringPiece input(p);
+ Gtk::TextIter start_cpy = start;
+ start_cpy.forward_chars(start_pos);
- while(m_regex.FindAndConsume(&input, &match1)) {
+ Gtk::TextIter end_cpy = start_cpy;
+ end_cpy.forward_chars(match.size());
- Gtk::TextIter start_cpy = start;
- // must construct the Glib::ustring from a char *.
- // otherwise it expect the num of chars (UTF-8) instead of bytes.
- // here we compute the index of the URL. It is anchor - start - match.
- Glib::ustring::size_type len = input.data() - p - match1.size();
- Glib::ustring segment(p, p + len);
- start_cpy.forward_chars (segment.size());
-
- end = start_cpy;
- // here match.str() is the std::string we need. All good.
- Glib::ustring segment2(match1);
- end.forward_chars (segment2.length());
-
- DBG_OUT("url is %s", segment2.c_str());
- get_buffer()->apply_tag (m_url_tag, start_cpy, end);
+ DBG_OUT("url is %s", start_cpy.get_slice(end_cpy).c_str());
+ get_buffer()->apply_tag(m_url_tag, start_cpy, end_cpy);
+
+ start = end_cpy;
+ s = start.get_slice(end);
}
}
@@ -553,12 +547,10 @@ namespace gnote {
{
if(tag != m_url_tag)
return;
- std::string s(start.get_slice(end));
- std::string match1;
- const char *p = s.c_str();
- pcrecpp::StringPiece input(p);
- if(!m_regex.FindAndConsume(&input, &match1))
- get_buffer()->remove_tag (m_url_tag, start, end);
+ Glib::ustring s(start.get_slice(end));
+ if(!m_regex->match(s)) {
+ get_buffer()->remove_tag(m_url_tag, start, end);
+ }
}
@@ -1003,33 +995,31 @@ namespace gnote {
get_buffer()->remove_tag (m_broken_link_tag, start, end);
- std::string s(start.get_slice(end));
- std::string match;
- const char * p = s.c_str();
- pcrecpp::StringPiece input(p);
-
-
- while(m_regex.FindAndConsume(&input, &match)) {
+ Glib::ustring s(start.get_slice(end));
+ Glib::MatchInfo match_info;
+ while(m_regex->match(s, match_info)) {
+ Glib::ustring match = match_info.fetch(0);
+ Glib::ustring::size_type start_pos = s.find(match);
Gtk::TextIter start_cpy = start;
- Glib::ustring::size_type len = input.data() - p - match.size();
- Glib::ustring segment(p, p + len);
- start_cpy.forward_chars (segment.length());
+ start_cpy.forward_chars(start_pos);
- end = start_cpy;
- segment = match;
- end.forward_chars (segment.length());
+ Gtk::TextIter end_cpy = start_cpy;
+ end_cpy.forward_chars(match.size());
if(get_note()->get_tag_table()->has_link_tag(start_cpy)) {
- break;
+ break;
}
DBG_OUT("Highlighting wikiword: '%s' at offset %d",
- match.c_str(), int(segment.length()));
+ start_cpy.get_slice(end_cpy).c_str(), int(start_pos));
- if (!manager().find(match)) {
- get_buffer()->apply_tag (m_broken_link_tag, start_cpy, end);
+ if(!manager().find(match)) {
+ get_buffer()->apply_tag (m_broken_link_tag, start_cpy, end_cpy);
}
+
+ start = end_cpy;
+ s = start.get_slice(end);
}
}
diff --git a/src/watchers.hpp b/src/watchers.hpp
index b97b7b7..4d57a59 100644
--- a/src/watchers.hpp
+++ b/src/watchers.hpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2010-2011 Aurimas Cernius
+ * Copyright (C) 2010-2012 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -28,8 +28,6 @@
#include <config.h>
#endif
-#include <pcrecpp.h>
-
#if FIXED_GTKSPELL
extern "C" {
#include <gtkspell/gtkspell.h>
@@ -157,7 +155,7 @@ namespace gnote {
NoteTag::Ptr m_url_tag;
Glib::RefPtr<Gtk::TextMark> m_click_mark;
- pcrecpp::RE m_regex;
+ Glib::RefPtr<Glib::Regex> m_regex;
static const char * URL_REGEX;
static bool s_text_event_connected;
};
@@ -213,7 +211,7 @@ namespace gnote {
protected:
NoteWikiWatcher()
- : m_regex(WIKIWORD_REGEX, pcrecpp::RE_Options(PCRE_UTF8))
+ : m_regex(Glib::Regex::create(WIKIWORD_REGEX))
{
}
private:
@@ -225,7 +223,7 @@ namespace gnote {
static const char * WIKIWORD_REGEX;
Glib::RefPtr<Gtk::TextTag> m_broken_link_tag;
- pcrecpp::RE m_regex;
+ Glib::RefPtr<Glib::Regex> m_regex;
sigc::connection m_on_insert_text_cid;
sigc::connection m_on_delete_range_cid;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]