summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Elstner <danielk@openismus.com>2007-09-12 14:12:03 +0000
committerMurray Cumming <murrayc@src.gnome.org>2007-09-12 14:12:03 +0000
commit7c3d8c926c65411b57514cfa01a27e7a45abb51b (patch)
treef8e6b18ec658ac8d1a1ed3026f1999eddf37f5d1
parentf73390bfac30242a4d11306f5ca65637e1293a1f (diff)
downloadglibmm-7c3d8c926c65411b57514cfa01a27e7a45abb51b.tar.gz
Some cosmetic cleanup. Also replace C-style casts in default argument
2007-09-06 Daniel Elstner <danielk@openismus.com> * glib/src/regex.{ccg,hg} (Regex): Some cosmetic cleanup. Also replace C-style casts in default argument values with static_cast<>. (escape_string): Wrap missing function. (match_full): Rename to and add as overloads of match(). (match_all_full): Rename to and add as overloads of match_all(). (split_full): Rename to and add as overloads of split(). svn path=/trunk/; revision=443
-rw-r--r--ChangeLog9
-rw-r--r--glib/src/regex.ccg72
-rw-r--r--glib/src/regex.hg100
3 files changed, 96 insertions, 85 deletions
diff --git a/ChangeLog b/ChangeLog
index 96cc095b..b5877749 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2007-09-06 Daniel Elstner <danielk@openismus.com>
+
+ * glib/src/regex.{ccg,hg} (Regex): Some cosmetic cleanup. Also
+ replace C-style casts in default argument values with static_cast<>.
+ (escape_string): Wrap missing function.
+ (match_full): Rename to and add as overloads of match().
+ (match_all_full): Rename to and add as overloads of match_all().
+ (split_full): Rename to and add as overloads of split().
+
2007-09-03 Daniel Elstner <danielk@openismus.com>
* glib/glibmm/ustring.cc (ustring::FormatStream::FormatStream): Use
diff --git a/glib/src/regex.ccg b/glib/src/regex.ccg
index 6e9cae4e..e087365e 100644
--- a/glib/src/regex.ccg
+++ b/glib/src/regex.ccg
@@ -21,39 +21,51 @@ 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
+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);
+ GError* gerror = 0;
+ 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);
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+ Glib::Error::throw_exception(gerror);
#else
- if(gerror)
- error = ::Glib::Error::throw_exception(gerror);
-#endif //GLIBMM_EXCEPTIONS_ENABLED
-
+ error = Glib::Error::throw_exception(gerror);
+#endif
return Glib::wrap(regex);
}
+// static
+Glib::ustring Regex::escape_string(const Glib::ustring& string)
+{
+ const Glib::ScopedPtr<char> buf (g_regex_escape_string(string.raw().c_str(),
+ string.raw().size()));
+ return Glib::ustring(buf.get());
+}
+
bool Regex::match(const Glib::ustring& string, RegexMatchFlags match_options)
{
- return g_regex_match(gobj(), string.c_str(), ((GRegexMatchFlags)(match_options)), NULL);
+ return g_regex_match(gobj(), string.c_str(), (GRegexMatchFlags)(match_options), 0);
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
-bool Regex::match_full(const Glib::ustring& string, int start_position, RegexMatchFlags match_options)
+bool Regex::match(const Glib::ustring& string, int start_position, RegexMatchFlags match_options)
#else
-bool Regex::match_full(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
+bool Regex::match(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
- bool retvalue = g_regex_match_full(gobj(), string.c_str(), -1, start_position, ((GRegexMatchFlags)(match_options)), NULL, &(gerror));
+ bool retvalue = g_regex_match_full(gobj(), string.c_str(), -1, start_position, ((GRegexMatchFlags)(match_options)), 0, &(gerror));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror)
::Glib::Error::throw_exception(gerror);
@@ -66,13 +78,13 @@ bool Regex::match_full(const Glib::ustring& string, int start_position, RegexMat
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
-bool Regex::match_full(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options)
+bool Regex::match(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options)
#else
-bool Regex::match_full(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
+bool Regex::match(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
- bool retvalue = g_regex_match_full(gobj(), string.c_str(), string_len, start_position, ((GRegexMatchFlags)(match_options)), NULL, &(gerror));
+ bool retvalue = g_regex_match_full(gobj(), string.c_str(), string_len, start_position, ((GRegexMatchFlags)(match_options)), 0, &(gerror));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror)
::Glib::Error::throw_exception(gerror);
@@ -87,18 +99,18 @@ bool Regex::match_full(const Glib::ustring& string, gssize string_len, int start
bool Regex::match_all(const Glib::ustring& string, RegexMatchFlags match_options)
{
- return g_regex_match_all(gobj(), string.c_str(), ((GRegexMatchFlags)(match_options)), NULL);
+ return g_regex_match_all(gobj(), string.c_str(), ((GRegexMatchFlags)(match_options)), 0);
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
-bool Regex::match_all_full(const Glib::ustring& string, int start_position, RegexMatchFlags match_options)
+bool Regex::match_all(const Glib::ustring& string, int start_position, RegexMatchFlags match_options)
#else
-bool Regex::match_all_full(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
+bool Regex::match_all(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
- bool retvalue = g_regex_match_all_full(gobj(), string.c_str(), -1, start_position, ((GRegexMatchFlags)(match_options)), NULL, &(gerror));
+ bool retvalue = g_regex_match_all_full(gobj(), string.c_str(), -1, start_position, ((GRegexMatchFlags)(match_options)), 0, &(gerror));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror)
::Glib::Error::throw_exception(gerror);
@@ -111,13 +123,13 @@ bool Regex::match_all_full(const Glib::ustring& string, int start_position, Rege
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
-bool Regex::match_all_full(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options)
+bool Regex::match_all(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options)
#else
-bool Regex::match_all_full(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
+bool Regex::match_all(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
- bool retvalue = g_regex_match_all_full(gobj(), string.c_str(), string_len, start_position, ((GRegexMatchFlags)(match_options)), NULL, &(gerror));
+ bool retvalue = g_regex_match_all_full(gobj(), string.c_str(), string_len, start_position, ((GRegexMatchFlags)(match_options)), 0, &(gerror));
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror)
::Glib::Error::throw_exception(gerror);
@@ -171,9 +183,9 @@ Glib::ustring Regex::replace_literal(const Glib::ustring& string, int start_posi
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
-Glib::StringArrayHandle Regex::split_full(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, int max_tokens) const
+Glib::StringArrayHandle Regex::split(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, int max_tokens) const
#else
-Glib::StringArrayHandle Regex::split_full(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, int max_tokens, std::auto_ptr<Glib::Error>& error) const
+Glib::StringArrayHandle Regex::split(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, int max_tokens, std::auto_ptr<Glib::Error>& error) const
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
@@ -189,6 +201,4 @@ Glib::StringArrayHandle Regex::split_full(const Glib::ustring& string, int start
return retvalue;
}
-
-
-} //namespace Glib
+} // namespace Glib
diff --git a/glib/src/regex.hg b/glib/src/regex.hg
index e9e4c3a7..5b029a8f 100644
--- a/glib/src/regex.hg
+++ b/glib/src/regex.hg
@@ -21,13 +21,11 @@ _DEFS(glibmm,glib)
#include <glibmm/ustring.h>
#include <glibmm/error.h>
#include <glibmm/arrayhandle.h>
-//#include <glibmm/value.h>
-
#include <glib/gregex.h>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef struct _GRegex GRegex;
-#endif //DOXYGEN_SHOULD_SKIP_THIS
+#endif
namespace Glib
{
@@ -99,87 +97,83 @@ class Regex
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);
+ static Glib::RefPtr<Glib::Regex> create(const Glib::ustring& pattern, RegexCompileFlags compile_options = static_cast<RegexCompileFlags>(0), RegexMatchFlags match_options = static_cast<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
+ static Glib::RefPtr<Glib::Regex> create(const Glib::ustring& pattern, RegexCompileFlags compile_options = static_cast<RegexCompileFlags>(0), RegexMatchFlags match_options = static_cast<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)
_WRAP_METHOD(int get_string_number(const Glib::ustring& name) const, g_regex_get_string_number)
- //TODO: _WRAP_METHOD(static Glib::ustring escape_string(const Glib::ustring& string, gint length) const, g_regex_escape_string)
+ static Glib::ustring escape_string(const Glib::ustring& string);
-/* Matching. */
- _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)
+ _WRAP_METHOD(static bool match_simple(const Glib::ustring& pattern, const Glib::ustring& string, RegexCompileFlags compile_options = static_cast<RegexCompileFlags>(0), RegexMatchFlags match_options = static_cast<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);
+ bool match(const Glib::ustring& string, RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0));
//TODO: Wrap GMatchInfo as an iterator:
//_WRAP_METHOD(bool match_full(const gchar* string, gssize string_len, int start_position, RegexMatchFlags match_options = (RegexMatchFlags)0, GMatchInfo** match_info = 0), g_regex_match_full, errthrow)
- #ifdef GLIBMM_EXCEPTIONS_ENABLED
- bool match_full(const Glib::ustring& string, int start_position, RegexMatchFlags match_options);
- #else
- bool match_full(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error);
- #endif //GLIBMM_EXCEPTIONS_ENABLED
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+ bool match(const Glib::ustring& string, int start_position, RegexMatchFlags match_options);
+#else
+ bool match(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error);
+#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
- #ifdef GLIBMM_EXCEPTIONS_ENABLED
- bool match_full(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options);
- #else
- bool match_full(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error);
- #endif //GLIBMM_EXCEPTIONS_ENABLED
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+ bool match(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options);
+#else
+ bool match(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error);
+#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
//TODO: _WRAP_METHOD(bool match_all(const Glib::ustring& string, RegexMatchFlags match_options = (RegexMatchFlags)0, GMatchInfo ** match_info = 0), g_regex_match_all)
- bool match_all(const Glib::ustring& string, RegexMatchFlags match_options = (RegexMatchFlags)0);
+ bool match_all(const Glib::ustring& string, RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0));
//TODO: _WRAP_METHOD(bool match_all_full(const gchar* string, gssize string_len, int start_position, RegexMatchFlags match_options = (RegexMatchFlags)0, GMatchInfo** match_info = 0), g_regex_match_all_full, errthrow)
- #ifdef GLIBMM_EXCEPTIONS_ENABLED
- bool match_all_full(const Glib::ustring& string, int start_position, RegexMatchFlags match_options);
- #else
- bool match_all_full(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error);
- #endif //GLIBMM_EXCEPTIONS_ENABLED
-
- #ifdef GLIBMM_EXCEPTIONS_ENABLED
- bool match_all_full(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options);
- #else
- bool match_all_full(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error);
- #endif //GLIBMM_EXCEPTIONS_ENABLED
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+ bool match_all(const Glib::ustring& string, int start_position, RegexMatchFlags match_options);
+#else
+ bool match_all(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error);
+#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+ bool match_all(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options);
+#else
+ bool match_all(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error);
+#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
- #m4 _CONVERSION(`gchar**',`Glib::StringArrayHandle',`Glib::StringArrayHandle($3, Glib::OWNERSHIP_DEEP)')
+#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 = (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(static Glib::StringArrayHandle split_simple(const Glib::ustring& pattern, const Glib::ustring& string, RegexCompileFlags compile_options = static_cast<RegexCompileFlags>(0), RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0)), g_regex_split_simple)
+ _WRAP_METHOD(Glib::StringArrayHandle split(const Glib::ustring& string, RegexMatchFlags match_options = static_cast<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)
+ _WRAP_METHOD(Glib::StringArrayHandle split(const gchar* string, gssize string_len, int start_position, RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0), int max_tokens = 0) const, g_regex_split_full, errthrow)
- #ifdef GLIBMM_EXCEPTIONS_ENABLED
- Glib::StringArrayHandle split_full(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, int max_tokens) const;
- #else
- Glib::StringArrayHandle split_full(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, int max_tokens, std::auto_ptr<Glib::Error>& error) const;
- #endif //GLIBMM_EXCEPTIONS_ENABLED
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+ Glib::StringArrayHandle split(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, int max_tokens) const;
+#else
+ Glib::StringArrayHandle split(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, int max_tokens, std::auto_ptr<Glib::Error>& error) const;
+#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
-/* String replacement. */
- _WRAP_METHOD(Glib::ustring replace(const gchar* string, gssize string_len, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options = (RegexMatchFlags)0), g_regex_replace, errthrow)
- #ifdef GLIBMM_EXCEPTIONS_ENABLED
+ _WRAP_METHOD(Glib::ustring replace(const gchar* string, gssize string_len, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0)), g_regex_replace, errthrow)
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::ustring replace(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options);
- #else
+#else
Glib::ustring replace(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error);
- #endif //GLIBMM_EXCEPTIONS_ENABLED
+#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
- _WRAP_METHOD(Glib::ustring replace_literal(const gchar *string, gssize string_len, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options = (RegexMatchFlags)0), g_regex_replace_literal, errthrow)
- #ifdef GLIBMM_EXCEPTIONS_ENABLED
+ _WRAP_METHOD(Glib::ustring replace_literal(const gchar *string, gssize string_len, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options = static_cast<RegexMatchFlags>(0)), g_regex_replace_literal, errthrow)
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
Glib::ustring replace_literal(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options);
- #else
+#else
Glib::ustring replace_literal(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error);
- #endif //GLIBMM_EXCEPTIONS_ENABLED
+#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
- _WRAP_METHOD(Glib::ustring replace_eval(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options, GRegexEvalCallback eval, gpointer user_data), g_regex_replace_eval, errthrow)
+ _WRAP_METHOD(Glib::ustring replace_eval(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options, GRegexEvalCallback eval, gpointer user_data), g_regex_replace_eval, errthrow)
_WRAP_METHOD(static bool check_replacement(const Glib::ustring& replacement, gboolean* has_references), g_regex_check_replacement, errthrow)
/* Match info */
@@ -212,6 +206,4 @@ gchar **g_match_info_fetch_all (const GMatchInfo *match_info);
*/
};
-
} // namespace Glib
-