Coverage Report

Created: 2025-11-07 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/icu/icu4c/source/i18n/collationtailoring.h
Line
Count
Source
1
// © 2016 and later: Unicode, Inc. and others.
2
// License & terms of use: http://www.unicode.org/copyright.html
3
/*
4
*******************************************************************************
5
* Copyright (C) 2013-2014, International Business Machines
6
* Corporation and others.  All Rights Reserved.
7
*******************************************************************************
8
* collationtailoring.h
9
*
10
* created on: 2013mar12
11
* created by: Markus W. Scherer
12
*/
13
14
#ifndef __COLLATIONTAILORING_H__
15
#define __COLLATIONTAILORING_H__
16
17
#include "unicode/utypes.h"
18
19
#if !UCONFIG_NO_COLLATION
20
21
#include "unicode/locid.h"
22
#include "unicode/unistr.h"
23
#include "unicode/uversion.h"
24
#include "collationsettings.h"
25
#include "uhash.h"
26
#include "umutex.h"
27
#include "unifiedcache.h"
28
 
29
30
struct UDataMemory;
31
struct UResourceBundle;
32
struct UTrie2;
33
34
U_NAMESPACE_BEGIN
35
36
struct CollationData;
37
38
class UnicodeSet;
39
40
/**
41
 * Collation tailoring data & settings.
42
 * This is a container of values for a collation tailoring
43
 * built from rules or deserialized from binary data.
44
 *
45
 * It is logically immutable: Do not modify its values.
46
 * The fields are public for convenience.
47
 *
48
 * It is shared, reference-counted, and auto-deleted; see SharedObject.
49
 *
50
 * U_I18N_API because genuca & genrb use it.
51
 */
52
struct U_I18N_API_CLASS CollationTailoring : public SharedObject {
53
    U_I18N_API CollationTailoring(const CollationSettings *baseSettings);
54
    U_I18N_API virtual ~CollationTailoring();
55
56
    /**
57
     * Returns true if the constructor could not initialize properly.
58
     */
59
7.84k
    U_I18N_API UBool isBogus() { return settings == nullptr; }
60
61
    U_I18N_API UBool ensureOwnedData(UErrorCode &errorCode);
62
63
    U_I18N_API static void makeBaseVersion(const UVersionInfo ucaVersion, UVersionInfo version);
64
    U_I18N_API void setVersion(const UVersionInfo baseVersion, const UVersionInfo rulesVersion);
65
    U_I18N_API int32_t getUCAVersion() const;
66
67
    // data for sorting etc.
68
    const CollationData *data;  // == base data or ownedData
69
    const CollationSettings *settings;  // reference-counted
70
    UnicodeString rules;
71
    // The locale is bogus when built from rules or constructed from a binary blob.
72
    // It can then be set by the service registration code which is thread-safe.
73
    mutable Locale actualLocale;
74
    // UCA version u.v.w & rules version r.s.t.q:
75
    // version[0]: builder version (runtime version is mixed in at runtime)
76
    // version[1]: bits 7..3=u, bits 2..0=v
77
    // version[2]: bits 7..6=w, bits 5..0=r
78
    // version[3]= (s<<5)+(s>>3)+t+(q<<4)+(q>>4)
79
    UVersionInfo version;
80
81
    // owned objects
82
    CollationData *ownedData;
83
    UObject *builder;
84
    UDataMemory *memory;
85
    UResourceBundle *bundle;
86
    UTrie2 *trie;
87
    UnicodeSet *unsafeBackwardSet;
88
    mutable UHashtable *maxExpansions;
89
    mutable UInitOnce maxExpansionsInitOnce;
90
91
private:
92
    /**
93
     * No copy constructor: A CollationTailoring cannot be copied.
94
     * It is immutable, and the data trie cannot be copied either.
95
     */
96
    CollationTailoring(const CollationTailoring &other) = delete;
97
};
98
99
// U_I18N_API because gencolusb uses it.
100
struct U_I18N_API_CLASS CollationCacheEntry : public SharedObject {
101
    U_I18N_API CollationCacheEntry(const Locale &loc, const CollationTailoring *t)
102
4.28k
            : validLocale(loc), tailoring(t) {
103
4.28k
        if(t != nullptr) {
104
4.28k
            t->addRef();
105
4.28k
        }
106
4.28k
    }
107
    U_I18N_API ~CollationCacheEntry();
108
109
    Locale validLocale;
110
    const CollationTailoring *tailoring;
111
};
112
113
template<> U_I18N_API
114
const CollationCacheEntry *
115
LocaleCacheKey<CollationCacheEntry>::createObject(const void *creationContext,
116
                                                  UErrorCode &errorCode) const;
117
U_NAMESPACE_END
118
119
#endif  // !UCONFIG_NO_COLLATION
120
#endif  // __COLLATIONTAILORING_H__