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.

111 lines
3.8KB

  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. //-----------------------------------------------------------------------------
  16. #pragma once
  17. #include "ftypes.h"
  18. //------------------------------------------------------------------------
  19. namespace Steinberg {
  20. //------------------------------------------------------------------------
  21. /** UTF-16 string class without buffer management. */
  22. //------------------------------------------------------------------------
  23. class UString
  24. {
  25. public:
  26. //------------------------------------------------------------------------
  27. UString (char16* buffer, int32 size)
  28. : thisBuffer (buffer),
  29. thisSize (size)
  30. {}
  31. int32 getSize () const { return thisSize; } ///< returns buffer size
  32. operator const char16* () const { return thisBuffer; } ///< cast to char16*
  33. /** Returns length of string (in code units). */
  34. int32 getLength () const;
  35. /** Copy from UTF-16 buffer. */
  36. UString& assign (const char16* src, int32 srcSize = -1);
  37. /** Append UTF-16 buffer. */
  38. UString& append (const char16* src, int32 srcSize = -1);
  39. /** Copy to UTF-16 buffer. */
  40. const UString& copyTo (char16* dst, int32 dstSize) const;
  41. /** Copy from ASCII string. */
  42. UString& fromAscii (const char* src, int32 srcSize = -1);
  43. UString& assign (const char* src, int32 srcSize = -1) { return fromAscii (src, srcSize); }
  44. /** Copy to ASCII string. */
  45. const UString& toAscii (char* dst, int32 dstSize) const;
  46. /** Scan integer from string. */
  47. bool scanInt (int64& value) const;
  48. /** Print integer to string. */
  49. bool printInt (int64 value);
  50. /** Scan float from string. */
  51. bool scanFloat (double& value) const;
  52. /** Print float to string. */
  53. bool printFloat (double value, int32 precision = 4);
  54. //------------------------------------------------------------------------
  55. protected:
  56. char16* thisBuffer;
  57. int32 thisSize;
  58. };
  59. //------------------------------------------------------------------------
  60. /** UTF-16 string with fixed buffer size. */
  61. //------------------------------------------------------------------------
  62. template<int32 maxSize>
  63. class UStringBuffer: public UString
  64. {
  65. public:
  66. //------------------------------------------------------------------------
  67. UStringBuffer ()
  68. : UString (data, maxSize)
  69. { data[0] = 0; }
  70. /** Construct from UTF-16 string. */
  71. UStringBuffer (const char16* src, int32 srcSize = -1)
  72. : UString (data, maxSize)
  73. { data[0] = 0; if (src) assign (src, srcSize); }
  74. /** Construct from ASCII string. */
  75. UStringBuffer (const char* src, int32 srcSize = -1)
  76. : UString (data, maxSize)
  77. { data[0] = 0; if (src) fromAscii (src, srcSize); }
  78. //------------------------------------------------------------------------
  79. protected:
  80. char16 data[maxSize];
  81. };
  82. //------------------------------------------------------------------------
  83. typedef UStringBuffer<128> UString128; ///< 128 character UTF-16 string
  84. typedef UStringBuffer<256> UString256; ///< 256 character UTF-16 string
  85. } // namespace Steinberg
  86. //------------------------------------------------------------------------
  87. #define USTRING(asciiString) Steinberg::UString256 (asciiString)
  88. #define USTRINGSIZE(var) (sizeof (var) / sizeof (Steinberg::char16))
  89. //------------------------------------------------------------------------