10 #include <wordring/whatwg/encoding/encoding.hpp>
11 #include <wordring/whatwg/encoding/encoding_defs.hpp>
13 #include <wordring/whatwg/infra/infra.hpp>
14 #include <wordring/whatwg/infra/unicode.hpp>
21 class text_decoder_common;
50 bool fatal()
const {
return m_error_mode == error_mode_name::Fatal; }
59 encoding_name m_encoding =
static_cast<encoding_name
>(0);
62 bool m_ignore_bom =
false;
63 bool m_bom_seen =
false;
64 error_mode_name m_error_mode = error_mode_name::Replacement;
74 std::u32string output;
80 if (item->m_eoq)
return output;
81 if ( (c.m_encoding == encoding_name::UTF_8 || c.m_encoding == encoding_name::UTF_16BE || c.m_encoding == encoding_name::UTF_16LE)
82 && (c.m_ignore_bom ==
false)
83 && (c.m_bom_seen ==
false))
86 if (item->m_value == U
'\xFEFF')
continue;
88 output.push_back(item->m_value);
91 return std::u32string{};
106 if (
encoding ==
static_cast<encoding_name
>(0) ||
encoding == encoding_name::replacement)
throw std::range_error(
"bad encoding label.");
110 if (
fatal ==
true) m_error_mode = error_mode_name::Fatal;
122 encoding_name
encoding = get_encoding_name(label);
124 if (
encoding ==
static_cast<encoding_name
>(0) ||
encoding == encoding_name::replacement)
throw std::range_error(
"bad encoding label.");
128 if (
fatal ==
true) m_error_mode = error_mode_name::Fatal;
139 template <
typename InputIterator = std::
nullptr_t>
140 std::u32string
decode(InputIterator first =
nullptr, InputIterator last =
nullptr,
bool stream =
false)
143 if (m_do_not_flush ==
false)
148 m_io_queue.
push(eoq);
152 m_do_not_flush = stream;
154 if constexpr (std::negation_v<std::is_same<InputIterator, std::nullptr_t>>)
156 m_io_queue.
push(first, last);
172 result_value rv =
process_item(*item, m_decoder, m_io_queue, output, m_error_mode);
173 if (std::holds_alternative<result_finished>(rv))
return serialize_io_queue(*
this, output);
174 if (std::holds_alternative<result_error>(rv))
throw std::range_error(
"decode error.");
181 bool m_do_not_flush =
false;
std::u32string serialize_io_queue(text_decoder_common &c, io_queue< char32_t > &in)
IO キューを直列化する
Definition: whatwg/encoding/api.hpp:71
result_value process_item(IoItem, Coder &, InQueue &, OutQueue &, error_mode_name)
文字アイテムを処理する
Definition: whatwg/encoding/encoding.hpp:62
文字にキュー終端表現を追加するラッパー
Definition: terminology.hpp:26
bool fatal() const
Fatal フラグ
Definition: whatwg/encoding/api.hpp:50
text_decoder(std::u32string_view label=U"utf-8", bool fatal=false, bool ignore_bom=false)
構築
Definition: whatwg/encoding/api.hpp:119
TextDecoderCommon
Definition: whatwg/encoding/api.hpp:98
TextDecoderCommon
Definition: whatwg/encoding/api.hpp:29
void push(value_type item)
Push
Definition: terminology.hpp:152
std::u32string encoding() const
エンコーディング名
Definition: whatwg/encoding/api.hpp:41
入出力ストリーム
Definition: terminology.hpp:55
std::u32string decode(InputIterator first=nullptr, InputIterator last=nullptr, bool stream=false)
デコード
Definition: whatwg/encoding/api.hpp:140
io_result< value_type > read()
値を一つ読み取る
Definition: terminology.hpp:79
friend std::u32string serialize_io_queue(text_decoder_common &, io_queue< char32_t > &)
IO キューを直列化する
Definition: whatwg/encoding/api.hpp:71
bool ignore_bom() const
BOM 無視フラグ
Definition: whatwg/encoding/api.hpp:56
待機状態を追加するラッパー
Definition: terminology.hpp:37
std::u32string get_encoding_label(encoding_name name)
エンコーディングに対応するラベルを返す
Definition: whatwg/encoding/encoding.hpp:171
coder get_encoding_decoder(encoding_name name)
Definition: whatwg/encoding/encoding.hpp:224