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