Case-insentive

S

salvo

I'm trying to make a case-insensitive class. Here is the code.


=================================Code=================================

#include<bits/char_traits.h>

struct ci_char_traits : public char_traits<char>
{
static bool eq( char c1, char c2 )
{
return toupper(c1) == toupper(c2);
}

static bool lt( char c1, char c2 )
{
return toupper(c1) < toupper(c2);
}

static int compare( const char *s1, const char *s2, size_t n )
{
/*TODO*/
}

static const char* find( const char* s, int n, char a )
{
while( n-- > 0 && toupper(*s) != toupper(a) )
{
++s;
}

return n >= 0 ? s : 0;
}
};

typedef basic_string<char, ci_char_traits> ci_string;

=============================================================

===============================Error==========================
emitrax@freek ~/programming/C++ $ g++ test_ci_string.cc -o test_ci_string
In file included from test_ci_string.cc:3:
ci_string/ci_string.h:30: error: parse error before `<' token
ci_string/ci_string.h:55: error: parse error before `}' token
ci_string/ci_string.h:57: error: syntax error before `;' token
test_ci_string.cc: In function `int main()':
test_ci_string.cc:7: error: `ci_string' undeclared in namespace `std'
test_ci_string.cc:7: error: parse error before `;' token
emitrax@freek ~/programming/C++ $
=============================================================

Can anyone help me?

Thanks
Salvo.
 
J

John Harrison

salvo said:
I'm trying to make a case-insensitive class. Here is the code.


=================================Code=================================

#include<bits/char_traits.h>

struct ci_char_traits : public char_traits<char>
{
static bool eq( char c1, char c2 )
{
return toupper(c1) == toupper(c2);
}

static bool lt( char c1, char c2 )
{
return toupper(c1) < toupper(c2);
}

static int compare( const char *s1, const char *s2, size_t n )
{
/*TODO*/
}

static const char* find( const char* s, int n, char a )
{
while( n-- > 0 && toupper(*s) != toupper(a) )
{
++s;
}

return n >= 0 ? s : 0;
}
};

typedef basic_string<char, ci_char_traits> ci_string;

=============================================================

===============================Error==========================
emitrax@freek ~/programming/C++ $ g++ test_ci_string.cc -o test_ci_string
In file included from test_ci_string.cc:3:
ci_string/ci_string.h:30: error: parse error before `<' token
ci_string/ci_string.h:55: error: parse error before `}' token
ci_string/ci_string.h:57: error: syntax error before `;' token
test_ci_string.cc: In function `int main()':
test_ci_string.cc:7: error: `ci_string' undeclared in namespace `std'
test_ci_string.cc:7: error: parse error before `;' token
emitrax@freek ~/programming/C++ $
=============================================================

Can anyone help me?

Thanks
Salvo.

You could help us by saying which lines 30, 55 and 57 are.

BTW your use of toupper is incorrect.

toupper(c1)

is incorrect if c1 is negative. You should say

toupper((unsigned char)c1)

john
 
J

John Harrison

Some guesses follow.
I'm trying to make a case-insensitive class. Here is the code.


=================================Code=================================

#include<bits/char_traits.h>

This is a non-standard header, replace with

#include said:
> struct ci_char_traits : public char_traits<char>

struct ci_char_traits : public std::char_traits said:
{
static bool eq( char c1, char c2 )
{
return toupper(c1) == toupper(c2);
}

[snip]

};

typedef basic_string<char, ci_char_traits> ci_string;

typedef std::basic_string<char, ci_char_traits> ci_string;

john
 
S

salvo

30--> struct ci_char_traits : public char_traits<char>

50--> typedef basic_string<char, ci_char_traits> ci_string;

Thanks John! I got my code compiled.
Those above were the errors. I had to
put std::char_traits and std::basic_string.

Regards
Salvo
 

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,599
Members
45,165
Latest member
JavierBrak
Top