_tOut transform_when(_tIn first, _tOut result, _fPred pred, _fOp op) { yunseq((yconstraint(!is_undereferenceable(first)), 0), (yconstraint(!is_undereferenceable(result)), 0)); for(; pred(*first); yunseq((++first, 0), (++result, 0))) *result = op(*first); return result; }
_tIn next_if(_tIn i, _fPred f, typename std::iterator_traits<_tIn>::difference_type n = 1) { yconstraint(!is_undereferenceable(i)); return f(*i) ? std::next(i, n) : i; }
_tIn next_if_eq(_tIn i, const _type& val, typename std::iterator_traits<_tIn>::difference_type n = 1) { yconstraint(!is_undereferenceable(i)); return *i == val ? std::next(i, n) : i; }
size_t UCS2ToMBCS(char* d, const char16_t* s, Encoding enc) { if(const auto pfun = FetchMapperPtr<size_t, char*, char32_t>(enc)) return UCS2ToMBCS(pfun, d, s); else yconstraint(d && s); return 0; }
ConversionResult MBCToUC(const char*& c, const char* e, Encoding enc, ConversionState&& st) { yconstraint(c <= e); if(const auto pfun = FetchMapperPtr<ConversionResult, ystdex::pseudo_output&&, GuardPair<const char*>&&, ConversionState&&>(enc)) return pfun(ystdex::pseudo_output(), {c, e}, std::move(st)); return ConversionResult::Unhandled; }
size_t UCS2ToMBCS(char* d, const char16_t* s, const char16_t* e, Encoding enc) { // TODO: Deferred. Use guard for encoding. if(const auto pfun = FetchMapperPtr<size_t, char*, char32_t>(enc)) return UCS2ToMBCS(pfun, d, s, e); else yconstraint(d && s && e && s <= e); return 0; }
size_t MBCSToUCS2(char16_t* d, const char* s, const char* e, Encoding enc) { if(const auto pfun = FetchMapperPtr<ConversionResult, char16_t&, GuardPair<const char*>&&, ConversionState&&>(enc)) return MBCSToUCS2(pfun, d, s, e); else yconstraint(d && s && e && s <= e); return 0; }
size_t MBCSToUCS2(char16_t* d, const char* s, Encoding enc) { if(const auto pfun = FetchMapperPtr<ConversionResult, char16_t&, const char*&, ConversionState&&>(enc)) return MBCSToUCS2(pfun, d, s); else yconstraint(d && s); return 0; }
size_t MBCSToUCS4(char32_t* d, const char* s, const char* e, Encoding enc) { // TODO: Use UCS-4 internal conversion directly? if(const auto pfun = FetchMapperPtr<ConversionResult, char16_t&, GuardPair<const char*>&&, ConversionState&&>(enc)) return MBCSToUCS4(pfun, d, s, e); else yconstraint(d && s && e && s <= e); return 0; }
size_t UCToMBC(char* d, const char16_t& s, Encoding enc) { yconstraint(d); size_t l(0); if(const auto pfun = FetchMapperPtr<size_t, char*, char32_t>(enc)) l = pfun(d, s); return l; }
ConversionResult MBCToUC(char16_t& uc, std::FILE* fp, Encoding enc, ConversionState&& st) { yconstraint(fp); if(const auto pfun = FetchMapperPtr<ConversionResult, char16_t&, ystdex::ifile_iterator&, ConversionState&&>(enc)) { ystdex::ifile_iterator i(fp); const auto r(pfun(uc, i, std::move(st))); i.sungetc(fp); return r; } return ConversionResult::Unhandled; }