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
conststringtable.cpp
Go to the documentation of this file.
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//-----------------------------------------------------------------------------
16
17#include "conststringtable.h"
18#include <cstring>
19#include <map>
20
21namespace Steinberg {
22
23static std::map<const char8*, char16*>* stringMap;
24static std::map<const char8, char16>* charMap;
25
26static char16* generateUTF16 (const char8* str);
27
28//----------------------------------------------------------------------------
29ConstStringTable* ConstStringTable::instance ()
30{
31 static ConstStringTable stringTable;
32 return &stringTable;
33}
34
35//----------------------------------------------------------------------------
36const char16* ConstStringTable::getString (const char8* str) const
37{
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;
44}
45
46//----------------------------------------------------------------------------
47char16 ConstStringTable::getString (const char8 str) const
48{
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;
61}
62
63//----------------------------------------------------------------------------
64ConstStringTable::ConstStringTable ()
65{
66 stringMap = new std::map<const char8*, char16*>;
68}
69
70//----------------------------------------------------------------------------
71ConstStringTable::~ConstStringTable ()
72{
73 // free out allocated strings
74 {
75 std::map<const char8*, char16*>::iterator iter = stringMap->begin ();
76 while (iter != stringMap->end ())
77 {
78 delete[] iter->second;
79 iter++;
80 }
81 } // delete iterator on map before deleting the map
82
83 delete stringMap;
84 delete charMap;
85}
86
87//----------------------------------------------------------------------------
88char16* generateUTF16 (const char8* str)
89{
90 int32 len = (int32)strlen (str);
91 char16* result = new char16[len + 1];
92 for (int32 i = 0; i < len; i++)
93 {
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
101 }
102 result[len] = 0;
103 return result;
104}
105//------------------------------------------------------------------------
106} // namespace Steinberg
const char16 * getString(const char8 *str) const
Returns a char16 string of a ASCII string literal.
T make_pair(T... args)