| 11487 | } |
| 11488 | |
| 11489 | inline encoded_result<char16_t> code_point_to_utf16(char32_t codepoint) { |
| 11490 | encoded_result<char16_t> er; |
| 11491 | |
| 11492 | if (codepoint <= unicode_detail::last_bmp_value) { |
| 11493 | er.code_units_size = 1; |
| 11494 | er.code_units = std::array<char16_t, 4>{ { static_cast<char16_t>(codepoint) } }; |
| 11495 | er.error = error_code::ok; |
| 11496 | } |
| 11497 | else { |
| 11498 | auto normal = codepoint - unicode_detail::normalizing_value; |
| 11499 | auto lead = unicode_detail::first_lead_surrogate + ((normal & unicode_detail::lead_surrogate_bitmask) >> unicode_detail::lead_shifted_bits); |
| 11500 | auto trail = unicode_detail::first_trail_surrogate + (normal & unicode_detail::trail_surrogate_bitmask); |
| 11501 | er.code_units = std::array<char16_t, 4>{ { |
| 11502 | static_cast<char16_t>(lead), |
| 11503 | static_cast<char16_t>(trail) |
| 11504 | } }; |
| 11505 | er.code_units_size = 2; |
| 11506 | er.error = error_code::ok; |
| 11507 | } |
| 11508 | return er; |
| 11509 | } |
| 11510 | |
| 11511 | inline encoded_result<char32_t> code_point_to_utf32(char32_t codepoint) { |
| 11512 | encoded_result<char32_t> er; |