wide_specific.h 526 B

12345678910111213141516171819202122
  1. #pragma once
  2. #include <util/system/types.h>
  3. #include <util/system/yassert.h>
  4. inline constexpr bool IsW16SurrogateLead(wchar16 c) noexcept {
  5. return 0xD800 <= c && c <= 0xDBFF;
  6. }
  7. inline constexpr bool IsW16SurrogateTail(wchar16 c) noexcept {
  8. return 0xDC00 <= c && c <= 0xDFFF;
  9. }
  10. inline size_t W16SymbolSize(const wchar16* begin, const wchar16* end) {
  11. Y_ASSERT(begin < end);
  12. if ((begin + 1 != end) && IsW16SurrogateLead(*begin) && IsW16SurrogateTail(*(begin + 1))) {
  13. return 2;
  14. }
  15. return 1;
  16. }