1 //-----------------------------------------------------------------------------
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)
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 //-----------------------------------------------------------------------------
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
29 #define STR16(x) SMTG_CPP11_CAT_PRIVATE_DONT_USE(L,x)
31 #define STR16(x) SMTG_CPP11_CAT_PRIVATE_DONT_USE(u,x)
34 #include "conststringtable.h"
35 #define STR16(x) Steinberg::ConstStringTable::instance ()->getString (x)
39 #define STR(x) STR16(x)
40 #define tStrBufferSize(buffer) (sizeof(buffer)/sizeof(Steinberg::tchar))
44 #define tStrBufferSize(buffer) (sizeof(buffer))
47 #define str8BufferSize(buffer) (sizeof(buffer)/sizeof(Steinberg::char8))
48 #define str16BufferSize(buffer) (sizeof(buffer)/sizeof(Steinberg::char16))
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
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
68 #define FORMAT_INT64 FORMAT_INT64A
69 #define FORMAT_UINT64 FORMAT_UINT64A
73 //----------------------------------------------------------------------------
75 //----------------------------------------------------------------------------
77 #define ENDLINE_A "\r\n"
78 #define ENDLINE_W STR ("\r\n")
80 #define ENDLINE_A "\r"
81 #define ENDLINE_W STR ("\r")
83 #define ENDLINE_A "\n"
84 #define ENDLINE_W STR ("\n")
88 #define ENDLINE ENDLINE_W
90 #define ENDLINE ENDLINE_A
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
101 //----------------------------------------------------------------------------
102 static const tchar kEmptyString
[] = { 0 };
103 static const char8 kEmptyString8
[] = { 0 };
104 static const char16 kEmptyString16
[] = { 0 };
107 static const tchar kInfiniteSymbol
[] = { 0x221E, 0 };
109 static const tchar
* const kInfiniteSymbol
= STR ("oo");
112 //----------------------------------------------------------------------------
114 inline int32
_tstrlen (const T
* wcs
)
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 //----------------------------------------------------------------------------
130 inline int32
_tstrcmp (const T
* src
, const T
* dst
)
132 while (*src
== *dst
&& *dst
)
138 if (*src
== 0 && *dst
== 0)
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
);
156 inline int32 strcmpT
<char8
> (const char8
* first
, const char8
* last
) { return _tstrcmp (first
, last
); }
159 inline int32 strcmpT
<char16
> (const char16
* first
, const char16
* last
) { return _tstrcmp (first
, last
); }
161 //----------------------------------------------------------------------------
163 inline int32
_tstrncmp (const T
* first
, const T
* last
, uint32 count
)
168 while (--count
&& *first
&& *first
== *last
)
174 if (*first
== 0 && *last
== 0)
176 else if (*first
== 0)
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
);
192 inline int32 strncmpT
<char8
> (const char8
* first
, const char8
* last
, uint32 count
) { return _tstrncmp (first
, last
, count
); }
195 inline int32 strncmpT
<char16
> (const char16
* first
, const char16
* last
, uint32 count
) {return _tstrncmp (first
, last
, count
); }
197 //----------------------------------------------------------------------------
199 inline T
* _tstrcpy (T
* dst
, const T
* src
)
202 while ((*cp
++ = *src
++) != 0) // copy string
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 //----------------------------------------------------------------------------
212 inline T
* _tstrncpy (T
* dest
, const T
* source
, uint32 count
)
215 while (count
&& (*dest
++ = *source
++) != 0) // copy string
218 if (count
) // pad out with zeros
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 //----------------------------------------------------------------------------
232 inline T
* _tstrcat (T
* dst
, const T
* src
)
237 cp
++; // find end of dst
239 while ((*cp
++ = *src
++) != 0) // Copy src to end of 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)
261 #if BYTEORDER == kBigEndian
262 char8
* pChr
= (char8
*)&dst
[i
];
266 dst
[i
] = static_cast<char16
> (src
[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