BsUnicode.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. /** Provides methods to converting between UTF-8 character encoding and other popular encodings. */
  8. class BS_UTILITY_EXPORT UTF8
  9. {
  10. public:
  11. /**
  12. * Converts from an ANSI encoding in the specified locale into UTF-8.
  13. *
  14. * @param[in] input Narrow string encoded as ANSI characters. Characters are expected to be in the code page
  15. * specified by @p locale.
  16. * @param[in] locale Locale that determines how are the ANSI characters interpreted.
  17. * @return UTF-8 encoded string.
  18. */
  19. static String fromANSI(const String& input, const std::locale& locale = std::locale());
  20. /**
  21. * Converts from an UTF-8 encoding into ANSI encoding in the specified locale.
  22. *
  23. * @param[in] input Narrow string encoded as UTF-8 characters.
  24. * @param[in] locale Locale that determines from which code page to generate the ANSI characters.
  25. * @param[in] invalidChar Character that will be used when an Unicode character cannot be represented using
  26. * the selected ANSI code page.
  27. * @return ANSI encoded string in the specified locale.
  28. */
  29. static String toANSI(const String& input, const std::locale& locale = std::locale(), char invalidChar = 0);
  30. /**
  31. * Converts from a system-specific wide character encoding into UTF-8.
  32. *
  33. * @param[in] input Wide string to convert. Actual encoding is system specific be can be assumed to be UTF-16 on
  34. * Windows and UTF-32 on Unix.
  35. * @return UTF-8 encoded string.
  36. */
  37. static String fromWide(const WString& input);
  38. /**
  39. * Converts from an UTF-8 encoding into system-specific wide character encoding.
  40. *
  41. * @param[in] input Narrow string encoded as UTF-8 characters.
  42. * @return Wide string encoded in a system-specific manner. Actual encoding can be assumed to be UTF-16
  43. * on Windows and UTF-32 and Unix.
  44. */
  45. static WString toWide(const String& input);
  46. /**
  47. * Converts from an UTF-16 encoding into UTF-8.
  48. *
  49. * @param[in] input String encoded as UTF-16.
  50. * @return UTF-8 encoded string.
  51. */
  52. static String fromUTF16(const U16String& input);
  53. /**
  54. * Converts from an UTF-8 encoding into UTF-16.
  55. *
  56. * @param[in] input String encoded as UTF-8.
  57. * @return UTF-16 encoded string.
  58. */
  59. static U16String toUTF16(const String& input);
  60. /**
  61. * Converts from an UTF-32 encoding into UTF-8.
  62. *
  63. * @param[in] input String encoded as UTF-32.
  64. * @return UTF-8 encoded string.
  65. */
  66. static String fromUTF32(const U32String& input);
  67. /**
  68. * Converts from an UTF-8 encoding into UTF-32.
  69. *
  70. * @param[in] input String encoded as UTF-8.
  71. * @return UTF-32 encoded string.
  72. */
  73. static U32String toUTF32(const String& input);
  74. };
  75. }