1 /* Copyright (C) 2007 The glibmm Development Team
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Library General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
13 * You should have received a copy of the GNU Library General Public
14 * License along with this library; if not, write to the Free
15 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #include <glibmm/utility.h>
23 #ifdef GLIBMM_EXCEPTIONS_ENABLED
24 Glib::RefPtr<Glib::Regex> Regex::create(const Glib::ustring& pattern,
25 RegexCompileFlags compile_options,
26 RegexMatchFlags match_options)
28 Glib::RefPtr<Glib::Regex> Regex::create(const Glib::ustring& pattern,
29 RegexCompileFlags compile_options,
30 RegexMatchFlags match_options,
31 std::auto_ptr<Glib::Error>& error)
32 #endif /* GLIBMM_EXCEPTIONS_ENABLED */
35 GRegex* regex = g_regex_new(pattern.c_str(), (GRegexCompileFlags)compile_options,
36 (GRegexMatchFlags)match_options, &gerror);
39 #ifdef GLIBMM_EXCEPTIONS_ENABLED
40 Glib::Error::throw_exception(gerror);
42 error = Glib::Error::throw_exception(gerror);
44 return Glib::wrap(regex);
48 Glib::ustring Regex::escape_string(const Glib::ustring& string)
50 const Glib::ScopedPtr<char> buf (g_regex_escape_string(string.raw().c_str(),
51 string.raw().size()));
52 return Glib::ustring(buf.get());
55 bool Regex::match(const Glib::ustring& string, RegexMatchFlags match_options)
57 return g_regex_match(gobj(), string.c_str(), (GRegexMatchFlags)(match_options), 0);
61 #ifdef GLIBMM_EXCEPTIONS_ENABLED
62 bool Regex::match(const Glib::ustring& string, int start_position, RegexMatchFlags match_options)
64 bool Regex::match(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
65 #endif //GLIBMM_EXCEPTIONS_ENABLED
68 bool retvalue = g_regex_match_full(gobj(), string.c_str(), -1, start_position, ((GRegexMatchFlags)(match_options)), 0, &(gerror));
69 #ifdef GLIBMM_EXCEPTIONS_ENABLED
71 ::Glib::Error::throw_exception(gerror);
74 error = ::Glib::Error::throw_exception(gerror);
75 #endif //GLIBMM_EXCEPTIONS_ENABLED
80 #ifdef GLIBMM_EXCEPTIONS_ENABLED
81 bool Regex::match(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options)
83 bool Regex::match(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
84 #endif //GLIBMM_EXCEPTIONS_ENABLED
87 bool retvalue = g_regex_match_full(gobj(), string.c_str(), string_len, start_position, ((GRegexMatchFlags)(match_options)), 0, &(gerror));
88 #ifdef GLIBMM_EXCEPTIONS_ENABLED
90 ::Glib::Error::throw_exception(gerror);
93 error = ::Glib::Error::throw_exception(gerror);
94 #endif //GLIBMM_EXCEPTIONS_ENABLED
100 bool Regex::match_all(const Glib::ustring& string, RegexMatchFlags match_options)
102 return g_regex_match_all(gobj(), string.c_str(), ((GRegexMatchFlags)(match_options)), 0);
106 #ifdef GLIBMM_EXCEPTIONS_ENABLED
107 bool Regex::match_all(const Glib::ustring& string, int start_position, RegexMatchFlags match_options)
109 bool Regex::match_all(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
110 #endif //GLIBMM_EXCEPTIONS_ENABLED
113 bool retvalue = g_regex_match_all_full(gobj(), string.c_str(), -1, start_position, ((GRegexMatchFlags)(match_options)), 0, &(gerror));
114 #ifdef GLIBMM_EXCEPTIONS_ENABLED
116 ::Glib::Error::throw_exception(gerror);
119 error = ::Glib::Error::throw_exception(gerror);
120 #endif //GLIBMM_EXCEPTIONS_ENABLED
125 #ifdef GLIBMM_EXCEPTIONS_ENABLED
126 bool Regex::match_all(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options)
128 bool Regex::match_all(const Glib::ustring& string, gssize string_len, int start_position, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
129 #endif //GLIBMM_EXCEPTIONS_ENABLED
132 bool retvalue = g_regex_match_all_full(gobj(), string.c_str(), string_len, start_position, ((GRegexMatchFlags)(match_options)), 0, &(gerror));
133 #ifdef GLIBMM_EXCEPTIONS_ENABLED
135 ::Glib::Error::throw_exception(gerror);
138 error = ::Glib::Error::throw_exception(gerror);
139 #endif //GLIBMM_EXCEPTIONS_ENABLED
146 #ifdef GLIBMM_EXCEPTIONS_ENABLED
147 Glib::ustring Regex::replace(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options)
149 Glib::ustring Regex::replace(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
150 #endif //GLIBMM_EXCEPTIONS_ENABLED
153 Glib::ustring retvalue = Glib::convert_return_gchar_ptr_to_ustring(g_regex_replace(gobj(), string.c_str(), -1, start_position, replacement.c_str(), ((GRegexMatchFlags)(match_options)), &(gerror)));
154 #ifdef GLIBMM_EXCEPTIONS_ENABLED
156 ::Glib::Error::throw_exception(gerror);
159 error = ::Glib::Error::throw_exception(gerror);
160 #endif //GLIBMM_EXCEPTIONS_ENABLED
166 #ifdef GLIBMM_EXCEPTIONS_ENABLED
167 Glib::ustring Regex::replace_literal(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options)
169 Glib::ustring Regex::replace_literal(const Glib::ustring& string, int start_position, const Glib::ustring& replacement, RegexMatchFlags match_options, std::auto_ptr<Glib::Error>& error)
170 #endif //GLIBMM_EXCEPTIONS_ENABLED
173 Glib::ustring retvalue = Glib::convert_return_gchar_ptr_to_ustring(g_regex_replace_literal(gobj(), string.c_str(), -1, start_position, replacement.c_str(), ((GRegexMatchFlags)(match_options)), &(gerror)));
174 #ifdef GLIBMM_EXCEPTIONS_ENABLED
176 ::Glib::Error::throw_exception(gerror);
179 error = ::Glib::Error::throw_exception(gerror);
180 #endif //GLIBMM_EXCEPTIONS_ENABLED
185 #ifdef GLIBMM_EXCEPTIONS_ENABLED
186 Glib::StringArrayHandle Regex::split(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, int max_tokens) const
188 Glib::StringArrayHandle Regex::split(const Glib::ustring& string, int start_position, RegexMatchFlags match_options, int max_tokens, std::auto_ptr<Glib::Error>& error) const
189 #endif //GLIBMM_EXCEPTIONS_ENABLED
192 Glib::StringArrayHandle retvalue = Glib::StringArrayHandle(g_regex_split_full(const_cast<GRegex*>(gobj()), string.c_str(), -1, start_position, ((GRegexMatchFlags)(match_options)), max_tokens, &(gerror)), Glib::OWNERSHIP_DEEP);
193 #ifdef GLIBMM_EXCEPTIONS_ENABLED
195 ::Glib::Error::throw_exception(gerror);
198 error = ::Glib::Error::throw_exception(gerror);
199 #endif //GLIBMM_EXCEPTIONS_ENABLED