extradata.h (2438B)
1 // © 2017 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 4 // extradata.h 5 // created: 2017jun04 Markus W. Scherer 6 // (pulled out of n2builder.cpp) 7 8 // Write mappings and compositions in compact form for Normalizer2 "extra data", 9 // the data that does not fit into the trie itself. 10 11 #ifndef __EXTRADATA_H__ 12 #define __EXTRADATA_H__ 13 14 #include "unicode/utypes.h" 15 16 #if !UCONFIG_NO_NORMALIZATION 17 18 #include "unicode/errorcode.h" 19 #include "unicode/unistr.h" 20 #include "unicode/utf16.h" 21 #include "hash.h" 22 #include "norms.h" 23 #include "toolutil.h" 24 #include "utrie2.h" 25 #include "uvectr32.h" 26 27 U_NAMESPACE_BEGIN 28 29 class ExtraData : public Norms::Enumerator { 30 public: 31 ExtraData(Norms &n, UBool fast); 32 33 void rangeHandler(UChar32 start, UChar32 end, Norm &norm) override; 34 35 UnicodeString maybeNoMappingsOnly; 36 UnicodeString maybeNoMappingsAndCompositions; 37 UnicodeString maybeYesCompositions; 38 UnicodeString yesYesCompositions; 39 UnicodeString yesNoMappingsAndCompositions; 40 UnicodeString yesNoMappingsOnly; 41 UnicodeString noNoMappingsCompYes; 42 UnicodeString noNoMappingsCompBoundaryBefore; 43 UnicodeString noNoMappingsCompNoMaybeCC; 44 UnicodeString noNoMappingsEmpty; 45 46 private: 47 /** 48 * Requires norm.hasMapping(). 49 * Returns the offset of the "first unit" from the beginning of the extraData for c, 50 * not from the beginning of the dataString. 51 * That is the same as the length of the optional data 52 * for the raw mapping and the ccc/lccc word. 53 */ 54 int32_t writeMapping(UChar32 c, const Norm &norm, UnicodeString &dataString); 55 /** Returns the full offset into the dataString of the "first unit" for c. */ 56 int32_t writeNoNoMapping(UChar32 c, const Norm &norm, 57 UnicodeString &dataString, Hashtable &previousMappings); 58 UBool setNoNoDelta(UChar32 c, Norm &norm) const; 59 /** Requires norm.combinesFwd(). */ 60 void writeCompositions(UChar32 c, const Norm &norm, UnicodeString &dataString); 61 void writeExtraData(UChar32 c, Norm &norm); 62 63 UBool optimizeFast; 64 Hashtable previousNoNoMappingsCompYes; // If constructed in runtime code, pass in UErrorCode. 65 Hashtable previousNoNoMappingsCompBoundaryBefore; 66 Hashtable previousNoNoMappingsCompNoMaybeCC; 67 Hashtable previousNoNoMappingsEmpty; 68 }; 69 70 U_NAMESPACE_END 71 72 #endif // #if !UCONFIG_NO_NORMALIZATION 73 74 #endif // __EXTRADATA_H__