1 // © 2017 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
5 // created: 2017sep14 Markus W. Scherer
7 #include "unicode/utypes.h"
8 #include "unicode/bytestream.h"
9 #include "unicode/edits.h"
19 class U_COMMON_API ByteSinkUtil
{
21 ByteSinkUtil() = delete; // all static
23 /** (length) bytes were mapped to valid (s16, s16Length). */
24 static UBool
appendChange(int32_t length
,
25 const char16_t *s16
, int32_t s16Length
,
26 ByteSink
&sink
, Edits
*edits
, UErrorCode
&errorCode
);
28 /** The bytes at [s, limit[ were mapped to valid (s16, s16Length). */
29 static UBool
appendChange(const uint8_t *s
, const uint8_t *limit
,
30 const char16_t *s16
, int32_t s16Length
,
31 ByteSink
&sink
, Edits
*edits
, UErrorCode
&errorCode
);
33 /** (length) bytes were mapped/changed to valid code point c. */
34 static void appendCodePoint(int32_t length
, UChar32 c
, ByteSink
&sink
, Edits
*edits
= nullptr);
36 /** The few bytes at [src, nextSrc[ were mapped/changed to valid code point c. */
37 static inline void appendCodePoint(const uint8_t *src
, const uint8_t *nextSrc
, UChar32 c
,
38 ByteSink
&sink
, Edits
*edits
= nullptr) {
39 appendCodePoint((int32_t)(nextSrc
- src
), c
, sink
, edits
);
42 /** Append the two-byte character (U+0080..U+07FF). */
43 static void appendTwoBytes(UChar32 c
, ByteSink
&sink
);
45 static UBool
appendUnchanged(const uint8_t *s
, int32_t length
,
46 ByteSink
&sink
, uint32_t options
, Edits
*edits
,
47 UErrorCode
&errorCode
) {
48 if (U_FAILURE(errorCode
)) { return FALSE
; }
49 if (length
> 0) { appendNonEmptyUnchanged(s
, length
, sink
, options
, edits
); }
53 static UBool
appendUnchanged(const uint8_t *s
, const uint8_t *limit
,
54 ByteSink
&sink
, uint32_t options
, Edits
*edits
,
55 UErrorCode
&errorCode
);
58 static void appendNonEmptyUnchanged(const uint8_t *s
, int32_t length
,
59 ByteSink
&sink
, uint32_t options
, Edits
*edits
);
62 class U_COMMON_API CharStringByteSink
: public ByteSink
{
64 CharStringByteSink(CharString
* dest
);
65 ~CharStringByteSink() override
;
67 CharStringByteSink() = delete;
68 CharStringByteSink(const CharStringByteSink
&) = delete;
69 CharStringByteSink
& operator=(const CharStringByteSink
&) = delete;
71 void Append(const char* bytes
, int32_t n
) override
;
73 char* GetAppendBuffer(int32_t min_capacity
,
74 int32_t desired_capacity_hint
,
76 int32_t scratch_capacity
,
77 int32_t* result_capacity
) override
;