1 | /**********************************************************************
|
---|
2 | *<
|
---|
3 | FILE: strclass.h
|
---|
4 |
|
---|
5 | DESCRIPTION:
|
---|
6 |
|
---|
7 | CREATED BY: Dan Silva
|
---|
8 |
|
---|
9 | HISTORY:
|
---|
10 |
|
---|
11 | *> Copyright (c) 1994, All Rights Reserved.
|
---|
12 | **********************************************************************/
|
---|
13 |
|
---|
14 | #ifndef __STRCLASS__H
|
---|
15 | #define __STRCLASS__H
|
---|
16 |
|
---|
17 |
|
---|
18 | //-----------------------------------------------------------------------
|
---|
19 | // CStr: Simple char string class
|
---|
20 | //-----------------------------------------------------------------------
|
---|
21 | class CStr {
|
---|
22 | char *buf;
|
---|
23 | public:
|
---|
24 | UtilExport CStr();
|
---|
25 | UtilExport CStr(const char *cs);
|
---|
26 | UtilExport CStr(const wchar_t *wcstr);
|
---|
27 | UtilExport CStr(const CStr& ws);
|
---|
28 | UtilExport ~CStr();
|
---|
29 | UtilExport char *data();
|
---|
30 | UtilExport operator char *();
|
---|
31 |
|
---|
32 | // realloc to nchars (padding with blanks)
|
---|
33 | UtilExport void Resize(int nchars);
|
---|
34 |
|
---|
35 | UtilExport int Length();
|
---|
36 | int length() { return Length(); }
|
---|
37 | BOOL isNull() { return Length()==0?1:0; }
|
---|
38 |
|
---|
39 | UtilExport CStr & operator=(const CStr& cs);
|
---|
40 | UtilExport CStr & operator=(const wchar_t *wcstr);
|
---|
41 | UtilExport CStr & operator=(const char *cs);
|
---|
42 |
|
---|
43 | // Concatenation operators.
|
---|
44 | UtilExport CStr operator+(const CStr& cs) const;
|
---|
45 | UtilExport CStr& operator+=(const CStr& cs);
|
---|
46 | CStr& Append(const CStr& cs) { return ((*this) += cs); }
|
---|
47 | CStr& append(const CStr& cs) { return ((*this) += cs); }
|
---|
48 | UtilExport CStr& remove(int pos); // remove all chars from pos to end
|
---|
49 | UtilExport CStr& remove(int pos, int N); // remove N chars from pos to end
|
---|
50 |
|
---|
51 | // Substring operator
|
---|
52 | UtilExport CStr Substr(int start, int nchars) const;
|
---|
53 | UtilExport char& operator[](int i);
|
---|
54 |
|
---|
55 | // Char search:(return -1 if not found)
|
---|
56 | UtilExport int first(char c);
|
---|
57 | UtilExport int last(char c);
|
---|
58 |
|
---|
59 | // Comparison
|
---|
60 | UtilExport int operator==(const CStr &cs) const;
|
---|
61 | UtilExport int operator<(const CStr &cs) const;
|
---|
62 | UtilExport int operator<=(const CStr &ws) const;
|
---|
63 | UtilExport int operator>(const CStr &ws) const;
|
---|
64 | UtilExport int operator>=(const CStr &ws) const;
|
---|
65 |
|
---|
66 | UtilExport void toUpper();
|
---|
67 | UtilExport void toLower();
|
---|
68 |
|
---|
69 | UtilExport int printf(const char *format, ...);
|
---|
70 | };
|
---|
71 |
|
---|
72 |
|
---|
73 | //-----------------------------------------------------------------------
|
---|
74 | // WStr: Simple Wide char string class
|
---|
75 | //-----------------------------------------------------------------------
|
---|
76 | class WStr {
|
---|
77 | wchar_t *buf;
|
---|
78 | public:
|
---|
79 | UtilExport WStr();
|
---|
80 | UtilExport WStr(const char *cs);
|
---|
81 | UtilExport WStr(const wchar_t *wcstr);
|
---|
82 | UtilExport WStr(const WStr& ws);
|
---|
83 | UtilExport ~WStr();
|
---|
84 | UtilExport wchar_t *data();
|
---|
85 | UtilExport operator wchar_t *();
|
---|
86 |
|
---|
87 | // realloc to nchars (padding with blanks)
|
---|
88 | UtilExport void Resize(int nchars);
|
---|
89 | UtilExport int Length();
|
---|
90 | int length() { return Length(); }
|
---|
91 | BOOL isNull() { return Length()==0?1:0; }
|
---|
92 |
|
---|
93 | UtilExport WStr & operator=(const WStr& ws);
|
---|
94 | UtilExport WStr & operator=(const wchar_t *wcstr);
|
---|
95 | UtilExport WStr & operator=(const char *cstr);
|
---|
96 |
|
---|
97 | // Concatenation operators.
|
---|
98 | UtilExport WStr operator+(const WStr& ws) const;
|
---|
99 | UtilExport WStr & operator+=(const WStr& ws);
|
---|
100 | WStr& Append(const WStr& ws) { return ((*this) += ws); }
|
---|
101 | WStr& append(const WStr& ws) { return ((*this) += ws); }
|
---|
102 | UtilExport WStr& remove(int pos); // remove chars from pos to end
|
---|
103 | UtilExport WStr& remove(int pos, int N); // remove N chars from pos to end
|
---|
104 |
|
---|
105 | // Substring operator
|
---|
106 | UtilExport WStr Substr(int start, int nchars) const;
|
---|
107 | wchar_t& operator[](int i) {return buf[i];}
|
---|
108 |
|
---|
109 | // Char search:(return -1 if not found)
|
---|
110 | UtilExport int first(wchar_t c);
|
---|
111 | UtilExport int last(wchar_t c);
|
---|
112 |
|
---|
113 | // Comparison
|
---|
114 | UtilExport int operator==(const WStr &ws) const;
|
---|
115 | UtilExport int operator<(const WStr &ws) const;
|
---|
116 | UtilExport int operator<=(const WStr &ws) const;
|
---|
117 | UtilExport int operator>(const WStr &ws) const;
|
---|
118 | UtilExport int operator>=(const WStr &ws) const;
|
---|
119 |
|
---|
120 | UtilExport void toUpper();
|
---|
121 | UtilExport void toLower();
|
---|
122 | UtilExport int printf(const wchar_t *format, ...);
|
---|
123 | };
|
---|
124 |
|
---|
125 |
|
---|
126 |
|
---|
127 | #ifdef _UNICODE
|
---|
128 | #define TSTR WStr
|
---|
129 | #else
|
---|
130 | #define TSTR CStr
|
---|
131 | #endif
|
---|
132 |
|
---|
133 | //--FilterList----------------------------------------------------------------------
|
---|
134 | // A class whose sole purpose is for buildingup a filter list to passing to
|
---|
135 | // GetSaveFileName and GetOpenFileName. It automatically puts in the imbedded nulls
|
---|
136 | // and two terminating nulls.
|
---|
137 | // Example:
|
---|
138 | //
|
---|
139 | // FilterList filterList;
|
---|
140 | // filterList.Append( _T("Jaguar files(*.jag)"));
|
---|
141 | // filterList.Append( _T("*.jag"));
|
---|
142 | // ofn.lpstrFilter = filterList;
|
---|
143 | // GetSaveFileName(&ofn)
|
---|
144 | //----------------------------------------------------------------------------------
|
---|
145 | class FilterList {
|
---|
146 | #define LISTBUFLEN 2048
|
---|
147 | public:
|
---|
148 | TCHAR buf[LISTBUFLEN];
|
---|
149 | int length;
|
---|
150 | FilterList() {
|
---|
151 | memset(buf,0,LISTBUFLEN);
|
---|
152 | length = 0;
|
---|
153 | }
|
---|
154 | UtilExport void Append(TCHAR *name);
|
---|
155 | operator TCHAR *() { return buf; }
|
---|
156 | };
|
---|
157 |
|
---|
158 |
|
---|
159 | /*------------------------------------------------
|
---|
160 | Split filename "name" into
|
---|
161 | p path
|
---|
162 | f filename
|
---|
163 | e extension
|
---|
164 | -------------------------------------------------*/
|
---|
165 |
|
---|
166 | UtilExport void SplitFilename(TSTR& name,TSTR* p, TSTR* f, TSTR* e);
|
---|
167 |
|
---|
168 | /*--------------------------------------------------
|
---|
169 | Split filename "name" into
|
---|
170 | p path
|
---|
171 | f filename.ext
|
---|
172 | -------------------------------------------------*/
|
---|
173 |
|
---|
174 | UtilExport void SplitPathFile(TSTR& name,TSTR* p, TSTR* f);
|
---|
175 |
|
---|
176 | #endif
|
---|