add a standard function to write a replacement character
parent
032d687293
commit
229b715d2c
|
@ -988,14 +988,6 @@ private:
|
|||
for (int w = p_width - int(n); --w >= 0; writer.put(c));
|
||||
}
|
||||
|
||||
template<typename R>
|
||||
void write_replacement(R &writer) const {
|
||||
/* Unicode replacement character */
|
||||
writer.put(0xEF);
|
||||
writer.put(0xBF);
|
||||
writer.put(0xBD);
|
||||
}
|
||||
|
||||
template<typename R>
|
||||
void write_char_raw(R &writer, char val) const {
|
||||
writer.put(val);
|
||||
|
@ -1009,7 +1001,7 @@ private:
|
|||
template<typename R>
|
||||
void write_char_raw(R &writer, char32_t val) const {
|
||||
if (!utf::encode<char>(writer, val)) {
|
||||
write_replacement(writer);
|
||||
utf::replace<char>(writer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1048,7 +1040,7 @@ private:
|
|||
}
|
||||
val.pop_front();
|
||||
} else if (!utf::encode<char>(writer, val)) {
|
||||
write_replacement(writer);
|
||||
utf::replace<char>(writer);
|
||||
val.pop_front();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -851,6 +851,24 @@ namespace utf {
|
|||
return encode<unicode_t<N>>(sink, r);
|
||||
}
|
||||
|
||||
template<typename C, typename R>
|
||||
inline std::size_t replace(R &sink) {
|
||||
if constexpr(max_units<C> > 2) {
|
||||
sink.put(0xEF);
|
||||
sink.put(0xBF);
|
||||
sink.put(0xBD);
|
||||
return 3;
|
||||
} else {
|
||||
sink.put(0xFFFD);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<std::size_t N, typename R>
|
||||
inline std::size_t replace(R &sink) {
|
||||
return replace<unicode_t<N>>(sink);
|
||||
}
|
||||
|
||||
/* @brief Get the number of Unicode code points in a string.
|
||||
*
|
||||
* This function keeps reading Unicode code points while it can and
|
||||
|
|
Loading…
Reference in New Issue