1 /* 2 ******************************************************************************* 3 * 4 * Copyright (C) 2009-2010, International Business Machines 5 * Corporation and others. All Rights Reserved. 6 * 7 ******************************************************************************* 8 * file name: n2builder.h 9 * encoding: US-ASCII 10 * tab size: 8 (not used) 11 * indentation:4 12 * 13 * created on: 2009nov25 14 * created by: Markus W. Scherer 15 */ 16 17 #ifndef __N2BUILDER_H__ 18 #define __N2BUILDER_H__ 19 20 #include "unicode/utypes.h" 21 #include "unicode/std_string.h" 22 23 #if !U_HAVE_STD_STRING 24 // The gennorm2 implementation uses STL classes like string and vector. 25 #undef UCONFIG_NO_NORMALIZATION 26 #define UCONFIG_NO_NORMALIZATION 1 27 #endif 28 29 #if !UCONFIG_NO_NORMALIZATION 30 31 #include "unicode/errorcode.h" 32 #include "unicode/unistr.h" 33 #include "normalizer2impl.h" // for IX_COUNT 34 #include "toolutil.h" 35 #include "utrie2.h" 36 37 U_NAMESPACE_BEGIN 38 39 extern UBool beVerbose, haveCopyright; 40 41 struct Norm; 42 43 class BuilderReorderingBuffer; 44 class ExtraDataWriter; 45 46 class Normalizer2DataBuilder { 47 public: 48 Normalizer2DataBuilder(UErrorCode &errorCode); 49 ~Normalizer2DataBuilder(); 50 51 enum OverrideHandling { 52 OVERRIDE_NONE, 53 OVERRIDE_ANY, 54 OVERRIDE_PREVIOUS 55 }; 56 57 void setOverrideHandling(OverrideHandling oh); 58 59 enum Optimization { 60 OPTIMIZE_NORMAL, 61 OPTIMIZE_FAST 62 }; 63 64 void setOptimization(Optimization opt) { optimization=opt; } 65 66 void setCC(UChar32 c, uint8_t cc); 67 void setOneWayMapping(UChar32 c, const UnicodeString &m); 68 void setRoundTripMapping(UChar32 c, const UnicodeString &m); 69 void removeMapping(UChar32 c); 70 71 void setUnicodeVersion(const char *v); 72 73 void writeBinaryFile(const char *filename); 74 75 private: 76 friend class CompositionBuilder; 77 friend class Decomposer; 78 friend class ExtraDataWriter; 79 friend class Norm16Writer; 80 81 // No copy constructor nor assignment operator. 82 Normalizer2DataBuilder(const Normalizer2DataBuilder &other); 83 Normalizer2DataBuilder &operator=(const Normalizer2DataBuilder &other); 84 85 Norm *allocNorm(); 86 Norm *getNorm(UChar32 c); 87 Norm *createNorm(UChar32 c); 88 Norm *checkNormForMapping(Norm *p, UChar32 c); // check for permitted overrides 89 90 const Norm &getNormRef(UChar32 c) const; 91 uint8_t getCC(UChar32 c) const; 92 UBool combinesWithCCBetween(const Norm &norm, uint8_t lowCC, uint8_t highCC) const; 93 UChar32 combine(const Norm &norm, UChar32 trail) const; 94 95 void addComposition(UChar32 start, UChar32 end, uint32_t value); 96 UBool decompose(UChar32 start, UChar32 end, uint32_t value); 97 void reorder(Norm *p, BuilderReorderingBuffer &buffer); 98 UBool hasNoCompBoundaryAfter(BuilderReorderingBuffer &buffer); 99 void setHangulData(); 100 void writeMapping(UChar32 c, const Norm *p, UnicodeString &dataString); 101 void writeCompositions(UChar32 c, const Norm *p, UnicodeString &dataString); 102 void writeExtraData(UChar32 c, uint32_t value, ExtraDataWriter &writer); 103 int32_t getCenterNoNoDelta() { 104 return indexes[Normalizer2Impl::IX_MIN_MAYBE_YES]-Normalizer2Impl::MAX_DELTA-1; 105 } 106 void writeNorm16(UChar32 start, UChar32 end, uint32_t value); 107 void processData(); 108 109 UTrie2 *normTrie; 110 UToolMemory *normMem; 111 Norm *norms; 112 113 int32_t phase; 114 OverrideHandling overrideHandling; 115 116 Optimization optimization; 117 118 int32_t indexes[Normalizer2Impl::IX_COUNT]; 119 UTrie2 *norm16Trie; 120 UnicodeString extraData; 121 122 UVersionInfo unicodeVersion; 123 }; 124 125 U_NAMESPACE_END 126 127 #endif // #if !UCONFIG_NO_NORMALIZATION 128 129 #endif // __N2BUILDER_H__ 130