LMMS
Loading...
Searching...
No Matches
fstrdefs.h
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// Project : SDK Core
3//
4// Category : SDK Core Interfaces
5// Filename : pluginterfaces/base/fstrdefs.h
6// Created by : Steinberg, 01/2004
7// Description : Definitions for handling strings (Unicode / ASCII / Platforms)
8//
9//-----------------------------------------------------------------------------
10// This file is part of a Steinberg SDK. It is subject to the license terms
11// in the LICENSE file found in the top-level directory of this distribution
12// and at www.steinberg.net/sdklicenses.
13// No part of the SDK, including this file, may be copied, modified, propagated,
14// or distributed except according to the terms contained in the LICENSE file.
15//-----------------------------------------------------------------------------
16
17#pragma once
18
19#include "ftypes.h"
20
21//----------------------------------------------------------------------------
23//----------------------------------------------------------------------------
24
25// 16 bit string operations
26#if SMTG_CPP11 // if c++11 unicode string literals
27 #define SMTG_CPP11_CAT_PRIVATE_DONT_USE(a,b) a ## b
28 #if SMTG_OS_WINDOWS
29 #define STR16(x) SMTG_CPP11_CAT_PRIVATE_DONT_USE(L,x)
30 #else
31 #define STR16(x) SMTG_CPP11_CAT_PRIVATE_DONT_USE(u,x)
32 #endif
33#else
34 #include "conststringtable.h"
35 #define STR16(x) Steinberg::ConstStringTable::instance ()->getString (x)
36#endif
37
38#ifdef UNICODE
39 #define STR(x) STR16(x)
40 #define tStrBufferSize(buffer) (sizeof(buffer)/sizeof(Steinberg::tchar))
41
42#else
43 #define STR(x) x
44 #define tStrBufferSize(buffer) (sizeof(buffer))
45#endif
46
47#define str8BufferSize(buffer) (sizeof(buffer)/sizeof(Steinberg::char8))
48#define str16BufferSize(buffer) (sizeof(buffer)/sizeof(Steinberg::char16))
49
50#if SMTG_OS_WINDOWS
51#define FORMAT_INT64A "I64d"
52#define FORMAT_UINT64A "I64u"
53
54#elif SMTG_OS_MACOS || SMTG_OS_LINUX
55#define FORMAT_INT64A "lld"
56#define FORMAT_UINT64A "llu"
57#define stricmp strcasecmp
58#define strnicmp strncasecmp
59#endif
60
61#ifdef UNICODE
62#define FORMAT_INT64W STR(FORMAT_INT64A)
63#define FORMAT_UINT64W STR(FORMAT_UINT64A)
64
65#define FORMAT_INT64 FORMAT_INT64W
66#define FORMAT_UINT64 FORMAT_UINT64W
67#else
68#define FORMAT_INT64 FORMAT_INT64A
69#define FORMAT_UINT64 FORMAT_UINT64A
70#endif
71
72
73//----------------------------------------------------------------------------
74// newline
75//----------------------------------------------------------------------------
76#if SMTG_OS_WINDOWS
77#define ENDLINE_A "\r\n"
78#define ENDLINE_W STR ("\r\n")
79#elif SMTG_OS_MACOS
80#define ENDLINE_A "\r"
81#define ENDLINE_W STR ("\r")
82#elif SMTG_OS_LINUX
83#define ENDLINE_A "\n"
84#define ENDLINE_W STR ("\n")
85#endif
86
87#ifdef UNICODE
88#define ENDLINE ENDLINE_W
89#else
90#define ENDLINE ENDLINE_A
91#endif
92
93#if SMTG_OS_WINDOWS && !defined(__GNUC__) && defined(_MSC_VER) && (_MSC_VER < 1900)
94#define stricmp _stricmp
95#define strnicmp _strnicmp
96#define snprintf _snprintf
97#endif
98
99namespace Steinberg {
100
101//----------------------------------------------------------------------------
102static const tchar kEmptyString[] = { 0 };
103static const char8 kEmptyString8[] = { 0 };
104static const char16 kEmptyString16[] = { 0 };
105
106#ifdef UNICODE
107static const tchar kInfiniteSymbol[] = { 0x221E, 0 };
108#else
109static const tchar* const kInfiniteSymbol = STR ("oo");
110#endif
111
112//----------------------------------------------------------------------------
113template <class T>
114inline int32 _tstrlen (const T* wcs)
115{
116 const T* eos = wcs;
117
118 while (*eos++)
119 ;
120
121 return (int32) (eos - wcs - 1);
122}
123
124inline int32 tstrlen (const tchar* str) {return _tstrlen (str);}
125inline int32 strlen8 (const char8* str) {return _tstrlen (str);}
126inline int32 strlen16 (const char16* str) {return _tstrlen (str);}
127
128//----------------------------------------------------------------------------
129template <class T>
130inline int32 _tstrcmp (const T* src, const T* dst)
131{
132 while (*src == *dst && *dst)
133 {
134 src++;
135 dst++;
136 }
137
138 if (*src == 0 && *dst == 0)
139 return 0;
140 else if (*src == 0)
141 return -1;
142 else if (*dst == 0)
143 return 1;
144 else
145 return (int32) (*src - *dst);
146}
147
148inline int32 tstrcmp (const tchar* src, const tchar* dst) {return _tstrcmp (src, dst);}
149inline int32 strcmp8 (const char8* src, const char8* dst) {return _tstrcmp (src, dst);}
150inline int32 strcmp16 (const char16* src, const char16* dst) {return _tstrcmp (src, dst);}
151
152template <typename T>
153inline int32 strcmpT (const T* first, const T* last);
154
155template <>
156inline int32 strcmpT<char8> (const char8* first, const char8* last) { return _tstrcmp (first, last); }
157
158template <>
159inline int32 strcmpT<char16> (const char16* first, const char16* last) { return _tstrcmp (first, last); }
160
161//----------------------------------------------------------------------------
162template <class T>
163inline int32 _tstrncmp (const T* first, const T* last, uint32 count)
164{
165 if (count == 0)
166 return 0;
167
168 while (--count && *first && *first == *last)
169 {
170 first++;
171 last++;
172 }
173
174 if (*first == 0 && *last == 0)
175 return 0;
176 else if (*first == 0)
177 return -1;
178 else if (*last == 0)
179 return 1;
180 else
181 return (int32) (*first - *last);
182}
183
184inline int32 tstrncmp (const tchar* first, const tchar* last, uint32 count) {return _tstrncmp (first, last, count);}
185inline int32 strncmp8 (const char8* first, const char8* last, uint32 count) {return _tstrncmp (first, last, count);}
186inline int32 strncmp16 (const char16* first, const char16* last, uint32 count) {return _tstrncmp (first, last, count);}
187
188template <typename T>
189inline int32 strncmpT (const T* first, const T* last, uint32 count);
190
191template <>
192inline int32 strncmpT<char8> (const char8* first, const char8* last, uint32 count) { return _tstrncmp (first, last, count); }
193
194template <>
195inline int32 strncmpT<char16> (const char16* first, const char16* last, uint32 count) {return _tstrncmp (first, last, count); }
196
197//----------------------------------------------------------------------------
198template <class T>
199inline T* _tstrcpy (T* dst, const T* src)
200{
201 T* cp = dst;
202 while ((*cp++ = *src++) != 0) // copy string
203 ;
204 return dst;
205}
206inline tchar* tstrcpy (tchar* dst, const tchar* src) {return _tstrcpy (dst, src);}
207inline char8* strcpy8 (char8* dst, const char8* src) {return _tstrcpy (dst, src);}
208inline char16* strcpy16 (char16* dst, const char16* src) {return _tstrcpy (dst, src);}
209
210//----------------------------------------------------------------------------
211template <class T>
212inline T* _tstrncpy (T* dest, const T* source, uint32 count)
213{
214 T* start = dest;
215 while (count && (*dest++ = *source++) != 0) // copy string
216 count--;
217
218 if (count) // pad out with zeros
219 {
220 while (--count)
221 *dest++ = 0;
222 }
223 return start;
224}
225
226inline tchar* tstrncpy (tchar* dest, const tchar* source, uint32 count) {return _tstrncpy (dest, source, count);}
227inline char8* strncpy8 (char8* dest, const char8* source, uint32 count) {return _tstrncpy (dest, source, count);}
228inline char16* strncpy16 (char16* dest, const char16* source, uint32 count) {return _tstrncpy (dest, source, count);}
229
230//----------------------------------------------------------------------------
231template <class T>
232inline T* _tstrcat (T* dst, const T* src)
233{
234 T* cp = dst;
235
236 while (*cp)
237 cp++; // find end of dst
238
239 while ((*cp++ = *src++) != 0) // Copy src to end of dst
240 ;
241
242 return dst;
243}
244
245inline tchar* tstrcat (tchar* dst, const tchar* src) {return _tstrcat (dst, src); }
246inline char8* strcat8 (char8* dst, const char8* src) {return _tstrcat (dst, src); }
247inline char16* strcat16 (char16* dst, const char16* src) {return _tstrcat (dst, src); }
248
249//----------------------------------------------------------------------------
250inline void str8ToStr16 (char16* dst, const char8* src, int32 n = -1)
251{
252 int32 i = 0;
253 for (;;)
254 {
255 if (i == n)
256 {
257 dst[i] = 0;
258 return;
259 }
260
261#if BYTEORDER == kBigEndian
262 char8* pChr = (char8*)&dst[i];
263 pChr[0] = 0;
264 pChr[1] = src[i];
265#else
266 dst[i] = static_cast<char16> (src[i]);
267#endif
268 if (src[i] == 0)
269 break;
270 i++;
271 }
272
273 while (n > i)
274 {
275 dst[i] = 0;
276 i++;
277 }
278}
279
280//------------------------------------------------------------------------
281inline bool FIDStringsEqual (FIDString id1, FIDString id2)
282{
283 return (id1 && id2) ? (strcmp8 (id1, id2) == 0) : false;
284}
285
286static const uint32 kPrintfBufferSize = 4096;
287
288//------------------------------------------------------------------------
289} // namespace Steinberg
register unsigned i
Definition inflate.c:1575
#define STR(x)
Definition fstrdefs.h:39
virtual ASIOError start()=0
Definition baseiids.cpp:43
T * _tstrcat(T *dst, const T *src)
Definition fstrdefs.h:232
int16 char16
Definition ftypes.h:101
int int32
Definition ftypes.h:50
static const uint32 kPrintfBufferSize
Definition fstrdefs.h:286
int32 strlen8(const char8 *str)
Definition fstrdefs.h:125
int32 strcmpT(const T *first, const T *last)
int32 tstrcmp(const tchar *src, const tchar *dst)
Definition fstrdefs.h:148
int32 strcmpT< char8 >(const char8 *first, const char8 *last)
Definition fstrdefs.h:156
void str8ToStr16(char16 *dst, const char8 *src, int32 n=-1)
Definition fstrdefs.h:250
static const char16 kEmptyString16[]
Definition fstrdefs.h:104
int32 tstrncmp(const tchar *first, const tchar *last, uint32 count)
Definition fstrdefs.h:184
char char8
Definition ftypes.h:93
int32 strcmpT< char16 >(const char16 *first, const char16 *last)
Definition fstrdefs.h:159
int32 strncmp16(const char16 *first, const char16 *last, uint32 count)
Definition fstrdefs.h:186
int32 _tstrcmp(const T *src, const T *dst)
Definition fstrdefs.h:130
static const tchar kEmptyString[]
Definition fstrdefs.h:102
T * _tstrcpy(T *dst, const T *src)
Definition fstrdefs.h:199
tchar * tstrncpy(tchar *dest, const tchar *source, uint32 count)
Definition fstrdefs.h:226
const char8 * FIDString
Definition ftypes.h:117
static const char8 kEmptyString8[]
Definition fstrdefs.h:103
int32 strncmpT< char8 >(const char8 *first, const char8 *last, uint32 count)
Definition fstrdefs.h:192
int32 strncmp8(const char8 *first, const char8 *last, uint32 count)
Definition fstrdefs.h:185
tchar * tstrcpy(tchar *dst, const tchar *src)
Definition fstrdefs.h:206
int32 strcmp8(const char8 *src, const char8 *dst)
Definition fstrdefs.h:149
int32 strcmp16(const char16 *src, const char16 *dst)
Definition fstrdefs.h:150
T * _tstrncpy(T *dest, const T *source, uint32 count)
Definition fstrdefs.h:212
char16 * strncpy16(char16 *dest, const char16 *source, uint32 count)
Definition fstrdefs.h:228
char16 tchar
Definition ftypes.h:105
int32 _tstrlen(const T *wcs)
Definition fstrdefs.h:114
char8 * strcat8(char8 *dst, const char8 *src)
Definition fstrdefs.h:246
int32 strlen16(const char16 *str)
Definition fstrdefs.h:126
tchar * tstrcat(tchar *dst, const tchar *src)
Definition fstrdefs.h:245
static const tchar kInfiniteSymbol[]
Definition fstrdefs.h:107
int32 tstrlen(const tchar *str)
Definition fstrdefs.h:124
char8 * strncpy8(char8 *dest, const char8 *source, uint32 count)
Definition fstrdefs.h:227
int32 strncmpT< char16 >(const char16 *first, const char16 *last, uint32 count)
Definition fstrdefs.h:195
char16 * strcat16(char16 *dst, const char16 *src)
Definition fstrdefs.h:247
int32 strncmpT(const T *first, const T *last, uint32 count)
bool FIDStringsEqual(FIDString id1, FIDString id2)
Definition fstrdefs.h:281
int32 _tstrncmp(const T *first, const T *last, uint32 count)
Definition fstrdefs.h:163
unsigned int uint32
Definition ftypes.h:51
char16 * strcpy16(char16 *dst, const char16 *src)
Definition fstrdefs.h:208
char8 * strcpy8(char8 *dst, const char8 *src)
Definition fstrdefs.h:207
int n
Definition crypt.c:458
char * cp
Definition unix.c:513
_WDL_CSTRING_PREFIX void INT_PTR count
Definition wdlcstring.h:263