BsUnicode.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "Prerequisites/BsPrerequisitesUtil.h"
  5. namespace bs
  6. {
  7. /** @addtogroup String
  8. * @{
  9. */
  10. /** Provides methods to converting between UTF-8 character encoding and other popular encodings. */
  11. class BS_UTILITY_EXPORT UTF8
  12. {
  13. public:
  14. /**
  15. * Converts from an ANSI encoding in the specified locale into UTF-8.
  16. *
  17. * @param[in] input Narrow string encoded as ANSI characters. Characters are expected to be in the code page
  18. * specified by @p locale.
  19. * @param[in] locale Locale that determines how are the ANSI characters interpreted.
  20. * @return UTF-8 encoded string.
  21. */
  22. static String fromANSI(const String& input, const std::locale& locale = std::locale(""));
  23. /**
  24. * Converts from an UTF-8 encoding into ANSI encoding in the specified locale.
  25. *
  26. * @param[in] input Narrow string encoded as UTF-8 characters.
  27. * @param[in] locale Locale that determines from which code page to generate the ANSI characters.
  28. * @param[in] invalidChar Character that will be used when an Unicode character cannot be represented using
  29. * the selected ANSI code page.
  30. * @return ANSI encoded string in the specified locale.
  31. */
  32. static String toANSI(const String& input, const std::locale& locale = std::locale(""), char invalidChar = 0);
  33. /**
  34. * Converts from a system-specific wide character encoding into UTF-8.
  35. *
  36. * @param[in] input Wide string to convert. Actual encoding is system specific be can be assumed to be UTF-16 on
  37. * Windows and UTF-32 on Unix.
  38. * @return UTF-8 encoded string.
  39. */
  40. static String fromWide(const WString& input);
  41. /**
  42. * Converts from an UTF-8 encoding into system-specific wide character encoding.
  43. *
  44. * @param[in] input Narrow string encoded as UTF-8 characters.
  45. * @return Wide string encoded in a system-specific manner. Actual encoding can be assumed to be UTF-16
  46. * on Windows and UTF-32 and Unix.
  47. */
  48. static WString toWide(const String& input);
  49. /**
  50. * Converts from an UTF-16 encoding into UTF-8.
  51. *
  52. * @param[in] input String encoded as UTF-16.
  53. * @return UTF-8 encoded string.
  54. */
  55. static String fromUTF16(const U16String& input);
  56. /**
  57. * Converts from an UTF-8 encoding into UTF-16.
  58. *
  59. * @param[in] input String encoded as UTF-8.
  60. * @return UTF-16 encoded string.
  61. */
  62. static U16String toUTF16(const String& input);
  63. /**
  64. * Converts from an UTF-32 encoding into UTF-8.
  65. *
  66. * @param[in] input String encoded as UTF-32.
  67. * @return UTF-8 encoded string.
  68. */
  69. static String fromUTF32(const U32String& input);
  70. /**
  71. * Converts from an UTF-8 encoding into UTF-32.
  72. *
  73. * @param[in] input String encoded as UTF-8.
  74. * @return UTF-32 encoded string.
  75. */
  76. static U32String toUTF32(const String& input);
  77. };
  78. /** @} */
  79. }