Cleanup
[carla.git] / source / includes / vst3sdk / pluginterfaces / base / ustring.h
blob9df8565e976118d30339f3b6c180bead682c7989
1 //-----------------------------------------------------------------------------
2 // Project : SDK Core
3 //
4 // Category : Helpers
5 // Filename : pluginterfaces/base/ustring.h
6 // Created by : Steinberg, 12/2005
7 // Description : UTF-16 String class
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 namespace Steinberg {
24 //------------------------------------------------------------------------
25 /** UTF-16 string class without buffer management.
26 Note: that some characters are encoded in 2 UTF16 code units (surrogate pair),
27 this means that getLength returns the number of code unit, not the count of character! */
28 class UString
30 public:
31 //------------------------------------------------------------------------
32 /** Construct from UTF-16 string, size is in code unit (count of char16) */
33 UString (char16* buffer, int32 size) : thisBuffer (buffer), thisSize (size) {}
35 /** returns buffer size */
36 int32 getSize () const { return thisSize; }
38 /** cast to char16* */
39 operator const char16* () const { return thisBuffer; }
41 /** Returns length of string (in code unit). Note this is not the count of character! */
42 int32 getLength () const;
44 /** Copy from UTF-16 buffer (srcSize is in code unit (count of char16)). */
45 UString& assign (const char16* src, int32 srcSize = -1);
47 /** Append UTF-16 buffer (srcSize is in code unit (count of char16)). */
48 UString& append (const char16* src, int32 srcSize = -1);
50 /** Copy to UTF-16 buffer (dstSize is in code unit (count of char16)). */
51 const UString& copyTo (char16* dst, int32 dstSize) const;
53 /** Copy from ASCII string (srcSize is in code unit (count of char16)). */
54 UString& fromAscii (const char* src, int32 srcSize = -1);
55 UString& assign (const char* src, int32 srcSize = -1) { return fromAscii (src, srcSize); }
57 /** Copy to ASCII string. */
58 const UString& toAscii (char* dst, int32 dstSize) const;
60 /** Scan integer from string. */
61 bool scanInt (int64& value) const;
63 /** Print integer to string. */
64 bool printInt (int64 value);
66 /** Scan float from string. */
67 bool scanFloat (double& value) const;
69 /** Print float to string. */
70 bool printFloat (double value, int32 precision = 4);
71 //------------------------------------------------------------------------
72 protected:
73 char16* thisBuffer;
74 int32 thisSize; ///< size in code unit (not in byte!)
77 //------------------------------------------------------------------------
78 /** UTF-16 string with fixed buffer size.
80 template <int32 maxSize>
81 class UStringBuffer : public UString
83 public:
84 //------------------------------------------------------------------------
85 UStringBuffer () : UString (data, maxSize) { data[0] = 0; }
87 /** Construct from UTF-16 string. */
88 UStringBuffer (const char16* src, int32 srcSize = -1) : UString (data, maxSize)
90 data[0] = 0;
91 if (src)
92 assign (src, srcSize);
95 /** Construct from ASCII string. */
96 UStringBuffer (const char* src, int32 srcSize = -1) : UString (data, maxSize)
98 data[0] = 0;
99 if (src)
100 fromAscii (src, srcSize);
102 //------------------------------------------------------------------------
103 protected:
104 char16 data[maxSize];
107 //------------------------------------------------------------------------
108 typedef UStringBuffer<128> UString128; ///< 128 character UTF-16 string
109 typedef UStringBuffer<256> UString256; ///< 256 character UTF-16 string
110 } // namespace Steinberg
112 //------------------------------------------------------------------------
113 #define USTRING(asciiString) Steinberg::UString256 (asciiString)
114 #define USTRINGSIZE(var) (sizeof (var) / sizeof (Steinberg::char16))
116 //------------------------------------------------------------------------