Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Case-insentive

Reply
Thread Tools

Case-insentive

 
 
salvo
Guest
Posts: n/a
 
      09-15-2005
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.
 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      09-15-2005
salvo wrote:
> 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
 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      09-15-2005
Some guesses follow.

salvo wrote:
> 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 <string>

>
> struct ci_char_traits : public char_traits<char>


struct ci_char_traits : public std::char_traits<char>

> {
> 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
 
Reply With Quote
 
salvo
Guest
Posts: n/a
 
      09-15-2005

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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments