Add initial bits for Qt6 support
[carla.git] / source / includes / vst3sdk / pluginterfaces / base / fstrdefs.h
blob00eaa1de98a243ae635b7f5ce482f1b6adf3ef3a
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 //-----------------------------------------------------------------------------
17 #pragma once
19 #include "ftypes.h"
21 //----------------------------------------------------------------------------
22 /** string methods defines unicode / ASCII */
23 //----------------------------------------------------------------------------
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
38 #ifdef UNICODE
39 #define STR(x) STR16(x)
40 #define tStrBufferSize(buffer) (sizeof(buffer)/sizeof(Steinberg::tchar))
42 #else
43 #define STR(x) x
44 #define tStrBufferSize(buffer) (sizeof(buffer))
45 #endif
47 #define str8BufferSize(buffer) (sizeof(buffer)/sizeof(Steinberg::char8))
48 #define str16BufferSize(buffer) (sizeof(buffer)/sizeof(Steinberg::char16))
50 #if SMTG_OS_WINDOWS
51 #define FORMAT_INT64A "I64d"
52 #define FORMAT_UINT64A "I64u"
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
61 #ifdef UNICODE
62 #define FORMAT_INT64W STR(FORMAT_INT64A)
63 #define FORMAT_UINT64W STR(FORMAT_UINT64A)
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
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
87 #ifdef UNICODE
88 #define ENDLINE ENDLINE_W
89 #else
90 #define ENDLINE ENDLINE_A
91 #endif
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
99 namespace Steinberg {
101 //----------------------------------------------------------------------------
102 static const tchar kEmptyString[] = { 0 };
103 static const char8 kEmptyString8[] = { 0 };
104 static const char16 kEmptyString16[] = { 0 };
106 #ifdef UNICODE
107 static const tchar kInfiniteSymbol[] = { 0x221E, 0 };
108 #else
109 static const tchar* const kInfiniteSymbol = STR ("oo");
110 #endif
112 //----------------------------------------------------------------------------
113 template <class T>
114 inline int32 _tstrlen (const T* wcs)
116 const T* eos = wcs;
118 while (*eos++)
121 return (int32) (eos - wcs - 1);
124 inline int32 tstrlen (const tchar* str) {return _tstrlen (str);}
125 inline int32 strlen8 (const char8* str) {return _tstrlen (str);}
126 inline int32 strlen16 (const char16* str) {return _tstrlen (str);}
128 //----------------------------------------------------------------------------
129 template <class T>
130 inline int32 _tstrcmp (const T* src, const T* dst)
132 while (*src == *dst && *dst)
134 src++;
135 dst++;
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);
148 inline int32 tstrcmp (const tchar* src, const tchar* dst) {return _tstrcmp (src, dst);}
149 inline int32 strcmp8 (const char8* src, const char8* dst) {return _tstrcmp (src, dst);}
150 inline int32 strcmp16 (const char16* src, const char16* dst) {return _tstrcmp (src, dst);}
152 template <typename T>
153 inline int32 strcmpT (const T* first, const T* last);
155 template <>
156 inline int32 strcmpT<char8> (const char8* first, const char8* last) { return _tstrcmp (first, last); }
158 template <>
159 inline int32 strcmpT<char16> (const char16* first, const char16* last) { return _tstrcmp (first, last); }
161 //----------------------------------------------------------------------------
162 template <class T>
163 inline int32 _tstrncmp (const T* first, const T* last, uint32 count)
165 if (count == 0)
166 return 0;
168 while (--count && *first && *first == *last)
170 first++;
171 last++;
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);
184 inline int32 tstrncmp (const tchar* first, const tchar* last, uint32 count) {return _tstrncmp (first, last, count);}
185 inline int32 strncmp8 (const char8* first, const char8* last, uint32 count) {return _tstrncmp (first, last, count);}
186 inline int32 strncmp16 (const char16* first, const char16* last, uint32 count) {return _tstrncmp (first, last, count);}
188 template <typename T>
189 inline int32 strncmpT (const T* first, const T* last, uint32 count);
191 template <>
192 inline int32 strncmpT<char8> (const char8* first, const char8* last, uint32 count) { return _tstrncmp (first, last, count); }
194 template <>
195 inline int32 strncmpT<char16> (const char16* first, const char16* last, uint32 count) {return _tstrncmp (first, last, count); }
197 //----------------------------------------------------------------------------
198 template <class T>
199 inline T* _tstrcpy (T* dst, const T* src)
201 T* cp = dst;
202 while ((*cp++ = *src++) != 0) // copy string
204 return dst;
206 inline tchar* tstrcpy (tchar* dst, const tchar* src) {return _tstrcpy (dst, src);}
207 inline char8* strcpy8 (char8* dst, const char8* src) {return _tstrcpy (dst, src);}
208 inline char16* strcpy16 (char16* dst, const char16* src) {return _tstrcpy (dst, src);}
210 //----------------------------------------------------------------------------
211 template <class T>
212 inline T* _tstrncpy (T* dest, const T* source, uint32 count)
214 T* start = dest;
215 while (count && (*dest++ = *source++) != 0) // copy string
216 count--;
218 if (count) // pad out with zeros
220 while (--count)
221 *dest++ = 0;
223 return start;
226 inline tchar* tstrncpy (tchar* dest, const tchar* source, uint32 count) {return _tstrncpy (dest, source, count);}
227 inline char8* strncpy8 (char8* dest, const char8* source, uint32 count) {return _tstrncpy (dest, source, count);}
228 inline char16* strncpy16 (char16* dest, const char16* source, uint32 count) {return _tstrncpy (dest, source, count);}
230 //----------------------------------------------------------------------------
231 template <class T>
232 inline T* _tstrcat (T* dst, const T* src)
234 T* cp = dst;
236 while (*cp)
237 cp++; // find end of dst
239 while ((*cp++ = *src++) != 0) // Copy src to end of dst
242 return dst;
245 inline tchar* tstrcat (tchar* dst, const tchar* src) {return _tstrcat (dst, src); }
246 inline char8* strcat8 (char8* dst, const char8* src) {return _tstrcat (dst, src); }
247 inline char16* strcat16 (char16* dst, const char16* src) {return _tstrcat (dst, src); }
249 //----------------------------------------------------------------------------
250 inline void str8ToStr16 (char16* dst, const char8* src, int32 n = -1)
252 int32 i = 0;
253 for (;;)
255 if (i == n)
257 dst[i] = 0;
258 return;
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++;
273 while (n > i)
275 dst[i] = 0;
276 i++;
280 //------------------------------------------------------------------------
281 inline bool FIDStringsEqual (FIDString id1, FIDString id2)
283 return (id1 && id2) ? (strcmp8 (id1, id2) == 0) : false;
286 static const uint32 kPrintfBufferSize = 4096;
288 //------------------------------------------------------------------------
289 } // namespace Steinberg