RE: [Boost-users] regular expression searching for Glib::ustring??

Paul Elliott <pelliott@io.com> wrote:
I am using Gtkmm. I want to do boost regular expression searching on Glib::ustring.
http://www.gtkmm.org/gtkmm2/docs/reference/html/classGlib_1_1ustring.htm l
The character type should be gunichar.
I am using Boost 1.30, in which the traits are documented in <boost/libs/regex/traits_class_ref.htm>. I don't know whether that documentation still applies to 1.31. You don't necessarily need custom traits to use custom iterator types. However, you do need to define custom traits to make character classes, case folding and so on work for all Unicode characters. To create a regex from a ustring I would write something like this: boost::reg_expression<gunichar, unicode_regex_traits> re; re.assign(s.begin(), s.end(), flags); When searching in a ustring I would write code like: my_predicate pred; boost::regex_grep(pred, s.begin(), s.end(), re, flags); boost::match_results<Glib::ustring::const_iterator, std::allocator<gunichar> > results; boost::regex_search<Glib::ustring::const_iterator, std::allocator<gunichar>, gunichar, unicode_regex_traits, std::allocator<gunichar> >( s.begin(), s.end(), results, re, flags); Glib::ustring result; boost::regex_merge( std::back_inserter(result), source.begin(), source.end(), re, std::basic_string<gunichar>(repl.begin(), repl.end())), flags); (The above is untested as we're not actually using Gtkmm but it's based on what we're doing with our own UTF-8 and UTF-16 strings.)

On Thu, Mar 18, 2004 at 04:08:59PM -0000, Ben Hutchings wrote:
In the above, you have unicode_regex_traits, which is necessary because when I tried: boost::basic_regex<gunichar> regular_expression; I got the following error message: err>In file included from gmore.hh:6, err> from peless.cc:6: err>search.hh: In instantiation of `boost::regex_traits<gunichar>': err>search.hh:30: instantiated from here err>search.hh:30: error: base class `boost::c_regex_traits<gunichar>' has err> incomplete type err>/usr/include/boost-1_31/boost/regex/v4/basic_regex.hpp: In instantiation of `boost::reg_expression<gunichar, boost::regex_traits<gunichar>, std::allocator<size_t> >': err>search.hh:60: instantiated from `boost::basic_regex<gunichar, boost::regex_traits<gunichar>, std::allocator<size_t> >' err>search.hh:60: instantiated from here err>/usr/include/boost-1_31/boost/regex/v4/basic_regex.hpp:48: error: no type named err> `size_type' in `class boost::regex_traits<gunichar>' err>/usr/include/boost-1_31/boost/regex/v4/basic_regex.hpp:49: error: no type named err> `uchar_type' in `class boost::regex_traits<gunichar>' err>/usr/include/boost-1_31/boost/regex/v4/basic_regex.hpp:50: error: no type named err> `string_type' in `class boost::regex_traits<gunichar>' err>/usr/include/boost-1_31/boost/regex/v4/basic_regex.hpp: In instantiation of `boost::reg_expression<gunichar, boost::regex_traits<gunichar>, std::allocator<size_t> >': err>search.hh:60: instantiated from `boost::basic_regex<gunichar, boost::regex_traits<gunichar>, std::allocator<size_t> >' err>search.hh:60: instantiated from here err>/usr/include/boost-1_31/boost/regex/v4/basic_regex.hpp:67: error: no type named err> `locale_type' in `class boost::regex_traits<gunichar>' err>/usr/include/boost-1_31/boost/regex/v4/basic_regex.hpp:178: error: no type err> named `locale_type' in `class boost::regex_traits<gunichar>' err>/usr/include/boost-1_31/boost/regex/v4/basic_regex.hpp:179: error: no type err> named `locale_type' in `class boost::regex_traits<gunichar>' err>/usr/include/boost-1_31/boost/regex/v4/regex_compile.hpp: In instantiation of `boost::reg_expression<gunichar, boost::regex_traits<gunichar>, std::allocator<size_t> >': err>search.hh:60: instantiated from `boost::basic_regex<gunichar, boost::regex_traits<gunichar>, std::allocator<size_t> >' err>search.hh:60: instantiated from here err>/usr/include/boost-1_31/boost/regex/v4/regex_compile.hpp:1137: error: no type err> named `string_type' in `class boost::regex_traits<gunichar>' err>/usr/include/boost-1_31/boost/regex/v4/regex_compile.hpp:1054: error: no type err> named `string_type' in `class boost::regex_traits<gunichar>' So this means that regex_traits<gunichar> does not work, and I must code my own substitute for regex_traits<gunichar>. What are the requirements for such a traits structure? What methods must mytraits::string_type have? What is the required relationship between the types? These requirements do not seem to be documented anywhere! Help! -- Paul Elliott 1(512)837-1096 pelliott@io.com PMB 181, 11900 Metric Blvd Suite J http://www.io.com/~pelliott/pme/ Austin TX 78758-3117
participants (2)
-
Ben Hutchings
-
Paul Elliott