2 **********************************************************************
3 * Copyright (C) 2013, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
9 * created on: 2013 Jan 7
10 * created by: Andy Heninger
13 #ifndef __IDENTIFIER_INFO_H__
14 #define __IDENTIFIER_INFO_H__
16 #include "unicode/utypes.h"
18 #include "unicode/uniset.h"
19 #include "unicode/uspoof.h"
26 // TODO(andy): review consistency of reference vs pointer arguments to the funcions.
29 * This class analyzes a possible identifier for script and identifier status. Use it by calling setIdentifierProfile
30 * then setIdentifier. Available methods include:
32 * <li>call getScripts for the specific scripts in the identifier. The identifier contains at least one character in
34 * <li>call getAlternates to get cases where a character is not limited to a single script. For example, it could be
35 * either Katakana or Hiragana.
36 * <li>call getCommonAmongAlternates to find out if any scripts are common to all the alternates.
37 * <li>call getNumerics to get a representative character (with value zero) for each of the decimal number systems in
39 * <li>call getRestrictionLevel to see what the UTS36 restriction level is.
42 * This is a port from ICU4J of class com.ibm.icu.text.IdentifierInfo
44 class U_I18N_API IdentifierInfo : public UMemory {
48 * Create an identifier info object. Subsequently, call setIdentifier(), etc.
51 IdentifierInfo(UErrorCode &status);
56 virtual ~IdentifierInfo();
59 /* Disallow copying for now. Can be added if there's a need. */
60 IdentifierInfo(const IdentifierInfo &other);
65 * Set the identifier profile: the characters that are to be allowed in the identifier.
67 * @param identifierProfile the characters that are to be allowed in the identifier
71 IdentifierInfo &setIdentifierProfile(const UnicodeSet &identifierProfile);
74 * Get the identifier profile: the characters that are to be allowed in the identifier.
76 * @return The characters that are to be allowed in the identifier.
79 const UnicodeSet &getIdentifierProfile() const;
83 * Set an identifier to analyze. Afterwards, call methods like getScripts()
85 * @param identifier the identifier to analyze
86 * @param status Errorcode, set if errors occur.
90 IdentifierInfo &setIdentifier(const UnicodeString &identifier, UErrorCode &status);
94 * Get the identifier that was analyzed. The returned string is owned by the ICU library,
95 * and must not be deleted by the caller.
97 * @return the identifier that was analyzed.
100 const UnicodeString *getIdentifier() const;
104 * Get the scripts found in the identifiers.
106 * @return the set of explicit scripts.
109 const ScriptSet *getScripts() const;
112 * Get the set of alternate scripts found in the identifiers. That is, when a character can be in two scripts, then
113 * the set consisting of those scripts will be returned.
115 * @return a uhash, with each key being of type (ScriptSet *).
116 * This is a set, not a map, so the value stored in the uhash is not relevant.
117 * (It is, in fact, 1).
118 * Ownership of the uhash and its contents remains with the IndetifierInfo object,
119 * and remains valid until a new identifer is set or until the object is deleted.
122 const UHashtable *getAlternates() const;
125 * Get the representative characters (zeros) for the numerics found in the identifier.
127 * @return the set of explicit scripts.
130 const UnicodeSet *getNumerics() const;
133 * Find out which scripts are in common among the alternates.
135 * @return the set of scripts that are in common among the alternates.
138 const ScriptSet *getCommonAmongAlternates() const;
141 * Get the number of scripts appearing in the identifier.
142 * Note: Common and Inherited scripts are omitted from the count.
143 * Note: Result may be high when the identifier contains characters
144 * with alternate scripts. The distinction between
145 * 0, 1 and > 1 will remain valid, however.
146 * @return the number of scripts.
148 int32_t getScriptCount() const;
150 #if !UCONFIG_NO_NORMALIZATION
153 * Find the "tightest" restriction level that the identifier satisfies.
155 * @return the restriction level.
158 URestrictionLevel getRestrictionLevel(UErrorCode &status) const;
160 #endif /*!UCONFIG_NO_NORMALIZATION */
162 UnicodeString toString() const;
165 * Produce a readable string of alternates.
167 * @param alternates a UHashtable of UScriptSets.
168 * Keys only, no meaningful values in the UHash.
169 * @return display form
172 static UnicodeString &displayAlternates(UnicodeString &dest, const UHashtable *alternates, UErrorCode &status);
175 * Static memory cleanup function.
178 static UBool cleanup();
181 IdentifierInfo & clear();
182 UBool containsWithAlternates(const ScriptSet &container, const ScriptSet &containee) const;
184 UnicodeString *fIdentifier;
185 ScriptSet *fRequiredScripts;
186 UHashtable *fScriptSetSet;
187 ScriptSet *fCommonAmongAlternates;
188 UnicodeSet *fNumerics;
189 UnicodeSet *fIdentifierProfile;
191 static UnicodeSet *ASCII;
192 static ScriptSet *JAPANESE;
193 static ScriptSet *CHINESE;
194 static ScriptSet *KOREAN;
195 static ScriptSet *CONFUSABLE_WITH_LATIN;
203 #endif // __IDENTIFIER_INFO_H__