Case-insentive

Discussion in 'C++' started by salvo, Sep 15, 2005.

  1. salvo

    salvo Guest

    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.
    salvo, Sep 15, 2005
    #1
    1. Advertising

  2. 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
    John Harrison, Sep 15, 2005
    #2
    1. Advertising

  3. 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
    John Harrison, Sep 15, 2005
    #3
  4. salvo

    salvo Guest

    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
    salvo, Sep 15, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Franks
    Replies:
    2
    Views:
    1,250
    Steve Franks
    Jun 10, 2004
  2. Tee
    Replies:
    3
    Views:
    7,803
    Herfried K. Wagner [MVP]
    Jun 23, 2004
  3. Janice

    lower case to upper case

    Janice, Dec 10, 2004, in forum: C Programming
    Replies:
    17
    Views:
    1,177
    Richard Bos
    Dec 14, 2004
  4. Replies:
    1
    Views:
    2,478
    Mark P
    Apr 6, 2007
  5. darrel

    'case' vs. 'case is'

    darrel, Aug 14, 2008, in forum: ASP .Net
    Replies:
    3
    Views:
    274
    Rory Becker
    Aug 14, 2008
Loading...

Share This Page