typeset 0.1.0
縦書き・横書きの日本語組版ライブラリ(JLReq 水準、ラスタ / PDF / SVG)
読み取り中…
検索中…
一致する文字列を見つけられません
utf.hpp
[詳解]
1#ifndef TYPESET_TEXT_UTF_HPP
2#define TYPESET_TEXT_UTF_HPP
3
4#include <cstddef>
5#include <string>
6
12namespace typeset::text {
13
15inline char32_t codePointAt(const std::u16string& s, size_t i, size_t& length) {
16 const char16_t c = s[i];
17 if (c >= 0xD800 && c <= 0xDBFF && i + 1 < s.size()) {
18 const char16_t c2 = s[i + 1];
19 if (c2 >= 0xDC00 && c2 <= 0xDFFF) {
20 length = 2;
21 return 0x10000 + (static_cast<char32_t>(c - 0xD800) << 10) +
22 static_cast<char32_t>(c2 - 0xDC00);
23 }
24 }
25 length = 1;
26 return c;
27}
28
29inline char32_t codePointAt(const std::u16string& s, size_t i) {
30 size_t len = 1;
31 return codePointAt(s, i, len);
32}
33
35inline void appendCodePoint(std::u16string& out, char32_t cp) {
36 if (cp <= 0xFFFF) {
37 out += static_cast<char16_t>(cp);
38 } else if (cp <= 0x10FFFF) {
39 const char32_t v = cp - 0x10000;
40 out += static_cast<char16_t>(0xD800 | (v >> 10));
41 out += static_cast<char16_t>(0xDC00 | (v & 0x3FF));
42 }
43}
44
45std::u16string utf8ToUtf16(const std::string& utf8);
46std::string utf16ToUtf8(const std::u16string& utf16);
47
48} // namespace typeset::text
49
50#endif // TYPESET_TEXT_UTF_HPP
text/char_class — JLReq の文字クラス
Definition style.hpp:9
std::u16string utf8ToUtf16(const std::string &utf8)
std::string utf16ToUtf8(const std::u16string &utf16)
char32_t codePointAt(const std::u16string &s, size_t i, size_t &length)
UTF-16 の位置 i からコードポイントを取り出す(サロゲートペア対応)
Definition utf.hpp:15
void appendCodePoint(std::u16string &out, char32_t cp)
コードポイントを UTF-16 に追加する
Definition utf.hpp:35