32 #ifndef __BYTESTREAM_H__
33 #define __BYTESTREAM_H__
42 #if U_SHOW_CPLUSPLUS_API
44 #include <type_traits>
74 virtual void Append(
const char* bytes, int32_t n) = 0;
87 inline void AppendU8(
const char* bytes, int32_t n) {
91 #if defined(__cpp_char8_t) || defined(U_IN_DOXYGEN)
103 inline void AppendU8(
const char8_t* bytes, int32_t n) {
104 Append(reinterpret_cast<const char*>(bytes), n);
150 virtual char* GetAppendBuffer(int32_t min_capacity,
151 int32_t desired_capacity_hint,
152 char* scratch, int32_t scratch_capacity,
153 int32_t* result_capacity);
163 virtual void Flush();
211 virtual void Append(
const char* bytes, int32_t n)
override;
227 int32_t desired_capacity_hint,
228 char* scratch, int32_t scratch_capacity,
229 int32_t* result_capacity)
override;
253 const int32_t capacity_;
265 template<
typename StringClass,
typename =
void>
271 template<
typename StringClass>
274 using type =
typename StringClass::value_type;
277 template<
typename StringClass>
290 template<
typename StringClass>
292 using Unit =
typename prv::value_type_or_char_t<StringClass>;
308 if (initialAppendCapacity > 0 &&
309 static_cast<uint32_t>(initialAppendCapacity) > dest->capacity() - dest->length()) {
310 dest->reserve(dest->length() + initialAppendCapacity);
319 virtual void Append(
const char* data, int32_t n)
override {
320 if constexpr (std::is_same_v<Unit, char>) {
321 dest_->append(data, n);
323 dest_->append(reinterpret_cast<const Unit*>(data), n);
338 #endif // __BYTESTREAM_H__
virtual char * GetAppendBuffer(int32_t min_capacity, int32_t desired_capacity_hint, char *scratch, int32_t scratch_capacity, int32_t *result_capacity)
Returns a writable buffer for appending and writes the buffer's capacity to *result_capacity.
StringByteSink(StringClass *dest)
Constructs a ByteSink that will append bytes to the dest string.
int32_t NumberOfBytesWritten() const
Returns the number of bytes actually written to the sink.
UBool Overflowed() const
Returns true if any bytes were discarded, i.e., if there was an attempt to write more than 'capacity'...
ByteSink()
Default constructor.
A ByteSink can be filled with bytes.
virtual void Append(const char *bytes, int32_t n)=0
Append "bytes[0,n-1]" to this.
Implementation of ByteSink that writes to a flat byte array, with bounds-checking: This sink will not...
typename StringClass::value_type type
StringByteSink(StringClass *dest, int32_t initialAppendCapacity)
Constructs a ByteSink that reserves append capacity and will append bytes to the dest string...
C++ API: Central ICU header for including the C++ standard <string> header and for related definition...
C++ API: Common ICU base class UObject.
int32_t NumberOfBytesAppended() const
Returns the number of bytes appended to the sink.
Basic definitions for ICU, for both C and C++ APIs.
Implementation of ByteSink that writes to a "string".
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
void AppendU8(const char8_t *bytes, int32_t n)
Appends n bytes to this.
UMemory is the common ICU base class.
virtual void Append(const char *data, int32_t n) override
Append "bytes[0,n-1]" to this.
int8_t UBool
The ICU boolean type, a signed-byte integer.
void AppendU8(const char *bytes, int32_t n)
Appends n bytes to this.