-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharx_cstring.h
132 lines (119 loc) · 2.65 KB
/
arx_cstring.h
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef ARX_CSTRING_H
#define ARX_CSTRING_H
namespace arx {
template <typename CT>
class CString {
const CT* _str;
int _size;
public:
CString( const CT* s );
CString( const CT* s, int size );
int Size() const;
bool operator== ( const CString& s ) const;
bool operator!= ( const CString& s ) const;
bool operator> ( const CString& s ) const;
bool operator< ( const CString& s ) const;
bool operator>= ( const CString& s ) const;
bool operator<= ( const CString& s ) const;
CT operator[] ( int i ) const;
const CT* Data() const { return _str; }
};
template <typename CT>
CString<CT>::CString( const CT* s ) {
_str = s;
_size = 0;
while( s[ _size ] != 0 ) _size++;
}
template <typename CT>
CString<CT>::CString( const CT* s, int sz ){
_str = s;
_size = sz;
}
template <typename CT>
int CString<CT>::Size() const {
return _size;
}
template <typename CT>
CT CString<CT>::operator[] ( int i ) const {
return _str[ i ];
}
template <typename CT>
bool CString<CT>::operator== ( const CString& s ) const {
int ret = 0;
if( s.Size() == this->Size()){
while( ret < this->Size() && s[ ret ] == (*this)[ ret ]){
ret++;
}
}
return ret == this->Size();
}
template <typename CT>
bool CString<CT>::operator!= ( const CString& s ) const {
return !((*this)==s);
}
template <typename CT>
bool CString<CT>::operator< ( const CString& s ) const {
int i= 0, sz = this->Size() > s.Size() ? s.Size() : this->Size();
bool neq = false;
while( i < sz && (*this)[i] <= s[i]) {
if( (*this)[i] < s[i]){
neq = 1;
break;
}
i++;
}
if( !neq && i == sz ){
if( this->Size() < s.Size() )
neq = 1;
}
return neq;
}
template <typename CT>
bool CString<CT>::operator> ( const CString& s ) const {
int i= 0, sz = this->Size() > s.Size() ? s.Size() : this->Size();
bool neq = false;
while( i < sz && (*this)[i] >= s[i]) {
if( (*this)[i] > s[i]){
neq = 1;
break;
}
i++;
}
if( !neq && i == sz ){
if( this->Size() > s.Size() )
neq = 1;
}
return neq;
}
template <typename CT>
bool CString<CT>::operator>= ( const CString& s ) const {
int i= 0, sz = this->Size() > s.Size() ? s.Size() : this->Size();
bool neq = false;
while( i < sz && (*this)[i] >= s[i]) {
if( (*this)[i] > s[i]){
neq = 1;
break;
}
i++;
}
if( !neq && this->Size() == s.Size() && i == sz )
neq = 1;
return neq;
}
template <typename CT>
bool CString<CT>::operator<= ( const CString& s ) const {
int i= 0, sz = this->Size() > s.Size() ? s.Size() : this->Size();
bool neq = false;
while( i < sz && (*this)[i] <= s[i]) {
if( (*this)[i] < s[i]){
neq = 1;
break;
}
i++;
}
if( !neq && this->Size() == s.Size() && i == sz )
neq = 1;
return neq;
}
}
#endif