⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mstl_char_traits.hpp

📁 一个类STL的多平台可移植的算法容器库,主要用于嵌入式系统编程时的内存管理等方面
💻 HPP
📖 第 1 页 / 共 3 页
字号:
    static size_type length( const char_type* s )
        {  return strlen(s);  }

    static int compare( const char_type* s1, const char_type* s2, size_type count )
        {  return charcmp_lower( s1, s2, count );  }

    static char_type* copy( char_type* d, const char_type* s, size_type count )
        {  return (char_type*)memcpy( d, s, count );  }

    static char_type* move( char_type* d, const char_type* s, size_type count )
        {  return (char_type*)memmove( d, s, count );  }

    static char_type* assign( char_type* d, size_type count, const char_type& c )
        {  return (char_type*)memset( d, c, count );  }

    static const char_type*
    find( const char_type* buf, size_type count, const char_type& c )
        {  return (const char_type*)memchr( buf, c, count );  }

}; //end cmp_no_case_char_traits

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

class lower_char_traits  //全部是小写char的traits
{
public:
    typedef  char        char_type;
    typedef  int         int_type;
    typedef  streampos   pos_type;
    typedef  streamoff   off_type;
    typedef  mbstate_t   state_type;
    typedef  def_size_t  size_type;

    static char_type eos()             {  return 0;  }
    static bool is_del( char_type c )  {  return isspace(c);  }

    static void assign( char_type& d, const char_type& s )
        {  d = tolower(s);  }
    static bool eq( const char_type& c1, const char_type& c2 )
        {  return ( c1 == c2 );  }
    static bool lt( const char_type& c1, const char_type& c2 )
        {  return ( c1 < c2 );  }

    static char_type to_char_type( const int_type& i )
        {  return static_cast<char_type>( i );  }
    static int_type to_int_type( const char_type& c )
        {  return static_cast<int_type>( static_cast<unsigned char>(c) );  }
    static bool eq_int_type( const int_type& i1, const int_type& i2 )
        {  return ( i1 == i2 );  }

    static int_type eof()
        {  return static_cast<int_type>( EOF );  }
    static int_type not_eof( const int_type& i )
        {  return ( i == eof() ? 0 : i );  }

    static size_type length( const char_type* s )
        {  return strlen(s);  }

    static int compare( const char_type* s1, const char_type* s2, size_type count )
    {
        int result = memcmp( s1, s2, count );
        if( result == 0 )
            return 0;
        else
            return ( result < 0 ? -1 : 1 );
    }

    static char_type* copy( char_type* d, const char_type* s, size_type count )
        {  return charcopy_lower( d, s, count );  }

    static char_type* move( char_type* d, const char_type* s, size_type count )
        {  return charmove_lower( d, s, count );  }

    static char_type* assign( char_type* d, size_type count, const char_type& c )
        {  return charset_lower( d, c, count );  }

    static const char_type*
    find( const char_type* buf, size_type count, const char_type& c )
        {  return (const char_type*)memchr( buf, c, count );  }

}; //end lower_char_traits

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

class upper_char_traits  //全部是大写char的traits
{
public:
    typedef  char        char_type;
    typedef  int         int_type;
    typedef  streampos   pos_type;
    typedef  streamoff   off_type;
    typedef  mbstate_t   state_type;
    typedef  def_size_t  size_type;

    static char_type eos()             {  return 0;  }
    static bool is_del( char_type c )  {  return isspace(c);  }

    static void assign( char_type& d, const char_type& s )
        {  d = toupper(s);  }
    static bool eq( const char_type& c1, const char_type& c2 )
        {  return ( c1 == c2 );  }
    static bool lt( const char_type& c1, const char_type& c2 )
        {  return ( c1 < c2 );  }

    static char_type to_char_type( const int_type& i )
        {  return static_cast<char_type>( i );  }
    static int_type to_int_type( const char_type& c )
        {  return static_cast<int_type>( static_cast<unsigned char>(c) );  }
    static bool eq_int_type( const int_type& i1, const int_type& i2 )
        {  return ( i1 == i2 );  }

    static int_type eof()
        {  return static_cast<int_type>( EOF );  }
    static int_type not_eof( const int_type& i )
        {  return ( i == eof() ? 0 : i );  }

    static size_type length( const char_type* s )
        {  return strlen(s);  }

    static int compare( const char_type* s1, const char_type* s2, size_type count )
    {
        int result = memcmp( s1, s2, count );
        if( result == 0 )
            return 0;
        else
            return ( result < 0 ? -1 : 1 );
    }

    static char_type* copy( char_type* d, const char_type* s, size_type count )
        {  return charcopy_upper( d, s, count );  }

    static char_type* move( char_type* d, const char_type* s, size_type count )
        {  return charmove_upper( d, s, count );  }

    static char_type* assign( char_type* d, size_type count, const char_type& c )
        {  return charset_upper( d, c, count );  }

    static const char_type*
    find( const char_type* buf, size_type count, const char_type& c )
        {  return (const char_type*)memchr( buf, c, count );  }

}; //end upper_char_traits

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

