mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 06:25:30 +00:00
ICU-23004 istreambuf_iterator example
This commit is contained in:
parent
cb1de7ef66
commit
4e8ae459d1
1 changed files with 14 additions and 0 deletions
|
@ -105,6 +105,20 @@ std::string_view firstSequence8(std::string_view s) {
|
|||
}
|
||||
}
|
||||
|
||||
template<typename InputStream> // some istream or streambuf
|
||||
std::u32string cpFromInput(InputStream &in) {
|
||||
// This is a single-pass input_iterator.
|
||||
std::istreambuf_iterator bufIter(in);
|
||||
std::istreambuf_iterator<typename InputStream::char_type> bufLimit;
|
||||
auto begin = utfIterator<char32_t, UTF_BEHAVIOR_FFFD>(bufIter);
|
||||
auto limit = utfIterator<char32_t, UTF_BEHAVIOR_FFFD>(bufLimit);
|
||||
std::u32string s32;
|
||||
for (; bufIter != bufLimit; ++bufIter) {
|
||||
s32.push_back(*bufIter);
|
||||
}
|
||||
return s32;
|
||||
}
|
||||
|
||||
#endif // SAMPLE_CODE
|
||||
|
||||
template<typename Unit>
|
||||
|
|
Loading…
Add table
Reference in a new issue