-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQkString.h
148 lines (130 loc) · 3.89 KB
/
QkString.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#pragma once
//#include "pch.h"
class QkString
{
public:
enum { MAX_LOCAL_STRING_LEN = 15 };
QkString();
QkString(const TCHAR ch);
QkString(const CHAR* ch);
QkString(const QkString& src);
QkString(LPCTSTR lpsz, int nLen = -1);
~QkString();
static QkString & EmptyInstance(LPCTSTR lpstrId=0)
{
if (!lpstrId)
{
if (_EmptyInstance.GetLength()>0)
{
// 放空 : 释放栈区数据,保存类结构中的本地数据。
_EmptyInstance.Empty();
}
}
else
{
_EmptyInstance = lpstrId;
}
return _EmptyInstance;
};
void Empty();
size_t GetLength() const;
bool IsEmpty() const;
TCHAR GetAt(int nIndex) const;
bool EnsureCapacity(size_t newSz, bool release=false);
void AsBuffer(bool isBuffer=true){
_isBuffer = isBuffer;
}
size_t Capacity(){
return m_pstr==m_szBuffer?MAX_LOCAL_STRING_LEN:_capacity;
};
size_t RecalcSize();
void ReFit();
void Prepend(QkString & other) {
Prepend(other, other.GetLength());
};
void Prepend(LPCTSTR pstr, int nLength = -1);
void Append(QkString & other) {
Append(other, other.GetLength());
};
void Append(LPCTSTR pstr, int nLength = -1);
void Assign(QkString & other) {
Assign(other, other.GetLength());
};
void Assign(LPCTSTR pstr, int nLength = -1);
//QkString& AssignThenReturn(LPCTSTR pstr, int nLength = -1) {
// Assign(pstr, nLength);
// return *this;
//};
LPCTSTR GetData() const;
LPCSTR GetData(std::string & buffer, int offset=0, int length=-1) const;
static LPCSTR GetData(std::string & buffer, LPCWSTR pStr);
void SetAt(int nIndex, TCHAR ch);
operator LPCTSTR() const;
TCHAR operator[] (int nIndex) const;
const QkString& operator=(const QkString& src);
const QkString& operator=(const TCHAR ch);
const QkString& operator=(LPCTSTR pstr);
#ifdef _UNICODE
const QkString& operator=(LPCSTR lpStr);
const QkString& operator+=(LPCSTR lpStr);
#else
const QkString& operator=(LPCWSTR lpwStr);
const QkString& operator+=(LPCWSTR lpwStr);
#endif
QkString operator+(const QkString& src) const;
QkString operator+(LPCTSTR pstr) const;
const QkString& operator+=(const QkString& src);
const QkString& operator+=(LPCTSTR pstr);
const QkString& operator+=(const TCHAR ch);
bool operator == (LPCTSTR str) const;
bool operator != (LPCTSTR str) const;
bool operator == (const QkString & str) const;
bool operator != (const QkString & str) const;
bool operator <= (LPCTSTR str) const;
bool operator < (LPCTSTR str) const;
bool operator >= (LPCTSTR str) const;
bool operator > (LPCTSTR str) const;
int Compare(LPCTSTR pstr) const;
int CompareNoCase(LPCTSTR pstr) const;
void MakeUpper();
void MakeLower();
QkString Left(int nLength) const;
QkString Mid(int iPos, int nLength = -1) const;
void MidFast(int iPos, int nLength = -1);
//QkString * MidFake(int iPos, int nLength = -1);
QkString Right(int nLength) const;
int Find(TCHAR ch, int iPos = 0) const;
int Find(LPCTSTR pstr, int iPos = 0) const;
int ReverseFind(TCHAR ch) const;
int ReverseFind(LPCTSTR pstr, int iPos = 0) const;
int Replace(LPCTSTR pstrFrom, LPCTSTR pstrTo);
void Trim();
void Split(const QkString & delim, std::vector<QkString> & ret);
bool StartWith(const QkString & prefix, bool ignoreCase=false, int toffset=0) const;
bool EndWith(const QkString & other, bool ignoreCase=false) const;
int __cdecl Format(LPCTSTR pstrFormat, ...);
int __cdecl SmallFormat(LPCTSTR pstrFormat, ...);
protected:
int __cdecl InnerFormat(LPCTSTR pstrFormat, va_list Args);
protected:
LPTSTR m_pstr;
TCHAR m_szBuffer[MAX_LOCAL_STRING_LEN + 1];
size_t _size;
size_t _capacity;
bool _isBuffer;
static QkString _EmptyInstance;
};
static std::vector<QkString> StrSplit(QkString text, QkString sp)
{
std::vector<QkString> vResults;
int pos = text.Find(sp, 0);
while (pos >= 0)
{
QkString t = text.Left(pos);
vResults.push_back(t);
text = text.Right(text.GetLength() - pos - sp.GetLength());
pos = text.Find(sp);
}
vResults.push_back(text);
return vResults;
}