Greta and basic_string<char, ignore_case_traits>

P

pillbug

I am trying to convince the Greta regular expression library to use the
following char_traits:

struct ignore_case_traits : std::char_traits<char> {
static bool eq (const char& x, const char& y) {
return tolower (x) == tolower (y);
}
static bool lt (const char& x, const char& y) {
return tolower (x) < tolower (y);
}
static int compare (const char* left, const char* right, size_t n) {
return strnicmp (left, right, n);
}
static const char* find (const char* str, int n, char ch) {
while ((n-- > 0) && (tolower (*str) != tolower (ch)))
++str;
return n >= 0 ? str : 0;
}
};

typedef std::basic_string<char, ignore_case_traits> istring;

I then use the following with Greta:

typedef regex::basic_rpattern<istring::const_iterator> rpattern;

However I am unable to compile the following:

istring istr ("...")
rpattern pat (istr);

The workaround is this:

rpattern pat (istr.c_str());

Any ideas? I have looked into the code and the rpattern constructors
looks like this:

rpattern (const string_type& str, /*various*/...)

And string_type comes from a rather deeply nested typdef in the
basic_rpattern_base_impl class:

typedef std::basic_string<char_type> string_type;

So it looks like rpattern totally ignores any traits I may define. And
since I cannot redefine std::char_traits<char>, which is what
string_type defaults the traits template parameter to, it seems I am
either stuck, or need to define an acceptable char_type substitution.

I guess this is pretty specific huh, sorry if it's OT.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,145
Latest member
web3PRAgeency
Top