JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
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 #define STR16(x) SMTG_CPP11_CAT_PRIVATE_DONT_USE(u,x)
29#else
30 #include "conststringtable.h"
31 #define STR16(x) Steinberg::ConstStringTable::instance ()->getString (x)
32#endif
33
34#ifdef UNICODE
35 #define STR(x) STR16(x)
36 #define tStrBufferSize(buffer) (sizeof(buffer)/sizeof(Steinberg::tchar))
37
38#else
39 #define STR(x) x
40 #define tStrBufferSize(buffer) (sizeof(buffer))
41#endif
42
43#define str8BufferSize(buffer) (sizeof(buffer)/sizeof(Steinberg::char8))
44#define str16BufferSize(buffer) (sizeof(buffer)/sizeof(Steinberg::char16))
45
46#if SMTG_OS_WINDOWS
47#define FORMAT_INT64A "I64d"
48#define FORMAT_UINT64A "I64u"
49
50#elif SMTG_OS_MACOS || SMTG_OS_LINUX
51#define FORMAT_INT64A "lld"
52#define FORMAT_UINT64A "llu"
53#define stricmp strcasecmp
54#define strnicmp strncasecmp
55#endif
56
57#ifdef UNICODE
58#define FORMAT_INT64W STR(FORMAT_INT64A)
59#define FORMAT_UINT64W STR(FORMAT_UINT64A)
60
61#define FORMAT_INT64 FORMAT_INT64W
62#define FORMAT_UINT64 FORMAT_UINT64W
63#else
64#define FORMAT_INT64 FORMAT_INT64A
65#define FORMAT_UINT64 FORMAT_UINT64A
66#endif
67
68
69//----------------------------------------------------------------------------
70// newline
71//----------------------------------------------------------------------------
72#if SMTG_OS_WINDOWS
73#define ENDLINE_A "\r\n"
74#define ENDLINE_W STR ("\r\n")
75#elif SMTG_OS_MACOS
76#define ENDLINE_A "\r"
77#define ENDLINE_W STR ("\r")
78#elif SMTG_OS_LINUX
79#define ENDLINE_A "\n"
80#define ENDLINE_W STR ("\n")
81#endif
82
83#ifdef UNICODE
84#define ENDLINE ENDLINE_W
85#else
86#define ENDLINE ENDLINE_A
87#endif
88
89#if SMTG_OS_WINDOWS && !defined(__GNUC__) && defined(_MSC_VER) && (_MSC_VER < 1900)
90#define stricmp _stricmp
91#define strnicmp _strnicmp
92#define snprintf _snprintf
93#endif
94
95namespace Steinberg {
96
97//----------------------------------------------------------------------------
98static SMTG_CONSTEXPR const tchar kEmptyString[] = { 0 };
99static SMTG_CONSTEXPR const char8 kEmptyString8[] = { 0 };
100static SMTG_CONSTEXPR const char16 kEmptyString16[] = { 0 };
101
102#ifdef UNICODE
103static SMTG_CONSTEXPR const tchar kInfiniteSymbol[] = { 0x221E, 0 };
104#else
105static SMTG_CONSTEXPR const tchar* const kInfiniteSymbol = STR ("oo");
106#endif
107
108//----------------------------------------------------------------------------
109template <class T>
110inline SMTG_CONSTEXPR14 int32 _tstrlen (const T* wcs)
111{
112 const T* eos = wcs;
113
114 while (*eos++)
115 ;
116
117 return (int32) (eos - wcs - 1);
118}
119
120inline SMTG_CONSTEXPR14 int32 tstrlen (const tchar* str) {return _tstrlen (str);}
121inline SMTG_CONSTEXPR14 int32 strlen8 (const char8* str) {return _tstrlen (str);}
122inline SMTG_CONSTEXPR14 int32 strlen16 (const char16* str) {return _tstrlen (str);}
123
124//----------------------------------------------------------------------------
125template <class T>
126inline SMTG_CONSTEXPR14 int32 _tstrcmp (const T* src, const T* dst)
127{
128 while (*src == *dst && *dst)
129 {
130 src++;
131 dst++;
132 }
133
134 if (*src == 0 && *dst == 0)
135 return 0;
136 if (*src == 0)
137 return -1;
138 if (*dst == 0)
139 return 1;
140 return (int32) (*src - *dst);
141}
142
143inline SMTG_CONSTEXPR14 int32 tstrcmp (const tchar* src, const tchar* dst) {return _tstrcmp (src, dst);}
144inline SMTG_CONSTEXPR14 int32 strcmp8 (const char8* src, const char8* dst) {return _tstrcmp (src, dst);}
145inline SMTG_CONSTEXPR14 int32 strcmp16 (const char16* src, const char16* dst) {return _tstrcmp (src, dst);}
146
147template <typename T>
148inline SMTG_CONSTEXPR14 int32 strcmpT (const T* first, const T* last);
149
150template <>
151inline SMTG_CONSTEXPR14 int32 strcmpT<char8> (const char8* first, const char8* last) { return _tstrcmp (first, last); }
152
153template <>
154inline SMTG_CONSTEXPR14 int32 strcmpT<char16> (const char16* first, const char16* last) { return _tstrcmp (first, last); }
155
156//----------------------------------------------------------------------------
157template <class T>
158inline SMTG_CONSTEXPR14 int32 _tstrncmp (const T* first, const T* last, uint32 count)
159{
160 if (count == 0)
161 return 0;
162
163 while (--count && *first && *first == *last)
164 {
165 first++;
166 last++;
167 }
168
169 if (*first == 0 && *last == 0)
170 return 0;
171 if (*first == 0)
172 return -1;
173 if (*last == 0)
174 return 1;
175 return (int32) (*first - *last);
176}
177
178inline SMTG_CONSTEXPR14 int32 tstrncmp (const tchar* first, const tchar* last, uint32 count) {return _tstrncmp (first, last, count);}
179inline SMTG_CONSTEXPR14 int32 strncmp8 (const char8* first, const char8* last, uint32 count) {return _tstrncmp (first, last, count);}
180inline SMTG_CONSTEXPR14 int32 strncmp16 (const char16* first, const char16* last, uint32 count) {return _tstrncmp (first, last, count);}
181
182template <typename T>
183inline SMTG_CONSTEXPR14 int32 strncmpT (const T* first, const T* last, uint32 count);
184
185template <>
186inline SMTG_CONSTEXPR14 int32 strncmpT<char8> (const char8* first, const char8* last, uint32 count) { return _tstrncmp (first, last, count); }
187
188template <>
189inline SMTG_CONSTEXPR14 int32 strncmpT<char16> (const char16* first, const char16* last, uint32 count) {return _tstrncmp (first, last, count); }
190
191//----------------------------------------------------------------------------
192template <class T>
193inline SMTG_CONSTEXPR14 T* _tstrcpy (T* dst, const T* src)
194{
195 T* cp = dst;
196 while ((*cp++ = *src++) != 0) // copy string
197 ;
198 return dst;
199}
200inline SMTG_CONSTEXPR14 tchar* tstrcpy (tchar* dst, const tchar* src) {return _tstrcpy (dst, src);}
201inline SMTG_CONSTEXPR14 char8* strcpy8 (char8* dst, const char8* src) {return _tstrcpy (dst, src);}
202inline SMTG_CONSTEXPR14 char16* strcpy16 (char16* dst, const char16* src) {return _tstrcpy (dst, src);}
203
204//----------------------------------------------------------------------------
205template <class T>
206inline SMTG_CONSTEXPR14 T* _tstrncpy (T* dest, const T* source, uint32 count)
207{
208 T* start = dest;
209 while (count && (*dest++ = *source++) != 0) // copy string
210 count--;
211
212 if (count) // pad out with zeros
213 {
214 while (--count)
215 *dest++ = 0;
216 }
217 return start;
218}
219
220inline SMTG_CONSTEXPR14 tchar* tstrncpy (tchar* dest, const tchar* source, uint32 count) {return _tstrncpy (dest, source, count);}
221inline SMTG_CONSTEXPR14 char8* strncpy8 (char8* dest, const char8* source, uint32 count) {return _tstrncpy (dest, source, count);}
222inline SMTG_CONSTEXPR14 char16* strncpy16 (char16* dest, const char16* source, uint32 count) {return _tstrncpy (dest, source, count);}
223
224//----------------------------------------------------------------------------
225template <class T>
226inline SMTG_CONSTEXPR14 T* _tstrcat (T* dst, const T* src)
227{
228 T* cp = dst;
229
230 while (*cp)
231 cp++; // find end of dst
232
233 while ((*cp++ = *src++) != 0) // Copy src to end of dst
234 ;
235
236 return dst;
237}
238
239inline SMTG_CONSTEXPR14 tchar* tstrcat (tchar* dst, const tchar* src) {return _tstrcat (dst, src); }
240inline SMTG_CONSTEXPR14 char8* strcat8 (char8* dst, const char8* src) {return _tstrcat (dst, src); }
241inline SMTG_CONSTEXPR14 char16* strcat16 (char16* dst, const char16* src) {return _tstrcat (dst, src); }
242
243//----------------------------------------------------------------------------
244inline SMTG_CONSTEXPR14 void str8ToStr16 (char16* dst, const char8* src, int32 n = -1)
245{
246 int32 i = 0;
247 for (;;)
248 {
249 if (i == n)
250 {
251 dst[i] = 0;
252 return;
253 }
254
255#if BYTEORDER == kBigEndian
256 char8* pChr = (char8*)&dst[i];
257 pChr[0] = 0;
258 pChr[1] = src[i];
259#else
260 dst[i] = static_cast<char16> (src[i]);
261#endif
262 if (src[i] == 0)
263 break;
264 i++;
265 }
266
267 while (n > i)
268 {
269 dst[i] = 0;
270 i++;
271 }
272}
273
274//------------------------------------------------------------------------
275inline SMTG_CONSTEXPR14 bool FIDStringsEqual (FIDString id1, FIDString id2)
276{
277 return (id1 && id2) ? (strcmp8 (id1, id2) == 0) : false;
278}
279
280static SMTG_CONSTEXPR const uint32 kPrintfBufferSize = 4096;
281
282#if SMTG_OS_WINDOWS
283/* cast between wchar_t and char16 */
284inline wchar_t* wscast (char16* s) { static_assert (sizeof (wchar_t) == sizeof (char16), ""); return reinterpret_cast<wchar_t*> (s); }
285inline char16* wscast (wchar_t* s) { static_assert (sizeof (wchar_t) == sizeof (char16), ""); return reinterpret_cast<char16*> (s);}
286inline const wchar_t* wscast (const char16* s) { static_assert (sizeof (wchar_t) == sizeof (char16), ""); return reinterpret_cast<const wchar_t*> (s); }
287inline const char16* wscast (const wchar_t* s) { static_assert (sizeof (wchar_t) == sizeof (char16), ""); return reinterpret_cast<const char16*> (s); }
288#endif
289
290//------------------------------------------------------------------------
291} // namespace Steinberg