summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMurray Cumming <murrayc@murrayc.com>2007-06-22 14:43:53 +0000
committerMurray Cumming <murrayc@src.gnome.org>2007-06-22 14:43:53 +0000
commitc72439e0d5963fd6200283a906b32300f2ab65b6 (patch)
tree3e3282e4d1b8ddc6384ff43e1b8f124584090a01
parentfdba92ddd4221df38d48677063af8d1de5939e5a (diff)
downloadglibmm-c72439e0d5963fd6200283a906b32300f2ab65b6.tar.gz
Added a create() method, and added some more default parameter values to
2007-06-22 Murray Cumming <murrayc@murrayc.com> * glib/src/regex.ccg: * glib/src/regex.hg: Added a create() method, and added some more default parameter values to the methods. * configure.in: * examples/Makefile.am: * examples/regex/main.cc: Added a very simple example. * glib/glibmm/value_custom.h: Put header guards around this, though this should never be included directly anyway. svn path=/trunk/; revision=419
-rw-r--r--ChangeLog13
-rw-r--r--configure.in1
-rw-r--r--examples/Makefile.am2
-rw-r--r--examples/regex/Makefile.am6
-rw-r--r--examples/regex/main.cc49
-rw-r--r--glib/glibmm/value_custom.h6
-rw-r--r--glib/src/regex.ccg20
-rw-r--r--glib/src/regex.hg11
8 files changed, 105 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index d448ac95..df71b551 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2007-06-22 Murray Cumming <murrayc@murrayc.com>
+
+ * glib/src/regex.ccg:
+ * glib/src/regex.hg: Added a create() method, and added some
+ more default parameter values to the methods.
+
+ * configure.in:
+ * examples/Makefile.am:
+ * examples/regex/main.cc: Added a very simple example.
+
+ * glib/glibmm/value_custom.h: Put header guards around this, though
+ this should never be included directly anyway.
+
2.13.6:
2007-06-17 Murray Cumming <murrayc@murrayc.com>
diff --git a/configure.in b/configure.in
index 663fe6f7..48061f6d 100644
--- a/configure.in
+++ b/configure.in
@@ -271,6 +271,7 @@ AC_CONFIG_FILES([
examples/thread/Makefile
examples/iochannel_stream/Makefile
examples/child_watch/Makefile
+ examples/regex/Makefile
scripts/Makefile
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 79d9c73a..02679415 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1,4 +1,4 @@
-example_dirs = markup options thread iochannel_stream child_watch
+example_dirs = markup options thread iochannel_stream child_watch regex
# These use gtkmm stuff:
# thread
diff --git a/examples/regex/Makefile.am b/examples/regex/Makefile.am
new file mode 100644
index 00000000..0c79f50b
--- /dev/null
+++ b/examples/regex/Makefile.am
@@ -0,0 +1,6 @@
+include $(top_srcdir)/examples/Makefile.am_fragment
+
+#Build the executable, but don't install it.
+noinst_PROGRAMS = example
+example_SOURCES = main.cc
+
diff --git a/examples/regex/main.cc b/examples/regex/main.cc
new file mode 100644
index 00000000..c5c5e24d
--- /dev/null
+++ b/examples/regex/main.cc
@@ -0,0 +1,49 @@
+/* Copyright (C) 2004 The glibmm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <glibmm.h>
+#include <iostream>
+
+Glib::ustring bool_text (bool val)
+{
+ return val ? "true" : "false";
+}
+
+int main(int argc, char** argv)
+{
+ Glib::init();
+
+ /* Reusing one regex pattern: */
+ Glib::RefPtr<Glib::Regex> regex = Glib::Regex::create ("(a)?(b)");
+ std::cout << "Pattern=" << regex->get_pattern()
+ << ", with string=abcd, result="
+ << bool_text( regex->match("abcd") )
+ << std::endl;
+ std::cout << "Pattern=" << regex->get_pattern()
+ << ", with string=1234, result="
+ << bool_text( regex->match("1234") )
+ << std::endl;
+ std::cout << std::endl;
+
+ /* Using the static function without a regex instance: */
+ std::cout << "Pattern=b* with string=abcd, result="
+ << bool_text( Glib::Regex::match_simple("b*", "abcd") )
+ << std::endl;
+
+ return 0;
+}
+
diff --git a/glib/glibmm/value_custom.h b/glib/glibmm/value_custom.h
index ab4ad7d5..e695dc0f 100644
--- a/glib/glibmm/value_custom.h
+++ b/glib/glibmm/value_custom.h
@@ -18,6 +18,9 @@
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#ifndef _GLIBMM_VALUE_CUSTOM_H
+#define _GLIBMM_VALUE_CUSTOM_H
+
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#ifndef _GLIBMM_VALUE_H_INCLUDE_VALUE_CUSTOM_H
#error "glibmm/value_custom.h cannot be included directly"
@@ -287,3 +290,6 @@ void Value<T>::value_copy_func(const GValue* src_value, GValue* dest_value)
} // namespace Glib
+#endif //_GLIBMM_VALUE_CUSTOM_H
+
+
diff --git a/glib/src/regex.ccg b/glib/src/regex.ccg
index e0591f64..6e9cae4e 100644
--- a/glib/src/regex.ccg
+++ b/glib/src/regex.ccg
@@ -20,6 +20,26 @@
namespace Glib
{
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+Glib::RefPtr<Glib::Regex> Regex::create(const Glib::ustring& pattern, RegexCompileFlags compile_options, RegexMatchFlags match_options)
+#else
+Glib::RefPtr<Glib::Regex> Regex::create(const Glib::ustring& pattern, RegexCompileFlags compile_options, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+{
+ GError* gerror = NULL;
+ GRegex* regex = g_regex_new(pattern.c_str(), (GRegexCompileFlags)compile_options, (GRegexMatchFlags)match_options, &gerror);
+
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+ if(gerror)
+ ::Glib::Error::throw_exception(gerror);
+#else
+ if(gerror)
+ error = ::Glib::Error::throw_exception(gerror);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+
+ return Glib::wrap(regex);
+}
+
bool Regex::match(const Glib::ustring& string, RegexMatchFlags match_options)
{
return g_regex_match(gobj(), string.c_str(), ((GRegexMatchFlags)(match_options)), NULL);
diff --git a/glib/src/regex.hg b/glib/src/regex.hg
index eafe8cb8..9a87957d 100644
--- a/glib/src/regex.hg
+++ b/glib/src/regex.hg
@@ -50,6 +50,13 @@ class Regex
_IGNORE(g_regex_ref, g_regex_unref)
public:
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+ static Glib::RefPtr<Glib::Regex> create(const Glib::ustring& pattern, RegexCompileFlags compile_options = (RegexCompileFlags)0, RegexMatchFlags match_options = (RegexMatchFlags)0);
+#else
+ static Glib::RefPtr<Glib::Regex> create(const Glib::ustring& pattern, RegexCompileFlags compile_options = (RegexCompileFlags)0, RegexMatchFlags match_options = (RegexMatchFlags)0, std::auto_ptr<Glib::Error>& error)
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+
+
_WRAP_METHOD(Glib::ustring get_pattern() const, g_regex_get_pattern)
_WRAP_METHOD(int get_max_backref() const, g_regex_get_max_backref)
_WRAP_METHOD(int get_capture_count() const, g_regex_get_capture_count)
@@ -58,7 +65,7 @@ public:
//TODO: _WRAP_METHOD(static Glib::ustring escape_string(const Glib::ustring& string, gint length) const, g_regex_escape_string)
/* Matching. */
- _WRAP_METHOD(static bool match_simple(const Glib::ustring& pattern, const Glib::ustring& string, RegexCompileFlags compile_options, RegexMatchFlags match_options = (RegexMatchFlags)0), g_regex_match_simple)
+ _WRAP_METHOD(static bool match_simple(const Glib::ustring& pattern, const Glib::ustring& string, RegexCompileFlags compile_options = (RegexCompileFlags)0, RegexMatchFlags match_options = (RegexMatchFlags)0), g_regex_match_simple)
//TODO: _WRAP_METHOD(bool match(const Glib::ustring& string, RegexMatchFlags match_options = (RegexMatchFlags)0, GMatchInfo **match_info = 0), g_regex_match)
bool match(const Glib::ustring& string, RegexMatchFlags match_options = (RegexMatchFlags)0);
@@ -98,7 +105,7 @@ public:
#m4 _CONVERSION(`gchar**',`Glib::StringArrayHandle',`Glib::StringArrayHandle($3, Glib::OWNERSHIP_DEEP)')
- _WRAP_METHOD(static Glib::StringArrayHandle split_simple(const Glib::ustring& pattern, const Glib::ustring& string, RegexCompileFlags compile_options, RegexMatchFlags match_options = (RegexMatchFlags)0), g_regex_split_simple)
+ _WRAP_METHOD(static Glib::StringArrayHandle split_simple(const Glib::ustring& pattern, const Glib::ustring& string, RegexCompileFlags compile_options = (RegexCompileFlags)0, RegexMatchFlags match_options = (RegexMatchFlags)0), g_regex_split_simple)
_WRAP_METHOD(Glib::StringArrayHandle split(const Glib::ustring& string, RegexMatchFlags match_options = (RegexMatchFlags)0), g_regex_split)
_WRAP_METHOD(Glib::StringArrayHandle split_full(const gchar* string, gssize string_len, int start_position, RegexMatchFlags match_options = (RegexMatchFlags)0, int max_tokens = 0) const, g_regex_split_full, errthrow)