[gnote] NoteUrlWatcher now use PCRE



commit 68f7aa7c135ca0ef01d9d7e9f4b828d02a3f3c08
Author: Hubert Figuiere <hub figuiere net>
Date:   Fri Jun 5 22:24:40 2009 -0400

    NoteUrlWatcher now use PCRE
---
 README           |    1 +
 configure.ac     |    1 +
 src/Makefile.am  |    2 ++
 src/watchers.cpp |   22 +++++++++++++---------
 src/watchers.hpp |    4 +++-
 5 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/README b/README
index 230ef08..541b011 100644
--- a/README
+++ b/README
@@ -18,6 +18,7 @@ Dependencies:
 - libxslt
 - libuuid
 - boost 1.34
+- libpcrepp (part of pcre)
 - (optional) gtk-spell 2.0.9
 
 Importing Tomboy notes
diff --git a/configure.ac b/configure.ac
index bd59cca..2f5fc15 100644
--- a/configure.ac
+++ b/configure.ac
@@ -71,6 +71,7 @@ PKG_CHECK_MODULES(LIBGTKMM, [gtkmm-2.4 >= $LIBGTKMM_VERSION])
 PKG_CHECK_MODULES(LIBXML, [libxml-2.0])
 PKG_CHECK_MODULES(LIBXSLT, [libxslt])
 PKG_CHECK_MODULES(GCONF, [gconf-2.0])
+PKG_CHECK_MODULES(PCRE, [libpcrecpp])
 dnl PKG_CHECK_MODULES(LIBGLADEMM, [libglademm-2.4 >= $LIBGLADEMM_VERSION])
 dnl PKG_CHECK_MODULES(LIBGNOMEUI, [libgnomeui-2.0 >= $LIBGNOMEUI_VERSION])
 dnl PKG_CHECK_MODULES(LIBGCONFMM, [gconfmm-2.6 >= $LIBGCONFMM_VERSION])
diff --git a/src/Makefile.am b/src/Makefile.am
index 0db092c..1dd9ba7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,6 +9,7 @@ AM_CPPFLAGS= LIBGTKMM_CFLAGS@ @LIBGLIBMM_CFLAGS@ \
 	@GCONF_CFLAGS@ @GTK_CFLAGS@ \
 	@GTKSPELL_CFLAGS@ @LIBXML_CFLAGS@ \
 	@LIBXSLT_CFLAGS@ \
+	@PCRE_CFLAGS@ \
 	-DGNOTE_LOCALEDIR=\"@GNOTE_LOCALEDIR \" \
 	-DDATADIR=\"$(datadir)\" -DLIBDIR=\"$(libdir)\"
 
@@ -17,6 +18,7 @@ AM_LDFLAGS=-Wl,--export-dynamic
 GNOTE_LIBS = libgnote.a @LIBGLIBMM_LIBS@ @LIBGTKMM_LIBS@ \
 	@GCONF_LIBS@ @BOOST_FILESYSTEM_LIBS@ @BOOST_REGEX_LIBS@ \
 	@LIBXSLT_LIBS@ \
+	@PCRE_LIBS@ \
 	@GTKSPELL_LIBS@ @GTK_LIBS@ \
 	-luuid -L$(top_builddir)/libtomboy -ltomboy
 
diff --git a/src/watchers.cpp b/src/watchers.cpp
index 489dd3c..ceec756 100644
--- a/src/watchers.cpp
+++ b/src/watchers.cpp
@@ -390,7 +390,7 @@ namespace gnote {
   
 
   NoteUrlWatcher::NoteUrlWatcher()
-    : m_regex(URL_REGEX, boost::regex::perl|boost::regex_constants::icase)
+    : m_regex(URL_REGEX, pcrecpp::RE_Options(PCRE_CASELESS|PCRE_UTF8))
   {
   }
 
@@ -509,26 +509,30 @@ namespace gnote {
     get_buffer()->remove_tag (m_url_tag, start, end);
 
     std::string s(start.get_slice(end));
+    std::string match1;
 
-    boost::sregex_iterator m1(s.begin(), s.end(), m_regex);
-    boost::sregex_iterator m2;
-    while(m1 != m2) {
-      const boost::sub_match<std::string::const_iterator> & match = (*m1)[1];
+    DBG_OUT("input is %s", s.c_str());
+    const char *p = s.c_str();
+    pcrecpp::StringPiece input(p);
+
+    while(m_regex.FindAndConsume(&input, &match1)) {
+
+      DBG_OUT("match1 '%s'", match1.c_str());
 
       Gtk::TextIter start_cpy = start;
-      // must construct the Glib::ustring from a std:;string.
+      // must construct the Glib::ustring from a char *.
       // otherwise it expect the num of chars (UTF-8) instead of bytes.
-      Glib::ustring segment(std::string(s.c_str(), match.first - s.begin()));
+      // here we compute the index of the URL. It is anchor - start - match.
+      Glib::ustring segment(p, input.data() - p - match1.size());
       start_cpy.forward_chars (segment.size());
 
       end = start_cpy;
       // here match.str() is the std::string we need. All good.
-      Glib::ustring segment2(match.str());
+      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);
-      ++m1;
     }
   }
 
diff --git a/src/watchers.hpp b/src/watchers.hpp
index 2be76b6..6e0eb7e 100644
--- a/src/watchers.hpp
+++ b/src/watchers.hpp
@@ -29,6 +29,8 @@
 
 #include <boost/regex.hpp>
 
+#include <pcrecpp.h>
+
 #if FIXED_GTKSPELL
 extern "C" {
 #include <gtkspell/gtkspell.h>
@@ -155,7 +157,7 @@ namespace gnote {
 
     NoteTag::Ptr                m_url_tag;
     Glib::RefPtr<Gtk::TextMark> m_click_mark;
-    boost::regex                m_regex;
+    pcrecpp::RE                 m_regex;
     static const char * URL_REGEX;
     static bool  s_text_event_connected;
   };



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