Using regex++ with non-standard character types
Our application stores all characters internally as XMLCh, which is a
typedef to either wchar_t or unsigned short, depending on platform and
various other things. My questions are
1) Is it even possible to use regex++ with types which are not char or
wchar_t? The documentation gives no examples of any other types, and
at one point says "the character type, ie char or wchar_t". When I try
to construct a reg_expression<XMLCh>, I get the following error message:
../../src/boost/boost/regex.hpp: In instantiation of
`boost::regex_traits<unsigned int>':
../../src/boost/boost/regex.hpp:461: instantiated from
`boost::reg_expression
miles_gould wrote:
Our application stores all characters internally as XMLCh, which is a typedef to either wchar_t or unsigned short, depending on platform and various other things. My questions are
1) Is it even possible to use regex++ with types which are not char or wchar_t? The documentation gives no examples of any other types, and at one point says "the character type, ie char or wchar_t". When I try to construct a reg_expression<XMLCh>, I get the following error message:
../../src/boost/boost/regex.hpp: In instantiation of `boost::regex_traits<unsigned int>': ../../src/boost/boost/regex.hpp:461: instantiated from `boost::reg_expression
>' regex.cpp:33: instantiated from here ../../src/boost/boost/regex.hpp:461: base class `boost::c_regex_traits<unsigned int>' has incomplete type ../../src/boost/boost/regex.hpp: In instantiation of `boost::reg_expression >': regex.cpp:33: instantiated from here ../../src/boost/boost/regex.hpp:461: no type named `size_type' in `class boost::regex_traits<unsigned int>' ../../src/boost/boost/regex.hpp:462: no type named `uchar_type' in `class boost::regex_traits<unsigned int>' ../../src/boost/boost/regex.hpp:463: no type named `string_type' in `class boost::regex_traits<unsigned int>' ../../src/boost/boost/regex.hpp:471: no type named `locale_type' in `class boost::regex_traits<unsigned int>'
Looks like your XMLCh is actually an unsigned int. AFAIK, there are no specializations for unsigned int as a char type in the regexp library. But you should be able to add a specialization for this type, I would think.
[compilation is on GCC 2.96 under Red Hat Linux 7.2]
2) Does this mean I need to define a custom traits class? (or rather a custom traits class for every possible definition of XMLCh?) Is there anything else I need to do?
HTH, Markus
Our application stores all characters internally as XMLCh, which is a typedef to either wchar_t or unsigned short, depending on platform and various other things. My questions are
1) Is it even possible to use regex++ with types which are not char or wchar_t? The documentation gives no examples of any other types, and at one point says "the character type, ie char or wchar_t". When I try to construct a reg_expression<XMLCh>, I get the following error message: 2) Does this mean I need to define a custom traits class? (or rather a custom traits class for every possible definition of XMLCh?) Is there anything else I need to do?
In theory just define your own traits class, you may well be able to inherit from one of the existing traits classes and get that to do most of the work. There is also a limitation that character types must be POD's. John Maddock http://ourworld.compuserve.com/homepages/john_maddock/index.htm
participants (3)
-
John Maddock
-
Markus Schöpflin
-
miles_gould