Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/intl/icu/source/common/bytesinkutil.h
Line
Count
Source (jump to first uncovered line)
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
13
U_NAMESPACE_BEGIN
14
15
class ByteSink;
16
class Edits;
17
18
class U_COMMON_API ByteSinkUtil {
19
public:
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
0
                                       ByteSink &sink, Edits *edits = nullptr) {
38
0
        appendCodePoint((int32_t)(nextSrc - src), c, sink, edits);
39
0
    }
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
0
                                 UErrorCode &errorCode) {
47
0
        if (U_FAILURE(errorCode)) { return FALSE; }
48
0
        if (length > 0) { appendNonEmptyUnchanged(s, length, sink, options, edits); }
49
0
        return TRUE;
50
0
    }
51
52
    static UBool appendUnchanged(const uint8_t *s, const uint8_t *limit,
53
                                 ByteSink &sink, uint32_t options, Edits *edits,
54
                                 UErrorCode &errorCode);
55
56
private:
57
    static void appendNonEmptyUnchanged(const uint8_t *s, int32_t length,
58
                                        ByteSink &sink, uint32_t options, Edits *edits);
59
};
60
61
U_NAMESPACE_END