ReactOS  0.4.14-dev-838-g99f979d
chstring.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifndef _CHSTRING_H
4 #define _CHSTRING_H
5 
6 #include <windows.h>
7 #include <provexce.h>
8 
10 {
11  long nRefs;
14 
16  {
17  return (WCHAR*)(this+1);
18  }
19 };
20 
21 class CHString
22 {
23 public:
24  CHString();
25  CHString(WCHAR ch, int nRepeat = 1);
26  CHString(LPCWSTR lpsz);
27  CHString(LPCWSTR lpch, int nLength);
28  CHString(LPCSTR lpsz);
29  CHString(const CHString& stringSrc);
30  CHString(const unsigned char* lpsz);
31  ~CHString();
32 
33  BSTR AllocSysString() const;
34  int Collate(LPCWSTR lpsz) const;
35  int Compare(LPCWSTR lpsz) const;
36  int CompareNoCase(LPCWSTR lpsz) const;
37  void Empty();
38  int Find(WCHAR ch) const;
39  int Find(LPCWSTR lpszSub) const;
40  int FindOneOf(LPCWSTR lpszCharSet) const;
41  void Format(UINT nFormatID, ...);
42  void Format(LPCWSTR lpszFormat, ...);
43  void FormatMessageW(UINT nFormatID, ...);
44  void FormatMessageW(LPCWSTR lpszFormat, ...);
45  void FormatV(LPCWSTR lpszFormat, va_list argList);
46  void FreeExtra();
47  int GetAllocLength() const;
48  WCHAR GetAt(int nIndex) const;
49  LPWSTR GetBuffer(int nMinBufLength);
50  LPWSTR GetBufferSetLength(int nNewLength);
51  int GetLength() const;
52  BOOL IsEmpty() const;
53  CHString Left(int nCount) const;
54  int LoadStringW(UINT nID);
56  void MakeLower();
57  void MakeReverse();
58  void MakeUpper();
59  CHString Mid(int nFirst) const;
60  CHString Mid(int nFirst, int nCount) const;
61  void ReleaseBuffer(int nNewLength = -1);
62  int ReverseFind(WCHAR ch) const;
63  CHString Right(int nCount) const;
64  void SetAt(int nIndex, WCHAR ch);
65  CHString SpanExcluding(LPCWSTR lpszCharSet) const;
66  CHString SpanIncluding(LPCWSTR lpszCharSet) const;
67  void TrimLeft();
68  void TrimRight();
69  void UnlockBuffer();
70 
71  const CHString& operator=(char ch);
72  const CHString& operator=(WCHAR ch);
73  const CHString& operator=(CHString *p);
74  const CHString& operator=(LPCSTR lpsz);
75  const CHString& operator=(LPCWSTR lpsz);
76  const CHString& operator=(const CHString& stringSrc);
77  const CHString& operator=(const unsigned char* lpsz);
78 
79  const CHString& operator+=(char ch);
80  const CHString& operator+=(WCHAR ch);
81  const CHString& operator+=(LPCWSTR lpsz);
82  const CHString& operator+=(const CHString& string);
83 
84  WCHAR operator[](int nIndex) const;
85 
86  operator LPCWSTR() const;
87 
88  friend CHString WINAPI operator+(WCHAR ch, const CHString& string);
89  friend CHString WINAPI operator+(const CHString& string, WCHAR ch);
90  friend CHString WINAPI operator+(const CHString& string, LPCWSTR lpsz);
91  friend CHString WINAPI operator+(LPCWSTR lpsz, const CHString& string);
92  friend CHString WINAPI operator+(const CHString& string1, const CHString& string2);
93 
94 protected:
96 
97  void AllocBeforeWrite(int nLen);
98  void AllocBuffer(int nLen);
99  void AllocCopy(CHString& dest, int nCopyLen, int nCopyIndex, int nExtraLen) const;
100  void AssignCopy(int nSrcLen, LPCWSTR lpszSrcData);
101  void ConcatCopy(int nSrc1Len, LPCWSTR lpszSrc1Data, int nSrc2Len, LPCWSTR lpszSrc2Data);
102  void ConcatInPlace(int nSrcLen, LPCWSTR lpszSrcData);
103  void CopyBeforeWrite();
104  CHStringData* GetData() const;
105  void Init();
106  int LoadStringW(UINT nID, LPWSTR lpszBuf, UINT nMaxBuf);
107  void Release();
108  static void WINAPI Release(CHStringData* pData);
109  static int WINAPI SafeStrlen(LPCWSTR lpsz);
110 };
111 
112 inline BOOL operator==(const CHString& s1, LPCWSTR s2) { return s1.Compare(s2) == 0; }
113 inline BOOL operator==(const CHString& s1, const CHString& s2) { return s1.Compare(s2) == 0; }
114 
115 inline BOOL operator!=(const CHString& s1, LPCWSTR s2) { return s1.Compare(s2) != 0; }
116 inline BOOL operator!=(const CHString& s1, const CHString& s2) { return s1.Compare(s2) != 0; }
117 
118 inline BOOL operator<(const CHString& s1, LPCWSTR s2) { return s1.Compare(s2) < 0; }
119 inline BOOL operator<(const CHString& s1, const CHString& s2) { return s1.Compare(s2) < 0; }
120 
121 inline BOOL operator>(const CHString& s1, LPCWSTR s2) { return s1.Compare(s2) > 0; }
122 inline BOOL operator>(const CHString& s1, const CHString& s2) { return s1.Compare(s2) > 0; }
123 
124 inline BOOL operator<=(const CHString& s1, LPCWSTR s2) { return s1.Compare(s2) <= 0; }
125 inline BOOL operator<=(const CHString& s1, const CHString& s2) { return s1.Compare(s2) <= 0; }
126 
127 inline BOOL operator>=(const CHString& s1, LPCWSTR s2) { return s1.Compare(s2) >= 0; }
128 inline BOOL operator>=(const CHString& s1, const CHString& s2) { return s1.Compare(s2) >= 0; }
129 
130 #endif
CHStringData * GetData() const
Definition: chstring.cpp:747
void ConcatInPlace(int nSrcLen, LPCWSTR lpszSrcData)
Definition: chstring.cpp:430
struct S2 s2
void UnlockBuffer()
Definition: chstring.cpp:1155
BOOL operator>=(const CHString &s1, LPCWSTR s2)
Definition: chstring.h:127
void Format(UINT nFormatID,...)
Definition: chstring.cpp:612
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
void Init()
Definition: chstring.cpp:770
void AllocBeforeWrite(int nLen)
Definition: chstring.cpp:253
void Empty()
Definition: chstring.cpp:530
static CHAR string2[MAX_PATH]
Definition: automation.c:468
int nAllocLength
Definition: chstring.h:13
CHString Left(int nCount) const
Definition: chstring.cpp:786
void ReleaseBuffer(int nNewLength=-1)
Definition: chstring.cpp:961
_In_ DWORD nLength
Definition: wincon.h:461
int nDataLength
Definition: chstring.h:12
static CHAR string1[MAX_PATH]
Definition: asmname.c:32
void ConcatCopy(int nSrc1Len, LPCWSTR lpszSrc1Data, int nSrc2Len, LPCWSTR lpszSrc2Data)
Definition: chstring.cpp:479
OLECHAR * BSTR
Definition: compat.h:1942
int LoadStringW(UINT nID)
Definition: chstring.cpp:807
void AssignCopy(int nSrcLen, LPCWSTR lpszSrcData)
Definition: chstring.cpp:374
void TrimLeft()
Definition: chstring.cpp:1074
void MakeUpper()
Definition: chstring.cpp:863
unsigned int BOOL
Definition: ntddk_ex.h:94
CHString Right(int nCount) const
Definition: chstring.cpp:1002
WCHAR * data()
Definition: chstring.h:15
const CHString & operator+=(char ch)
Definition: chstring.cpp:1280
BOOL operator>(const CHString &s1, LPCWSTR s2)
Definition: chstring.h:121
LPWSTR LockBuffer()
Definition: chstring.cpp:825
LPWSTR m_pchData
Definition: chstring.h:95
char * va_list
Definition: acmsvcex.h:78
const char * LPCSTR
Definition: xmlstorage.h:183
void AllocCopy(CHString &dest, int nCopyLen, int nCopyIndex, int nExtraLen) const
Definition: chstring.cpp:319
void FormatV(LPCWSTR lpszFormat, va_list argList)
Definition: chstring.cpp:651
void MakeLower()
Definition: chstring.cpp:839
LPWSTR GetBufferSetLength(int nNewLength)
Definition: chstring.cpp:733
BOOL operator==(const CHString &s1, LPCWSTR s2)
Definition: chstring.h:112
long nRefs
Definition: chstring.h:11
__wchar_t WCHAR
Definition: xmlstorage.h:180
void SetAt(int nIndex, WCHAR ch)
Definition: chstring.cpp:1040
void AllocBuffer(int nLen)
Definition: chstring.cpp:269
CHString SpanIncluding(LPCWSTR lpszCharSet) const
Definition: chstring.cpp:1062
struct S1 s1
int Find(WCHAR ch) const
Definition: chstring.cpp:555
#define WINAPI
Definition: msvc.h:6
friend CHString WINAPI operator+(WCHAR ch, const CHString &string)
Definition: chstring.cpp:1337
BOOL operator!=(const CHString &s1, LPCWSTR s2)
Definition: chstring.h:115
void Release()
Definition: chstring.cpp:921
void FreeExtra()
Definition: chstring.cpp:659
void MakeReverse()
Definition: chstring.cpp:851
LPWSTR GetBuffer(int nMinBufLength)
Definition: chstring.cpp:698
HRESULT Compare(IMFAttributes *pTheirs, MF_ATTRIBUTES_MATCH_TYPE MatchType, [out] BOOL *pbResult)
int ReverseFind(WCHAR ch) const
Definition: chstring.cpp:983
int GetLength() const
Definition: chstring.cpp:762
int Collate(LPCWSTR lpsz) const
Definition: chstring.cpp:400
int Compare(LPCWSTR lpsz) const
Definition: chstring.cpp:410
unsigned int UINT
Definition: ndis.h:50
CHString Mid(int nFirst) const
Definition: chstring.cpp:875
void FormatMessageW(UINT nFormatID,...)
Definition: chstring.cpp:634
const CHString & operator=(char ch)
Definition: chstring.cpp:1168
int CompareNoCase(LPCWSTR lpsz) const
Definition: chstring.cpp:420
BOOL operator<=(const CHString &s1, LPCWSTR s2)
Definition: chstring.h:124
CHString SpanExcluding(LPCWSTR lpszCharSet) const
Definition: chstring.cpp:1050
WCHAR GetAt(int nIndex) const
Definition: chstring.cpp:689
BOOL IsEmpty() const
Definition: chstring.cpp:778
static char * dest
Definition: rtl.c:135
BSTR AllocSysString() const
Definition: chstring.cpp:357
GLfloat GLfloat p
Definition: glext.h:8902
WCHAR * LPWSTR
Definition: xmlstorage.h:184
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
void CopyBeforeWrite()
Definition: chstring.cpp:505
WCHAR operator[](int nIndex) const
Definition: chstring.cpp:1321
BOOL operator<(const CHString &s1, LPCWSTR s2)
Definition: chstring.h:118
static int WINAPI SafeStrlen(LPCWSTR lpsz)
Definition: chstring.cpp:1023
int FindOneOf(LPCWSTR lpszCharSet) const
Definition: chstring.cpp:593
int GetAllocLength() const
Definition: chstring.cpp:681
void TrimRight()
Definition: chstring.cpp:1107