zhangzengfei
2022-07-20 c90c3e794bdd95127d0c34ff1d9e8759d18a0445
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/****************************************************************************
 *
 *  Copyright (C) 2000-2001 RealNetworks, Inc. All rights reserved.
 *
 *  This program is free software.  It may be distributed under the terms
 *  in the file LICENSE, found in the top level of the source distribution.
 *
 */
 
#ifndef _STR_H
#define _STR_H
 
#include "types.h"
#include "tlist.h"
 
class CBuffer
{
public:
    CBuffer( void );
    CBuffer( const CBuffer& other );
    CBuffer( size_t len );
    CBuffer( CPByte pbuf, size_t len );
    ~CBuffer( void );
 
    CBuffer& operator=( const CBuffer& other );
    Byte  operator[]( size_t n ) const;
    Byte& operator[]( size_t n );
 
    void   Clear( void );
 
    void   Set( CPByte pbuf, size_t len );
    size_t GetSize( void ) const;
    void   SetSize( size_t len );
    PByte  GetBuffer( void );
    CPByte GetBuffer( void ) const;
    void   SetBuffer( CPByte pbuf );
 
protected:
    size_t m_nAlloc;
    size_t m_nLen;
    PByte  m_buf;
};
 
class CString
{
public:
    CString( void );
    CString( const CString& other );
    CString( CPCHAR sz );
    CString( CPCHAR buf, size_t len );
    CString( char c, UINT32 nrep = 1 );
    ~CString( void );
 
    CString& operator=( const CString& other );
    CString& operator=( CPCHAR sz );
 
    void  Set( CPCHAR buf, size_t len );
 
    UINT32    GetLength( void ) const;
    bool    IsEmpty( void ) const;
    int     Compare( const CString& other ) const;
    int     CompareNum( const CString& other, UINT32 len) const;
    int     CompareNoCase( const CString& other ) const;
    int     CompareNumNoCase( const CString& other, UINT32 len) const;
 
    char    GetAt( UINT32 pos ) const;
    char&   GetAt( UINT32 pos );
    void    SetAt( UINT32 pos, char c );
    void    Append( CPCHAR sz );
    void    ToLower( void );
    void    ToUpper( void );
    void    DeQuote( void );
 
    CPCHAR Find( char c, UINT32 pos = 0 ) const;
 
    inline operator CPCHAR( void )      const { assert(m_sz); return m_sz; }
    inline char  operator[]( int pos )  const { return GetAt( pos ); }
 
protected:
    PCHAR   m_sz;
};
typedef TDoubleList<CString> CStringList;
 
inline bool operator==( const CString& lhs, const CString& rhs ) { return (lhs.Compare( rhs ) == 0); }
inline bool operator==( const CString& lhs, CPCHAR rhs )         { return (lhs.Compare( rhs ) == 0); }
inline bool operator==( CPCHAR lhs, const CString& rhs )         { return (rhs.Compare( lhs ) == 0); }
 
inline bool operator!=( const CString& lhs, const CString& rhs ) { return (lhs.Compare( rhs ) != 0); }
inline bool operator!=( const CString& lhs, CPCHAR rhs )         { return (lhs.Compare( rhs ) != 0); }
inline bool operator!=( CPCHAR lhs, const CString& rhs )         { return (rhs.Compare( lhs ) != 0); }
 
inline bool operator<=( const CString& lhs, const CString& rhs ) { return (lhs.Compare( rhs ) <= 0); }
inline bool operator<=( const CString& lhs, CPCHAR rhs )         { return (lhs.Compare( rhs ) <= 0); }
inline bool operator<=( CPCHAR lhs, const CString& rhs )         { return (rhs.Compare( lhs ) > 0); }
 
inline bool operator>=( const CString& lhs, const CString& rhs ) { return (lhs.Compare( rhs ) >= 0); }
inline bool operator>=( const CString& lhs, CPCHAR rhs )         { return (lhs.Compare( rhs ) >= 0); }
inline bool operator>=( CPCHAR lhs, const CString& rhs )         { return (rhs.Compare( lhs ) < 0); }
 
inline bool operator<( const CString& lhs, const CString& rhs ) { return (lhs.Compare( rhs ) < 0); }
inline bool operator<( const CString& lhs, CPCHAR rhs )         { return (lhs.Compare( rhs ) < 0); }
inline bool operator<( CPCHAR lhs, const CString& rhs )         { return (rhs.Compare( lhs ) >= 0); }
 
inline bool operator>( const CString& lhs, const CString& rhs ) { return (lhs.Compare( rhs ) > 0); }
inline bool operator>( const CString& lhs, CPCHAR rhs )         { return (lhs.Compare( rhs ) > 0); }
inline bool operator>( CPCHAR lhs, const CString& rhs )         { return (rhs.Compare( lhs ) <= 0); }
 
#endif //ndef _STR_H