Commit f24ccbaa authored by daniel_e's avatar daniel_e
Browse files

Show an error dialog if there is an error in the regex.

parent 2cbb7a54
2002-10-27 Daniel Elstner <daniel.elstner@gmx.net>
* src/stringutils.{cc,h} (int_to_string): New function.
* src/mainwindow.cc (on_exec_search): Show an error dialog if
there is an error in the regex.
2002-10-27 Daniel Elstner <daniel.elstner@gmx.net>
* src/mainwindow.cc (on_select_folder): Hide the file selection
......
......@@ -25,10 +25,10 @@
#include "statusline.h"
#include "stringutils.h"
#include <iostream>
#include <memory>
#include <glib.h>
#include <gtkmm.h>
#include <algorithm>
#include <iostream>
#include <config.h>
......@@ -470,17 +470,37 @@ void MainWindow::on_exec_search()
{
BusyAction busy (*this);
const Glib::ustring regex = entry_regex_->get_text();
const bool caseless = button_caseless_->get_active();
const bool multiple = button_multiple_->get_active();
try
{
Pcre::Pattern pattern (
entry_regex_->get_text(),
button_caseless_->get_active() ? Pcre::CASELESS : Pcre::CompileOptions(0));
filelist_->find_matches(pattern, button_multiple_->get_active());
Pcre::Pattern pattern (regex, (caseless) ? Pcre::CASELESS : Pcre::CompileOptions(0));
filelist_->find_matches(pattern, multiple);
}
catch(const Pcre::Error& e)
catch(const Pcre::Error& error)
{
std::cerr << e.what() << std::endl;
Glib::ustring message = "Error in regular expression";
const int offset = error.offset();
if(offset >= 0 && unsigned(offset) < regex.bytes())
{
const Glib::ustring::const_iterator pos (regex.begin().base() + offset);
message += " at \302\273";
message += *pos;
message += "\302\253 (index ";
message += Util::int_to_string(std::distance(regex.begin(), pos) + 1);
message += ")";
}
message += ":\n";
message += error.what();
Gtk::MessageDialog dialog (*this, message, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
dialog.run();
return;
}
......
......@@ -20,11 +20,14 @@
#include "stringutils.h"
#include <glib/gmessages.h>
#include <glibmm.h>
#include <algorithm>
#include <sstream>
#include <utility>
#include <vector>
#include <glib/gmessages.h>
#include <glibmm.h>
#include <config.h>
namespace
......@@ -508,6 +511,19 @@ Glib::ustring Util::convert_to_ascii(const std::string& str)
return result;
}
Glib::ustring Util::int_to_string(int number)
{
std::ostringstream output;
#if REGEXXER_HAVE_STD_LOCALE
output.imbue(std::locale(""));
#endif
output << number;
return Glib::locale_to_utf8(output.str());
}
Glib::ustring Util::transform_pathname(const Glib::ustring& path, bool shorten)
{
using namespace Glib;
......
......@@ -41,6 +41,7 @@ std::string substitute_references(const std::string& substitution,
Glib::ustring filename_to_utf8_fallback(const std::string& filename);
Glib::ustring convert_to_ascii(const std::string& str);
Glib::ustring int_to_string(int number);
Glib::ustring transform_pathname(const Glib::ustring& path, bool shorten);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment