Char_traits
head File
Char_traits.h
// generic char_traits clas. Note That this class is provided only
// AS A Base for ExPlicit Specialization; It is unlikely to be useful
// as is for any particular user-defined Type. In particular, IT
// * Will Not Work * for a non-pod type.
Character Features Template, the purpose is to provide a unified method function of the most basic characteristic.
Char_traits inherited __char_traits_base
Template
: public __char_traits_base <_chart, _Chart>
{};
// Specialization for char.
// Char character type template offset
__STL_TEMPLATE_NULL CLASS Char_Traits
: public __char_traits_base
{
PUBLIC:
// int type to CHAR type conversion
Static char_type to_char_type (const INT_TYPE & __C) {
Return static_cast
}
// CHAR to INT type conversion
Static int_type to_int_type (const char_type& __c) {
Return static_cast
}
// Compare two strings
Static int compare (const char * __s2, size_t __n)
{RETURN MEMCMP (__ S1, __s2, __n);
/ / The length of the character
Static size_t length (const char * __s) {return strlen (__ s);}
// character assignment
Static void Assign (Char & __C1, Const Char & __C2) {__C1 = __C2;}
// string assignment
Static char * assign (char * __s, size_t __n, char __c)
{MEMSET (__ s, __c, __n); return __s;}
}
// Specialization for Wchar_t.
// Wide character type template offset
__Stl_template_null class char_traits
: public __char_traits_base
{};
// Class __char_traits_base.
// Character characteristic base class
Template
PUBLIC:
Typedef _Chart Char_type; // Character Type
TYPEDEF _INTT INT_TYPE; / / INT type
#ifdef __stl_use_new_ioostreams
TypeDef streamoff off_type;
Typedef Streampos POS_TYPE;
TYPEDEF MBSTATE_T State_Type;
#ENDIF / * __STL_USE_NEW_IOSTREAMS * / / / The character assignment
Static void assign (char_type & __c1, const char_type& __c2) {__c1 = __c2;}
// Character comparison
Static Bool EQ (Const_Chart & __C1, Const _Chart & __C2)
{RETURN __C1 == __C2;}
// Character size comparison
Static Bool LT (const _chart & __c1, const _chart & __c2)
{RETURN __C1 <__C2;}
// string comparison
Static int compare (const _chart * __s1, const _chart * __s2, size_t __n) {
FOR (size_t __i = 0; __i <__n; __ i)
IF (! EQ (__ S1 [__ i], __s2 [__ i]))))
Return __s1 [__ i] <__s2 [__ i]? -1: 1;
Return 0;
}
// string length
Static size_t length (const _chart * __s) {
Const _Chart __nullchar = _chart ();
SIZE_T __I;
FOR (__i = 0;! EQ (__ s [__ i], __nullchar); __ i)
{}
Return__i;
}
/ / Find characters in strings
Static const _chart * find (const _chart * __s, size_t __n, const _chart & __c)
{
For (; __n> 0; __ s, --__ n)
IF (EQ (* __ s, __c))
Return__s;
Return 0;
}
// String to another string
Static _Chart * Move (_Chart * __s1, const _chart * __s2, size_t __n) {
Memmove (__ S1, __s2, __n * sizeof (_chart));
Return __s1;
}
/ / Copy one string to another string
Static _Chart * Copy (_Chart * __s1, const _chart * __s2, size_t __n) {
Memcpy (__ s1, __s2, __n * sizeof (_chart));
Return __s1;
}
// string assignment
Static _Chart * Assign (_Chart * __s, size_t __n, _chart __c) {
FOR (size_t __i = 0; __i <__n; __ i)
__s [__ i] = __c;
Return__s;
}
/ / Judgment is the end of the end
Static int_type not_eof (const INT_TYPE & __C) {
Return! EQ_INT_TYPE (__ C, EOF ())? __c: 0;
}
// int to Char type conversion
Static char_type to_char_type (const INT_TYPE & __C) {
Return static_cast
}
// CHAR to INT type conversion
Static int_type to_int_type (const char_type& __c) {
Return static_cast
}
// Judgment whether the two int types are equal
Static Bool EQ_INT_TYPE (const INT_TYPE & __C1, Const INT_TYPE & ___C2) {
Return __c1 == __c2;
}
// Return End Integer Value
Static int_type eof () {
Return static_cast
}
}