29 #include YFM_YSLib_Service_TextManager
30 #include YFM_CHRLib_MappingEx
32 #include YFM_CHRLib_Convert
55 : p_buffer(p_buf), block(b), index(idx)
75 YAssert(p_buffer,
"Null buffer pointer found.");
76 YAssert(block != 0 || index != 0,
"Begin iterator found."),
78 "Invalid iterator found.");
81 index = (*p_buffer)[--block].first.size();
83 YAssert(index != 0,
"Invalid index found.");
87 "Invalid index found.");
92 TextFileBuffer::iterator::reference
97 auto& vec((*p_buffer)[block].
first);
99 YAssert(!vec.empty(),
"Empty block found.");
100 YAssert(index < vec.size(),
"Invalid index found.");
108 YAssert(x.p_buffer == y.p_buffer,
"Iterators to different buffer are not"
111 return x.block == y.block && x.index == y.index;
129 TextFileBuffer::operator[](
size_t idx)
137 if(
const auto pfun = FetchMapperFunc(
File.Encoding))
155 == ConversionResult::OK))
157 n_byte += GetCountOf(st);
159 std::ungetc(*i,
File.GetPtr()),
165 TextFileBuffer::iterator
180 const size_t idx(pos / BlockSize);
188 if(
const auto pfun = FetchSkipMapperFunc(
File.Encoding))
190 File.Locate(idx * BlockSize);
192 size_t n_byte(0), n_char(0);
200 == ConversionResult::OK))
202 n_byte += GetCountOf(st);
204 std::ungetc(*i,
File.GetPtr());
217 auto idx(i.GetBlockN());
218 const auto pos(i.GetIndexN());
221 return idx * BlockSize + pos *
max_width;
223 if(
const auto pfun = FetchSkipMapperFunc(
File.Encoding))
225 const auto& vec((*
this)[idx].
first);
227 YAssert(!vec.empty() && bool(
File),
"Block loading failed.");
229 File.Locate(idx *= BlockSize);
231 const auto mid(vec.cbegin() + pos);
233 YAssert(mid <= vec.cend(),
"Wrong iterator found.");
235 auto it(vec.begin());
237 YAssert(it <= mid,
"Wrong iterator found.");
247 == ConversionResult::OK))
249 n_byte += GetCountOf(st);
261 const auto i_end(buf.end());
262 auto i_beg(buf.GetIterator(pos));
265 throw std::out_of_range(
"Wrong offset found.");
269 YAssert(pos < pos + len,
"Unexpected unsigned integer round up.");
273 str.reserve(len * 2);
274 while(len != 0 && i_beg != i_end)
276 str.push_back(*i_beg);
TextFileBuffer(TextFile &)
构造:使用文本文件。
static auto first(const _tIterator &i) -> decltype((i->first))
size_t GetPosition(iterator)
取迭代器对应的文本字节位置。
ConversionResult ConvertCharacter(_fConv f, ucs2_t &uc, _tIn &&i, ConversionState &&st)
iterator & operator++() ynothrow
迭代:循环向后遍历。
iterator end() ynothrow
取文本缓冲区终止迭代器。
size_t max_width
最大编码每字符的字节数。
#define YB_UNLIKELY(expr)
分支预测提示。
size_t fixed_width
固定编码每字符的字节数。
#define yunseq
无序列依赖表达式组求值。
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
TextFileBuffer * p_buffer
#define ythrow(...)
YSLib 动态异常规范:根据是否使用异常规范宏指定或忽略动态异常规范。
YF_API size_t FetchMaxVariantCharWidth(Encoding)
取指定变长编码的最大字符宽度。
iterator & operator--() ynothrow
迭代:循环向前遍历。
#define YAssertNonnull(_expr)
reference operator*() const
iterator begin() ynothrow
取文本缓冲区起始迭代器。
YF_API size_t FetchFixedCharWidth(Encoding)
取指定固定编码的固定字符宽度。
char16_t ucs2_t
UCS-2 字符类型。
#define yconstexpr
指定编译时常量表达式。
bool operator==(const TextFileBuffer::iterator &x, const TextFileBuffer::iterator &y) ynothrow
static yconstexpr size_t BlockSize
默认文本区块大小。
File Encoding nTextSize iterator GetIterator(size_t)
取文本字节位置对应的迭代器。
_fCodemapTransform * FetchMapperPtr(Encoding enc)
取指定编码映射的转换函数指针。
string CopySliceFrom(TextFileBuffer &buf, size_t pos, size_t len) ythrow(std
iterator(TextFileBuffer *={}, size_t=0, size_t=0) ynothrow
构造:指定文本读取位置。
#define YAssert(_expr, _msg)
pair< vector< ucs2_t >, size_t > BlockType
缓冲区块类型。