1 //-----------------------------------------------------------------------------
4 // Category : SDK Core Interfaces
5 // Filename : pluginterfaces/base/conststringtable.cpp
6 // Created by : Steinberg, 09/2007
7 // Description : constant unicode string table
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"
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
;
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 ())
41 char16
* uStr
= generateUTF16 (str
);
42 stringMap
->insert (std::make_pair (str
, 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 ())
53 #if BYTEORDER == kBigEndian
54 char8
* puStr
= (char8
*)&uStr
;
59 charMap
->insert (std::make_pair (str
, 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
;
81 } // delete iterator on map before deleting the map
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
];
105 //------------------------------------------------------------------------
106 } // namespace Steinberg