xtd 0.2.0
Loading...
Searching...
No Matches
__character_formatter.h
Go to the documentation of this file.
1
3#pragma once
5#if !defined(__XTD_CORE_INTERNAL__)
6#error "Do not include this file: Internal use only"
7#endif
9
10#include "../types.h"
11#include <locale>
12
14template<typename char_t, typename value_t>
15inline std::basic_string<char_t> __character_formatter(const std::basic_string<char_t>& fmt, value_t value, const std::locale& loc) {
16 std::basic_string<char_t> result;
17 xtd::char32 codepoint = value;
18 if (codepoint < 0x80)
19 result.push_back(static_cast<char>(codepoint));
20 else if (codepoint < 0x800) {
21 result.push_back(static_cast<char>((codepoint >> 6) | 0xc0));
22 result.push_back(static_cast<char>((codepoint & 0x3f) | 0x80));
23 } else if (codepoint < 0x10000) {
24 result.push_back(static_cast<char>((codepoint >> 12) | 0xe0));
25 result.push_back(static_cast<char>(((codepoint >> 6) & 0x3f) | 0x80));
26 result.push_back(static_cast<char>((codepoint & 0x3f) | 0x80));
27 } else {
28 result.push_back(static_cast<char>((codepoint >> 18) | 0xf0));
29 result.push_back(static_cast<char>(((codepoint >> 12) & 0x3f) | 0x80));
30 result.push_back(static_cast<char>(((codepoint >> 6) & 0x3f) | 0x80));
31 result.push_back(static_cast<char>((codepoint & 0x3f) | 0x80));
32 }
33 return result;
34}
char32_t char32
Represents a 32-bit unicode character.
Definition char32.h:26