Add initial bits for Qt6 support
[carla.git] / source / includes / vst3sdk / pluginterfaces / base / conststringtable.cpp
blob4891cefa15b17f82f5da5c47e4402684aa4b7a55
1 //-----------------------------------------------------------------------------
2 // Project : SDK Core
3 //
4 // Category : SDK Core Interfaces
5 // Filename : pluginterfaces/base/conststringtable.cpp
6 // Created by : Steinberg, 09/2007
7 // Description : constant unicode string table
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 #include "conststringtable.h"
18 #include <cstring>
19 #include <map>
21 namespace Steinberg {
23 static std::map<const char8*, char16*>* stringMap;
24 static std::map<const char8, char16>* charMap;
26 static char16* generateUTF16 (const char8* str);
28 //----------------------------------------------------------------------------
29 ConstStringTable* ConstStringTable::instance ()
31 static ConstStringTable stringTable;
32 return &stringTable;
35 //----------------------------------------------------------------------------
36 const char16* ConstStringTable::getString (const char8* str) const
38 std::map<const char8*, char16*>::iterator iter = stringMap->find (str);
39 if (iter != stringMap->end ())
40 return iter->second;
41 char16* uStr = generateUTF16 (str);
42 stringMap->insert (std::make_pair (str, uStr));
43 return uStr;
46 //----------------------------------------------------------------------------
47 const char16 ConstStringTable::getString (const char8 str) const
49 std::map<const char8, char16>::iterator iter = charMap->find (str);
50 if (iter != charMap->end ())
51 return iter->second;
52 char16 uStr = 0;
53 #if BYTEORDER == kBigEndian
54 char8* puStr = (char8*)&uStr;
55 puStr[1] = str;
56 #else
57 uStr = str;
58 #endif
59 charMap->insert (std::make_pair (str, uStr));
60 return uStr;
63 //----------------------------------------------------------------------------
64 ConstStringTable::ConstStringTable ()
66 stringMap = new std::map<const char8*, char16*>;
67 charMap = new std::map<const char8, char16>;
70 //----------------------------------------------------------------------------
71 ConstStringTable::~ConstStringTable ()
73 // free out allocated strings
75 std::map<const char8*, char16*>::iterator iter = stringMap->begin ();
76 while (iter != stringMap->end ())
78 delete[] iter->second;
79 iter++;
81 } // delete iterator on map before deleting the map
83 delete stringMap;
84 delete charMap;
87 //----------------------------------------------------------------------------
88 char16* generateUTF16 (const char8* str)
90 int32 len = (int32)strlen (str);
91 char16* result = new char16[len + 1];
92 for (int32 i = 0; i < len; i++)
94 #if BYTEORDER == kBigEndian
95 char8* pChr = (char8*)&result[i];
96 pChr[0] = 0;
97 pChr[1] = str[i];
98 #else
99 result[i] = str[i];
100 #endif
102 result[len] = 0;
103 return result;
105 //------------------------------------------------------------------------
106 } // namespace Steinberg