//字符串内全部是小写char并且和其他字符串进行比较时不区分大小写的traits
class cmp_no_case_lower_char_traits
{
public:
    typedef  char        char_type;
    typedef  int         int_type;
    typedef  streampos   pos_type;
    typedef  streamoff   off_type;
    typedef  mbstate_t   state_type;
    typedef  def_size_t  size_type;

    static char_type eos()             {  return 0;  }
    static bool is_del( char_type c )  {  return isspace(c);  }

    static void assign( char_type& d, const char_type& s )
        {  d = tolower(s);  }
    static bool eq( const char_type& c1, const char_type& c2 )
        {  return ( tolower(c1) == tolower(c2) );  }
    static bool lt( const char_type& c1, const char_type& c2 )
        {  return ( tolower(c1) < tolower(c2) );  }

    static char_type to_char_type( const int_type& i )
        {  return static_cast<char_type>( i );  }
    static int_type to_int_type( const char_type& c )
        {  return static_cast<int_type>( static_cast<unsigned char>(c) );  }
    static bool eq_int_type( const int_type& i1, const int_type& i2 )
        {  return ( i1 == i2 );  }

    static int_type eof()
        {  return static_cast<int_type>( EOF );  }
    static int_type not_eof( const int_type& i )
        {  return ( i == eof() ? 0 : i );  }

    static size_type length( const char_type* s )
        {  return strlen(s);  }

    static int compare( const char_type* s1, const char_type* s2, size_type count )
        {  return charcmp_lower( s1, s2, count );  }

    static char_type* copy( char_type* d, const char_type* s, size_type count )
        {  return charcopy_lower( d, s, count );  }

    static char_type* move( char_type* d, const char_type* s, size_type count )
        {  return charmove_lower( d, s, count );  }

    static char_type* assign( char_type* d, size_type count, const char_type& c )
        {  return charset_lower( d, c, count );  }

    static const char_type*
    find( const char_type* buf, size_type count, const char_type& c )
        {  return (const char_type*)memchr( buf, c, count );  }

}; //end cmp_no_case_lower_char_traits

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

//字符串内全部是大写char并且和其他字符串进行比较时不区分大小写的traits
class cmp_no_case_upper_char_traits
{
public:
    typedef  char        char_type;
    typedef  int         int_type;
    typedef  streampos   pos_type;
    typedef  streamoff   off_type;
    typedef  mbstate_t   state_type;
    typedef  def_size_t  size_type;

    static char_type eos()             {  return 0;  }
    static bool is_del( char_type c )  {  return isspace(c);  }

    static void assign( char_type& d, const char_type& s )
        {  d = toupper(s);  }
    static bool eq( const char_type& c1, const char_type& c2 )
        {  return ( toupper(c1) == toupper(c2) );  }
    static bool lt( const char_type& c1, const char_type& c2 )
        {  return ( toupper(c1) < toupper(c2) );  }

    static char_type to_char_type( const int_type& i )
        {  return static_cast<char_type>( i );  }
    static int_type to_int_type( const char_type& c )
        {  return static_cast<int_type>( static_cast<unsigned char>(c) );  }
    static bool eq_int_type( const int_type& i1, const int_type& i2 )
        {  return ( i1 == i2 );  }

    static int_type eof()
        {  return static_cast<int_type>( EOF );  }
    static int_type not_eof( const int_type& i )
        {  return ( i == eof() ? 0 : i );  }

    static size_type length( const char_type* s )
        {  return strlen(s);  }

    static int compare( const char_type* s1, const char_type* s2, size_type count )
        {  return charcmp_upper( s1, s2, count );  }

    static char_type* copy( char_type* d, const char_type* s, size_type count )
        {  return charcopy_upper( d, s, count );  }

    static char_type* move( char_type* d, const char_type* s, size_type count )
        {  return charmove_upper( d, s, count );  }

    static char_type* assign( char_type* d, size_type count, const char_type& c )
        {  return charset_upper( d, c, count );  }

    static const char_type*
    find( const char_type* buf, size_type count, const char_type& c )
        {  return (const char_type*)memchr( buf, c, count );  }

}; //end cmp_no_case_upper_char_traits

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

class cmp_no_case_wchar_traits  //比较时不区分大小写wchar_t的traits
{
public:
    typedef  wchar_t     char_type;
    typedef  wint_t      int_type;
    typedef  wstreamoff  pos_type;
    typedef  wstreampos  off_type;
    typedef  mbstate_t   state_type;
    typedef  def_size_t  size_type;

    static char_type eos()             {  return 0;  }
    static bool is_del( char_type c )  {  return iswspace(c);  }

    static void assign( char_type& d, const char_type& s )
        {  d = s;  }
    static bool eq( const char_type& c1, const char_type& c2 )
        {  return ( towlower(c1) == towlower(c2) );  }
    static bool lt( const char_type& c1, const char_type& c2 )
        {  return ( towlower(c1) < towlower(c2) );  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -