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"
18 class U_COMMON_API ByteSinkUtil
{
20 ByteSinkUtil() = delete; // all static
22 /** (length) bytes were mapped to valid (s16, s16Length). */
23 static UBool
appendChange(int32_t length
,
24 const char16_t *s16
, int32_t s16Length
,
25 ByteSink
&sink
, Edits
*edits
, UErrorCode
&errorCode
);
27 /** The bytes at [s, limit[ were mapped to valid (s16, s16Length). */
28 static UBool
appendChange(const uint8_t *s
, const uint8_t *limit
,
29 const char16_t *s16
, int32_t s16Length
,
30 ByteSink
&sink
, Edits
*edits
, UErrorCode
&errorCode
);
32 /** (length) bytes were mapped/changed to valid code point c. */
33 static void appendCodePoint(int32_t length
, UChar32 c
, ByteSink
&sink
, Edits
*edits
= nullptr);
35 /** The few bytes at [src, nextSrc[ were mapped/changed to valid code point c. */
36 static inline void appendCodePoint(const uint8_t *src
, const uint8_t *nextSrc
, UChar32 c
,
37 ByteSink
&sink
, Edits
*edits
= nullptr) {
38 appendCodePoint((int32_t)(nextSrc
- src
), c
, sink
, edits
);
41 /** Append the two-byte character (U+0080..U+07FF). */
42 static void appendTwoBytes(UChar32 c
, ByteSink
&sink
);
44 static UBool
appendUnchanged(const uint8_t *s
, int32_t length
,
45 ByteSink
&sink
, uint32_t options
, Edits
*edits
,
46 UErrorCode
&errorCode
) {
47 if (U_FAILURE(errorCode
)) { return FALSE
; }
48 if (length
> 0) { appendNonEmptyUnchanged(s
, length
, sink
, options
, edits
); }
52 static UBool
appendUnchanged(const uint8_t *s
, const uint8_t *limit
,
53 ByteSink
&sink
, uint32_t options
, Edits
*edits
,
54 UErrorCode
&errorCode
);
57 static void appendNonEmptyUnchanged(const uint8_t *s
, int32_t length
,
58 ByteSink
&sink
, uint32_t options
, Edits
*edits
);