xref: /aosp_15_r20/external/icu/libicu/cts_headers/scriptset.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /*
4*0e209d39SAndroid Build Coastguard Worker **********************************************************************
5*0e209d39SAndroid Build Coastguard Worker *   Copyright (C) 2013, International Business Machines
6*0e209d39SAndroid Build Coastguard Worker *   Corporation and others.  All Rights Reserved.
7*0e209d39SAndroid Build Coastguard Worker **********************************************************************
8*0e209d39SAndroid Build Coastguard Worker *
9*0e209d39SAndroid Build Coastguard Worker * scriptset.h
10*0e209d39SAndroid Build Coastguard Worker *
11*0e209d39SAndroid Build Coastguard Worker * created on: 2013 Jan 7
12*0e209d39SAndroid Build Coastguard Worker * created by: Andy Heninger
13*0e209d39SAndroid Build Coastguard Worker */
14*0e209d39SAndroid Build Coastguard Worker 
15*0e209d39SAndroid Build Coastguard Worker #ifndef __SCRIPTSET_H__
16*0e209d39SAndroid Build Coastguard Worker #define __SCRIPTSET_H__
17*0e209d39SAndroid Build Coastguard Worker 
18*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
19*0e209d39SAndroid Build Coastguard Worker #include "unicode/uobject.h"
20*0e209d39SAndroid Build Coastguard Worker #include "unicode/uscript.h"
21*0e209d39SAndroid Build Coastguard Worker 
22*0e209d39SAndroid Build Coastguard Worker #include "uelement.h"
23*0e209d39SAndroid Build Coastguard Worker 
24*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
25*0e209d39SAndroid Build Coastguard Worker 
26*0e209d39SAndroid Build Coastguard Worker //-------------------------------------------------------------------------------
27*0e209d39SAndroid Build Coastguard Worker //
28*0e209d39SAndroid Build Coastguard Worker //  ScriptSet - A bit set representing a set of scripts.
29*0e209d39SAndroid Build Coastguard Worker //
30*0e209d39SAndroid Build Coastguard Worker //              This class was originally used exclusively with script sets appearing
31*0e209d39SAndroid Build Coastguard Worker //              as part of the spoof check whole script confusable binary data. Its
32*0e209d39SAndroid Build Coastguard Worker //              use has since become more general, but the continued use to wrap
33*0e209d39SAndroid Build Coastguard Worker //              prebuilt binary data does constrain the design.
34*0e209d39SAndroid Build Coastguard Worker //
35*0e209d39SAndroid Build Coastguard Worker //-------------------------------------------------------------------------------
36*0e209d39SAndroid Build Coastguard Worker class U_I18N_API ScriptSet: public UMemory {
37*0e209d39SAndroid Build Coastguard Worker   public:
38*0e209d39SAndroid Build Coastguard Worker     static constexpr int32_t SCRIPT_LIMIT = 224;  // multiple of 32!
39*0e209d39SAndroid Build Coastguard Worker 
40*0e209d39SAndroid Build Coastguard Worker     ScriptSet();
41*0e209d39SAndroid Build Coastguard Worker     ScriptSet(const ScriptSet &other);
42*0e209d39SAndroid Build Coastguard Worker     ~ScriptSet();
43*0e209d39SAndroid Build Coastguard Worker 
44*0e209d39SAndroid Build Coastguard Worker     bool operator == (const ScriptSet &other) const;
45*0e209d39SAndroid Build Coastguard Worker     bool operator != (const ScriptSet &other) const {return !(*this == other);}
46*0e209d39SAndroid Build Coastguard Worker     ScriptSet & operator = (const ScriptSet &other);
47*0e209d39SAndroid Build Coastguard Worker 
48*0e209d39SAndroid Build Coastguard Worker     UBool      test(UScriptCode script, UErrorCode &status) const;
49*0e209d39SAndroid Build Coastguard Worker     ScriptSet &Union(const ScriptSet &other);
50*0e209d39SAndroid Build Coastguard Worker     ScriptSet &set(UScriptCode script, UErrorCode &status);
51*0e209d39SAndroid Build Coastguard Worker     ScriptSet &reset(UScriptCode script, UErrorCode &status);
52*0e209d39SAndroid Build Coastguard Worker     ScriptSet &intersect(const ScriptSet &other);
53*0e209d39SAndroid Build Coastguard Worker     ScriptSet &intersect(UScriptCode script, UErrorCode &status);
54*0e209d39SAndroid Build Coastguard Worker     UBool      intersects(const ScriptSet &other) const;  // Sets contain at least one script in common.
55*0e209d39SAndroid Build Coastguard Worker     UBool      contains(const ScriptSet &other) const;    // All set bits in other are also set in this.
56*0e209d39SAndroid Build Coastguard Worker 
57*0e209d39SAndroid Build Coastguard Worker     ScriptSet &setAll();
58*0e209d39SAndroid Build Coastguard Worker     ScriptSet &resetAll();
59*0e209d39SAndroid Build Coastguard Worker     int32_t countMembers() const;
60*0e209d39SAndroid Build Coastguard Worker     int32_t hashCode() const;
61*0e209d39SAndroid Build Coastguard Worker     int32_t nextSetBit(int32_t script) const;
62*0e209d39SAndroid Build Coastguard Worker 
63*0e209d39SAndroid Build Coastguard Worker     UBool isEmpty() const;
64*0e209d39SAndroid Build Coastguard Worker 
65*0e209d39SAndroid Build Coastguard Worker     UnicodeString &displayScripts(UnicodeString &dest) const; // append script names to dest string.
66*0e209d39SAndroid Build Coastguard Worker     ScriptSet & parseScripts(const UnicodeString &scriptsString, UErrorCode &status);  // Replaces ScriptSet contents.
67*0e209d39SAndroid Build Coastguard Worker 
68*0e209d39SAndroid Build Coastguard Worker     // Wraps around UScript::getScriptExtensions() and adds the corresponding scripts to this instance.
69*0e209d39SAndroid Build Coastguard Worker     void setScriptExtensions(UChar32 codePoint, UErrorCode& status);
70*0e209d39SAndroid Build Coastguard Worker 
71*0e209d39SAndroid Build Coastguard Worker   private:
72*0e209d39SAndroid Build Coastguard Worker     uint32_t  bits[SCRIPT_LIMIT / 32];
73*0e209d39SAndroid Build Coastguard Worker };
74*0e209d39SAndroid Build Coastguard Worker 
75*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
76*0e209d39SAndroid Build Coastguard Worker 
77*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
78*0e209d39SAndroid Build Coastguard Worker uhash_compareScriptSet(const UElement key1, const UElement key2);
79*0e209d39SAndroid Build Coastguard Worker 
80*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
81*0e209d39SAndroid Build Coastguard Worker uhash_hashScriptSet(const UElement key);
82*0e209d39SAndroid Build Coastguard Worker 
83*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
84*0e209d39SAndroid Build Coastguard Worker uhash_deleteScriptSet(void *obj);
85*0e209d39SAndroid Build Coastguard Worker 
86*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
87*0e209d39SAndroid Build Coastguard Worker uhash_equalsScriptSet(const UElement key1, const UElement key2);
88*0e209d39SAndroid Build Coastguard Worker 
89*0e209d39SAndroid Build Coastguard Worker #endif // __SCRIPTSET_H_
90