BsUnicode.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. * @return ANSI encoded string in the specified locale.
  26. */
  27. static String toANSI(const String& input, const std::locale& locale = std::locale(), char invalidChar = 0);
  28. /**
  29. * Converts from a system-specific wide character encoding into UTF-8.
  30. *
  31. * @param[in] input Wide string to convert. Actual encoding is system specific be can be assumed to be UTF-16 on
  32. * Windows and UTF-32 on Unix.
  33. * @return UTF-8 encoded string.
  34. */
  35. static String fromWide(const WString& input);
  36. /**
  37. * Converts from an UTF-8 encoding into system-specific wide character encoding.
  38. *
  39. * @param[in] input Narrow string encoded as UTF-8 characters.
  40. * @return Wide string encoded in a system-specific manner. Actual encoding can be assumed to be UTF-16
  41. * on Windows and UTF-32 and Unix.
  42. */
  43. static WString toWide(const String& input);
  44. /**
  45. * Converts from an UTF-16 encoding into UTF-8.
  46. *
  47. * @param[in] input String encoded as UTF-16.
  48. * @return UTF-8 encoded string.
  49. */
  50. static String fromUTF16(const U16String& input);
  51. /**
  52. * Converts from an UTF-8 encoding into UTF-16.
  53. *
  54. * @param[in] input String encoded as UTF-8.
  55. * @return UTF-16 encoded string.
  56. */
  57. static U16String toUTF16(const String& input);
  58. /**
  59. * Converts from an UTF-32 encoding into UTF-8.
  60. *
  61. * @param[in] input String encoded as UTF-32.
  62. * @return UTF-8 encoded string.
  63. */
  64. static String fromUTF32(const U32String& input);
  65. /**
  66. * Converts from an UTF-8 encoding into UTF-32.
  67. *
  68. * @param[in] input String encoded as UTF-8.
  69. * @return UTF-32 encoded string.
  70. */
  71. static U32String toUTF32(const String& input);
  72. };
  73. }