Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.1KB

  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. #include "conststringtable.h"
  17. #include <cstring>
  18. #include <map>
  19. namespace Steinberg {
  20. static std::map<const char8*, char16*>* stringMap;
  21. static std::map<const char8, char16>* charMap;
  22. static char16* generateUTF16 (const char8* str);
  23. //----------------------------------------------------------------------------
  24. ConstStringTable* ConstStringTable::instance ()
  25. {
  26. static ConstStringTable stringTable;
  27. return &stringTable;
  28. }
  29. //----------------------------------------------------------------------------
  30. const char16* ConstStringTable::getString (const char8* str) const
  31. {
  32. std::map<const char8*, char16*>::iterator iter = stringMap->find (str);
  33. if (iter != stringMap->end ())
  34. return iter->second;
  35. char16* uStr = generateUTF16 (str);
  36. stringMap->insert (std::make_pair (str, uStr));
  37. return uStr;
  38. }
  39. //----------------------------------------------------------------------------
  40. const char16 ConstStringTable::getString (const char8 str) const
  41. {
  42. std::map<const char8, char16>::iterator iter = charMap->find (str);
  43. if (iter != charMap->end ())
  44. return iter->second;
  45. char16 uStr = 0;
  46. #if BYTEORDER == kBigEndian
  47. char8* puStr = (char8*)&uStr;
  48. puStr[1] = str;
  49. #else
  50. uStr = str;
  51. #endif
  52. charMap->insert (std::make_pair (str, uStr));
  53. return uStr;
  54. }
  55. //----------------------------------------------------------------------------
  56. ConstStringTable::ConstStringTable ()
  57. {
  58. stringMap = new std::map<const char8*, char16*>;
  59. charMap = new std::map<const char8, char16>;
  60. }
  61. //----------------------------------------------------------------------------
  62. ConstStringTable::~ConstStringTable ()
  63. {
  64. // free out allocated strings
  65. {
  66. std::map<const char8*, char16*>::iterator iter = stringMap->begin ();
  67. while (iter != stringMap->end ())
  68. {
  69. delete[] iter->second;
  70. iter++;
  71. }
  72. } // delete iterator on map before deleting the map
  73. delete stringMap;
  74. delete charMap;
  75. }
  76. //----------------------------------------------------------------------------
  77. char16* generateUTF16 (const char8* str)
  78. {
  79. int32 len = (int32)strlen (str);
  80. char16* result = new char16[len + 1];
  81. for (int32 i = 0; i < len; i++)
  82. {
  83. #if BYTEORDER == kBigEndian
  84. char8* pChr = (char8*)&result[i];
  85. pChr[0] = 0;
  86. pChr[1] = str[i];
  87. #else
  88. result[i] = str[i];
  89. #endif
  90. }
  91. result[len] = 0;
  92. return result;
  93. }
  94. //------------------------------------------------------------------------
  95. } // namespace Steinberg