1// © 2017 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3
4// bytesinkutil.h
5// created: 2017sep14 Markus W. Scherer
6
7#include "unicode/utypes.h"
8#include "unicode/bytestream.h"
9#include "unicode/edits.h"
10#include "cmemory.h"
11#include "uassert.h"
12
13U_NAMESPACE_BEGIN
14
15class ByteSink;
16class Edits;
17
18class U_COMMON_API ByteSinkUtil {
19public:
20    ByteSinkUtil() = delete;  // all static
21
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);
26
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);
31
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);
34
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);
39    }
40
41    /** Append the two-byte character (U+0080..U+07FF). */
42    static void appendTwoBytes(UChar32 c, ByteSink &sink);
43
44    static UBool appendUnchanged(const uint8_t *s, int32_t length,
45                                 ByteSink &sink, uint32_t options, Edits *edits,
46                                 UErrorCode &errorCode);
47
48    static UBool appendUnchanged(const uint8_t *s, const uint8_t *limit,
49                                 ByteSink &sink, uint32_t options, Edits *edits,
50                                 UErrorCode &errorCode);
51};
52
53U_NAMESPACE_END
54