// CharString doesn't provide the public API that StringByteSink requires a // string class to have so this template specialization replaces the default // implementation of StringByteSink<CharString> with CharStringByteSink. template<> class StringByteSink<CharString> : public CharStringByteSink { public:
StringByteSink(CharString* dest) : CharStringByteSink(dest) { }
StringByteSink(CharString* dest, int32_t /*initialAppendCapacity*/) : CharStringByteSink(dest) { }
};
class U_COMMON_API ByteSinkUtil { public:
ByteSinkUtil() = delete; // all static
/** * Calls a lambda that writes to a ByteSink with a CheckedArrayByteSink * and then returns through u_terminateChars(), in order to implement * the classic ICU4C C API writing to a fix sized buffer on top of a * contemporary C++ API. * * @param buffer receiving buffer * @param capacity capacity of receiving buffer * @param lambda that gets called with the sink as an argument * @param status set to U_BUFFER_OVERFLOW_ERROR on overflow * @return number of bytes written, or needed (in case of overflow) * @internal
*/ template <typename F, typename = std::enable_if_t<
std::is_invocable_r_v<void, F, ByteSink&, UErrorCode&>>> static int32_t viaByteSinkToTerminatedChars(char* buffer, int32_t capacity,
F&& lambda,
UErrorCode& status) { if (U_FAILURE(status)) { return 0; }
CheckedArrayByteSink sink(buffer, capacity);
lambda(sink, status); if (U_FAILURE(status)) { return 0; }
int32_t reslen = sink.NumberOfBytesAppended();
if (sink.Overflowed()) {
status = U_BUFFER_OVERFLOW_ERROR; return reslen;
}
/** * Calls a lambda that writes to a ByteSink with a CharStringByteSink and * then returns a CharString, in order to implement a contemporary C++ API * on top of a C/C++ compatibility ByteSink API. * * @param lambda that gets called with the sink as an argument * @param status to check and report * @return the resulting string, or an empty string (in case of error) * @internal
*/ template <typename F, typename = std::enable_if_t<
std::is_invocable_r_v<void, F, ByteSink&, UErrorCode&>>> static CharString viaByteSinkToCharString(F&& lambda, UErrorCode& status) { if (U_FAILURE(status)) { return {}; }
CharString result;
CharStringByteSink sink(&result);
lambda(sink, status); return result;
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.4Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.