[regexxer] Remove the dependency to libpcre.
- From: Fabien Parent <fparent src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [regexxer] Remove the dependency to libpcre.
- Date: Mon, 3 Jan 2011 18:30:36 +0000 (UTC)
commit 6996b0ef806d3a17adacd89964ef27db189af724
Author: Fabien Parent <parent f gmail com>
Date: Mon Jan 3 19:26:03 2011 +0100
Remove the dependency to libpcre.
Makefile.am | 2 -
configure.ac | 4 +-
src/filebuffer.cc | 18 +++--
src/filebuffer.h | 2 +-
src/fileshared.cc | 10 ++-
src/fileshared.h | 4 +-
src/filetree.cc | 7 +-
src/filetree.h | 6 +-
src/filetreeprivate.cc | 6 +-
src/filetreeprivate.h | 12 ++--
src/mainwindow.cc | 21 ++---
src/pcreshell.cc | 196 ------------------------------------------------
src/pcreshell.h | 148 ------------------------------------
13 files changed, 45 insertions(+), 391 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index c420083..b34c425 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -52,8 +52,6 @@ src_regexxer_SOURCES = \
src/mainwindow.cc \
src/mainwindow.h \
src/miscutils.h \
- src/pcreshell.cc \
- src/pcreshell.h \
src/prefdialog.cc \
src/prefdialog.h \
src/sharedptr.h \
diff --git a/configure.ac b/configure.ac
index 39eb81b..d78654a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -38,8 +38,8 @@ AM_GLIB_GNU_GETTEXT
# gmodule-export-2.0 adds -Wl,--export-dynamic to the linker flags
# so that libglade can get at the custom widget creation functions.
PKG_CHECK_MODULES([REGEXXER_MODULES],
- [gtk+-2.0 >= 2.16.0 gtkmm-2.4 >= 2.12.0 gconfmm-2.6 >= 2.6.1
- libpcre >= 5.0 gtksourceviewmm-2.0 >= 2.9.0])
+ [gtk+-2.0 >= 2.16.0 gtkmm-2.4 >= 2.12.0 glibmm-2.4 >= 2.27.4.1
+ gconfmm-2.6 >= 2.6.1 gtksourceviewmm-2.0 >= 2.9.0])
DK_PKG_PATH_PROG([GDK_PIXBUF_CSOURCE], [gdk-pixbuf-2.0], [gdk-pixbuf-csource])
DK_PKG_PATH_PROG([GTK_UPDATE_ICON_CACHE], [gtk+-2.0], [gtk-update-icon-cache])
diff --git a/src/filebuffer.cc b/src/filebuffer.cc
index f1ce216..69a237e 100644
--- a/src/filebuffer.cc
+++ b/src/filebuffer.cc
@@ -22,7 +22,6 @@
#include "filebufferundo.h"
#include "globalstrings.h"
#include "miscutils.h"
-#include "pcreshell.h"
#include "stringutils.h"
#include "translation.h"
@@ -254,7 +253,7 @@ bool FileBuffer::in_user_action() const
* If multiple is false then every line is matched only once, otherwise
* multiple matches per line will be found (like modifier /g in Perl).
*/
-int FileBuffer::find_matches(Pcre::Pattern& pattern, bool multiple,
+int FileBuffer::find_matches(const Glib::RefPtr<Glib::Regex>& pattern, bool multiple,
const sigc::slot<void, int, const Glib::ustring&>& feedback)
{
ScopedLock lock (*this);
@@ -292,10 +291,12 @@ int FileBuffer::find_matches(Pcre::Pattern& pattern, bool multiple,
return match_count_;
}
- const int capture_count =
- pattern.match(subject, offset, (last_was_empty) ? Pcre::ANCHORED | Pcre::NOT_EMPTY
- : Pcre::MatchOptions(0));
- if (capture_count <= 0)
+ Glib::MatchInfo match_info;
+ bool is_matched =
+ pattern->match(subject, offset, match_info,
+ (last_was_empty) ? Glib::REGEX_MATCH_ANCHORED | Glib::REGEX_MATCH_NOTEMPTY
+ : static_cast<Glib::RegexMatchFlags>(0));
+ if (!is_matched)
{
if (last_was_empty && unsigned(offset) < subject.bytes())
{
@@ -312,7 +313,8 @@ int FileBuffer::find_matches(Pcre::Pattern& pattern, bool multiple,
++match_count_;
++original_match_count_;
- const std::pair<int, int> bounds = pattern.get_substring_bounds(0);
+ std::pair<int, int> bounds;
+ match_info.fetch_pos(0, bounds.first, bounds.second);
iterator start = line;
iterator stop = line;
@@ -321,7 +323,7 @@ int FileBuffer::find_matches(Pcre::Pattern& pattern, bool multiple,
stop .set_line_index(bounds.second);
const MatchDataPtr match (new MatchData(
- original_match_count_, subject, pattern, capture_count));
+ original_match_count_, subject, match_info));
match_set_.insert(match_set_.end(), match);
match->install_mark(start);
diff --git a/src/filebuffer.h b/src/filebuffer.h
index f4b542d..b51111d 100644
--- a/src/filebuffer.h
+++ b/src/filebuffer.h
@@ -50,7 +50,7 @@ public:
bool is_freeable() const;
bool in_user_action() const;
- int find_matches(Pcre::Pattern& pattern, bool multiple,
+ int find_matches(const Glib::RefPtr<Glib::Regex>& pattern, bool multiple,
const sigc::slot<void, int, const Glib::ustring&>& feedback);
int get_match_count() const;
diff --git a/src/fileshared.cc b/src/fileshared.cc
index 30176c9..f69d267 100644
--- a/src/fileshared.cc
+++ b/src/fileshared.cc
@@ -19,7 +19,6 @@
*/
#include "fileshared.h"
-#include "pcreshell.h"
#include <glib.h>
#include <algorithm>
@@ -59,15 +58,20 @@ namespace Regexxer
/**** Regexxer::MatchData **************************************************/
MatchData::MatchData(int match_index, const Glib::ustring& line,
- const Pcre::Pattern& pattern, int capture_count)
+ Glib::MatchInfo& match_info)
:
index (match_index),
subject (line)
{
+ int capture_count = match_info.get_match_count();
captures.reserve(capture_count);
for (int i = 0; i < capture_count; ++i)
- captures.push_back(pattern.get_substring_bounds(i));
+ {
+ std::pair<int, int> bounds;
+ match_info.fetch_pos(i, bounds.first, bounds.second);
+ captures.push_back(bounds);
+ }
length = calculate_match_length(subject, captures.front());
}
diff --git a/src/fileshared.h b/src/fileshared.h
index 4674552..aa0698f 100644
--- a/src/fileshared.h
+++ b/src/fileshared.h
@@ -28,8 +28,6 @@
#include <utility>
#include <vector>
-namespace Pcre { class Pattern; }
-
namespace Regexxer
{
@@ -79,7 +77,7 @@ struct MatchData : public Util::SharedObject
Glib::RefPtr<Gtk::TextMark> mark;
MatchData(int match_index, const Glib::ustring& line,
- const Pcre::Pattern& pattern, int capture_count);
+ Glib::MatchInfo& match_info);
~MatchData();
void install_mark(const Gtk::TextBuffer::iterator& pos);
diff --git a/src/filetree.cc b/src/filetree.cc
index 7ec05cc..bef390e 100644
--- a/src/filetree.cc
+++ b/src/filetree.cc
@@ -21,7 +21,6 @@
#include "filetree.h"
#include "filetreeprivate.h"
#include "globalstrings.h"
-#include "pcreshell.h"
#include "stringutils.h"
#include "translation.h"
@@ -106,7 +105,7 @@ FileTree::FileTree()
FileTree::~FileTree()
{}
-void FileTree::find_files(const std::string& dirname, Pcre::Pattern& pattern,
+void FileTree::find_files(const std::string& dirname, const Glib::RefPtr<Glib::Regex>& pattern,
bool recursive, bool hidden)
{
FindData find_data (pattern, recursive, hidden);
@@ -224,7 +223,7 @@ BoundState FileTree::get_bound_state()
return bound;
}
-void FileTree::find_matches(Pcre::Pattern& pattern, bool multiple)
+void FileTree::find_matches(const Glib::RefPtr<Glib::Regex>& pattern, bool multiple)
{
{
Util::ScopedBlock block_conn (conn_match_count_);
@@ -391,7 +390,7 @@ void FileTree::find_recursively(const std::string& dirname, FindData& find_data)
{
const ustring basename = Glib::filename_display_basename(fullname);
- if (find_data.pattern.match(basename) > 0)
+ if (find_data.pattern->match(basename))
{
find_add_file(basename, fullname, find_data);
++file_count;
diff --git a/src/filetree.h b/src/filetree.h
index e665f46..369a0fd 100644
--- a/src/filetree.h
+++ b/src/filetree.h
@@ -33,7 +33,7 @@
#include <list>
namespace Gtk { class TreeStore; }
-namespace Pcre { class Pattern; }
+namespace Glib { class Regex; }
namespace Gnome { namespace Conf { class Value; } }
namespace Regexxer
@@ -47,7 +47,7 @@ public:
FileTree();
virtual ~FileTree();
- void find_files(const std::string& dirname, Pcre::Pattern& pattern,
+ void find_files(const std::string& dirname, const Glib::RefPtr<Glib::Regex>& pattern,
bool recursive, bool hidden);
int get_file_count() const;
@@ -60,7 +60,7 @@ public:
BoundState get_bound_state();
- void find_matches(Pcre::Pattern& pattern, bool multiple);
+ void find_matches(const Glib::RefPtr<Glib::Regex>& pattern, bool multiple);
long get_match_count() const;
void replace_all_matches(const Glib::ustring& substitution);
diff --git a/src/filetreeprivate.cc b/src/filetreeprivate.cc
index 05504e5..a14dc39 100644
--- a/src/filetreeprivate.cc
+++ b/src/filetreeprivate.cc
@@ -192,7 +192,8 @@ const std::list<Glib::ustring>& FileTree::Error::get_error_list() const
/**** Regexxer::FileTree::FindData *****************************************/
-FileTree::FindData::FindData(Pcre::Pattern& pattern_, bool recursive_, bool hidden_)
+FileTree::FindData::FindData(const Glib::RefPtr<Glib::Regex>& pattern_,
+ bool recursive_, bool hidden_)
:
pattern (pattern_),
recursive (recursive_),
@@ -205,7 +206,8 @@ FileTree::FindData::~FindData()
/**** Regexxer::FileTree::FindMatchesData **********************************/
-FileTree::FindMatchesData::FindMatchesData(Pcre::Pattern& pattern_, bool multiple_)
+FileTree::FindMatchesData::FindMatchesData(const Glib::RefPtr<Glib::Regex>& pattern_,
+ bool multiple_)
:
pattern (pattern_),
multiple (multiple_),
diff --git a/src/filetreeprivate.h b/src/filetreeprivate.h
index 5a04f13..aea0417 100644
--- a/src/filetreeprivate.h
+++ b/src/filetreeprivate.h
@@ -117,10 +117,10 @@ private:
struct FileTree::FindData
{
- FindData(Pcre::Pattern& pattern_, bool recursive_, bool hidden_);
+ FindData(const Glib::RefPtr<Glib::Regex>& pattern_, bool recursive_, bool hidden_);
~FindData();
- Pcre::Pattern& pattern;
+ const Glib::RefPtr<Glib::Regex>& pattern;
const bool recursive;
const bool hidden;
FileTreePrivate::DirStack dirstack;
@@ -133,11 +133,11 @@ private:
struct FileTree::FindMatchesData
{
- FindMatchesData(Pcre::Pattern& pattern_, bool multiple_);
+ FindMatchesData(const Glib::RefPtr<Glib::Regex>& pattern_, bool multiple_);
- Pcre::Pattern& pattern;
- const bool multiple;
- bool path_match_first_set;
+ const Glib::RefPtr<Glib::Regex>& pattern;
+ const bool multiple;
+ bool path_match_first_set;
private:
FindMatchesData(const FileTree::FindMatchesData&);
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index ffb3ff3..9221d9b 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -21,7 +21,6 @@
#include "mainwindow.h"
#include "filetree.h"
#include "globalstrings.h"
-#include "pcreshell.h"
#include "prefdialog.h"
#include "statusline.h"
#include "stringutils.h"
@@ -545,13 +544,15 @@ void MainWindow::on_find_files()
try
{
- Pcre::Pattern pattern (Util::shell_pattern_to_regex(combo_entry_pattern_->get_entry()->get_text()), Pcre::DOTALL);
+ Glib::RefPtr<Glib::Regex> pattern = Glib::Regex::create(
+ Util::shell_pattern_to_regex(combo_entry_pattern_->get_entry()->get_text()),
+ Glib::REGEX_DOTALL);
filetree_->find_files(folder, pattern,
button_recursive_->get_active(),
button_hidden_->get_active());
}
- catch (const Pcre::Error&)
+ catch (const Glib::RegexError&)
{
Gtk::MessageDialog dialog (*window_, _("The file search pattern is invalid."),
false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
@@ -580,24 +581,18 @@ void MainWindow::on_exec_search()
try
{
- Pcre::Pattern pattern (regex, (caseless) ? Pcre::CASELESS : Pcre::CompileOptions(0));
+ Glib::RefPtr<Glib::Regex> pattern =
+ Glib::Regex::create(regex, (caseless) ? Glib::REGEX_CASELESS
+ : static_cast<Glib::RegexCompileFlags>(0));
filetree_->find_matches(pattern, multiple);
}
- catch (const Pcre::Error& error)
+ catch (const Glib::RegexError& error)
{
Gtk::MessageDialog dialog (*window_, error.what(), false,
Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
dialog.run();
- const int offset = error.offset();
-
- if (offset >= 0 && offset < entry_regex_->get_text_length())
- {
- entry_regex_->grab_focus();
- entry_regex_->select_region(offset, offset + 1);
- }
-
return;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]