Unicode.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // Unicode.h //
  4. // Copyright (C) Microsoft Corporation. All rights reserved. //
  5. // This file is distributed under the University of Illinois Open Source //
  6. // License. See LICENSE.TXT for details. //
  7. // //
  8. // Provides utitlity functions to work with Unicode and other encodings. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #pragma once
  12. #include <string>
  13. #include <specstrings.h>
  14. namespace Unicode
  15. {
  16. // Based on http://msdn.microsoft.com/en-us/library/windows/desktop/dd374101(v=vs.85).aspx.
  17. enum class Encoding { ASCII = 0, UTF8, UTF8_BOM, UTF16_LE, UTF16_BE, UTF32_LE, UTF32_BE };
  18. // An acp_char is a character encoded in the current Windows ANSI code page.
  19. typedef char acp_char;
  20. // A ccp_char is a character encoded in the console code page.
  21. typedef char ccp_char;
  22. _Success_(return != false)
  23. bool UTF8ToConsoleString(_In_z_ const char* text, _Inout_ std::string* pValue, _Out_opt_ bool* lossy);
  24. _Success_(return != false)
  25. bool UTF16ToConsoleString(_In_z_ const wchar_t* text, _Inout_ std::string* pValue, _Out_opt_ bool* lossy);
  26. _Success_(return != false)
  27. bool UTF8ToUTF16String(_In_opt_z_ const char *pUTF8, _Inout_ std::wstring *pUTF16);
  28. _Success_(return != false)
  29. bool UTF8ToUTF16String(_In_opt_count_(cbUTF8) const char *pUTF8, size_t cbUTF8, _Inout_ std::wstring *pUTF16);
  30. std::wstring UTF8ToUTF16StringOrThrow(_In_z_ const char *pUTF8);
  31. _Success_(return != false)
  32. bool UTF16ToUTF8String(_In_z_ const wchar_t *pUTF16, _Inout_ std::string *pUTF8);
  33. std::string UTF16ToUTF8StringOrThrow(_In_z_ const wchar_t *pUTF16);
  34. bool IsStarMatchUTF8(_In_reads_opt_(maskLen) const char *pMask, size_t maskLen,
  35. _In_reads_opt_(nameLen) const char *pName, size_t nameLen);
  36. bool IsStarMatchUTF16(_In_reads_opt_(maskLen) const wchar_t *pMask, size_t maskLen,
  37. _In_reads_opt_(nameLen) const wchar_t *pName, size_t nameLen);
  38. _Success_(return != false)
  39. bool UTF8BufferToUTF16Buffer(
  40. _In_NLS_string_(cbUTF8) const char *pUTF8,
  41. int cbUTF8,
  42. _Outptr_result_buffer_(*pcchUTF16) wchar_t **ppUTF16,
  43. size_t *pcchUTF16) throw();
  44. _Success_(return != false)
  45. bool UTF16BufferToUTF8Buffer(
  46. _In_NLS_string_(cchUTF16) const wchar_t *pUTF16,
  47. int cchUTF16,
  48. _Outptr_result_buffer_(*pcbUTF8) char **ppUTF8,
  49. size_t *pcbUTF8) throw();
  50. } // namespace Unicode