• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 *******************************************************************************
3 *
4 *   Copyright (C) 2003, International Business Machines
5 *   Corporation and others.  All Rights Reserved.
6 *
7 *******************************************************************************
8 *   file name:  genldml.h
9 */
10 #ifndef GENLDML_H
11 #define GENLDML_H
12 
13 #include "unicode/ures.h"
14 #include "unicode/format.h"
15 #include "unicode/unistr.h"
16 #include "unicode/resbund.h"
17 #include "unicode/ustdio.h"
18 #include "unicode/fmtable.h"
19 #include "unicode/ucol.h"
20 #include "unicode/smpdtfmt.h"
21 #include "unicode/ustring.h"
22 #include "unicode/msgfmt.h"
23 #include "unicode/fmtable.h"
24 #include "unicode/locid.h"
25 #include "unicode/rep.h"
26 #include "unicode/numfmt.h"
27 #include "unicode/decimfmt.h"
28 #include "unicode/dcfmtsym.h"
29 #include "unicode/ures.h"
30 #include "unicode/ucol.h"
31 #include "unicode/unum.h"
32 #include "unicode/udata.h"     /* ICU API for data handling.                 */
33 #include "unicode/uset.h"
34 #include "unicode/ucnv.h"
35 #include "uoptions.h"
36 #include "unicode/uchar.h"
37 //#include "ucol_tok.h"
38 
39 #include <stdio.h>
40 
41 class GenerateXML {
42 private:
43 	/*
44 	 *
45 	 *  "&		a	<<		befg	<<		c		<<		d		<<		d"
46 	 *   ^			^				^										^
47 	 *   start		prevCurrent		current 								end
48 	 */
49 	struct Token{
50 		UChar* start;
51 		UChar* end ;
52 		UChar* current;
53 		UChar* prevCurrent;
54 		UChar* chars;
55 		int32_t charsCapacity;
56 		int32_t charsLen;
57 
58 	};
59     UnicodeString mSettings;
60 
61 	/* Full path to the resource bundle eg: root.res */
62 	ResourceBundle mSourceBundle;
63 
64 	/*Bundle to retrieve the xml strings */
65 	ResourceBundle mStringsBundle;
66 
67 	/* output file stream handle */
68 	FILE* mFile;
69 
70 	/* error code */
71 	UErrorCode mError;
72 
73 	/* locale */
74 	Locale mLocale;
75 
76 	/* indenting string */
77 	UnicodeString indentOffset;
78 
79     const char* locName;
80     const char* path;
81     /* destination directory */
82     const char* destDir;
83 
84     /* default private constructor */
85 	GenerateXML();
86 
87 	/*overloaded utility function with 3 args for formatting the string*/
88 	UnicodeString formatString(UnicodeString& str, const Formattable* args, int32_t num,UnicodeString& result);
89 
90 	/*overloaded utility function with 2 args for formatting the string*/
91 	UnicodeString formatString(UnicodeString& str,UnicodeString& argument, UnicodeString& result);
92 
93 	/* get the file handle */
94 	FILE* getFileHandle(const char* path, const char* name);
95 
96 	/* print the unicode string */
97 	void printString( UnicodeString* uString, FILE* file);
98     void printString( UnicodeString* uString);
99 	/* chop the indent string*/
100 	void chopIndent();
101 	void chopIndent(UnicodeString& indent);
102     void addIndent(UnicodeString& indent);
103 	/**
104 	 * writeXMLVersionAndComments()
105 	 * Prints version and comments strings in the output xml file
106 	 * Creation date: (6/29/00 3:56:37 PM)
107 	 * @return void
108 	 * @param void
109 	 */
110 	void writeXMLVersionAndComments();
111 
112 	/**
113 	 * writeDocVersion()
114 	 * Prints document version and IBM copytright info strings in the output xml file
115 	 * Creation date: (6/29/00 3:56:37 PM)
116 	 * @return void
117 	 * @param void
118 	 */
119 	void writeVersion(UnicodeString& xmlString);
120 
121 	/**
122 	 * writeIdentity()
123 	 * Prints identity info strings in the output xml file
124 	 * <identity></identity> tags
125 	 * Creation date: (6/29/00 3:56:37 PM)
126 	 * @return void
127 	 * @param void
128 	 */
129 	void writeIdentity();
130 
131     void writeLocaleScript(UnicodeString& xmlString);
132 
133 	void writeScript(UnicodeString& xmlString);
134 
135 	void writeLanguage(UnicodeString& xmlString);
136 
137 	void writeCountryNames(UnicodeString& xmlString);
138 
139 	void writeVariantNames(UnicodeString& xmlString);
140 
141 	void writeKeywordNames(UnicodeString& xmlString);
142 
143 	void writeTypeNames(UnicodeString& xmlString);
144 
145 	void writeLayout();
146 
147 	void writeEncodings();
148 
149     void writeExemplarCharacters(UnicodeString& xmlString);
150 
151     void writeDelimiters();
152 
153 	void writeMeasurement();
154 
155 	void writeDisplayNames();
156 
157 	void writeCalendars(UnicodeString& xmlString);
158 
159 	void writeCalendar(ResourceBundle& calendar, UnicodeString& cal,UBool isDefault, UnicodeString& xmlString);
160 
161     void writeAMPMmarkers(ResourceBundle& calendar, UnicodeString& xmlString);
162 
163     void writeDateFormat(ResourceBundle& calendar, UnicodeString& xmlString);
164 
165     void writeDateTimeFormat(ResourceBundle& calendar, UnicodeString& xmlString);
166 
167     void writeDateTimeElements(ResourceBundle& calendar, UnicodeString& xmlString);
168 
169     void writeDayNames(ResourceBundle& calendar, UnicodeString& xmlString);
170 
171     void writeEra(ResourceBundle& calendar, UnicodeString& xmlString);
172 
173     void writeMonthNames(ResourceBundle& calendar,UnicodeString& xmlString);
174 
175     void writeTimeFormat(ResourceBundle& calendar, UnicodeString& xmlString);
176 
177 	void writeWeek(ResourceBundle& calendar, UnicodeString& xmlString);
178 
179 	void writeFormats(UnicodeString& xmlString);
180 
181 	void writeFormat(const char* style, const char* start, const char* end, const char* type,UnicodeString& pattern, UnicodeString& xmlString, UBool split=FALSE);
182 
183     void writeFormat(const char* elemName, const char* style, const char* start, const char* end, const char* type,UnicodeString& pattern, UnicodeString& xmlString, UBool split=FALSE);
184 
185 	void writeLocalePatternChars(UnicodeString& xmlString);
186 
187 	void writeNumberFormat();
188 
189 	void writeRuleBasedNumberFormat(UnicodeString& xmlString);
190 
191 	void writeNumberElements(UnicodeString& xmlString);
192 
193 	void writeNumberPatterns(UnicodeString& xmlString);
194 	void writeDates();
195 
196 	void writeCurrency(UnicodeString&);
197 
198 	void writeCurrencies(UnicodeString&);
199 
200 	void writeCollations();
201 
202 	void writeCollation(ResourceBundle& bundle, UnicodeString& xmlString,UnicodeString* collKey=NULL);
203 
204     void writeCollation(UnicodeString& src, UnicodeString &xmlString, uint32_t prevStrength, const char* keyName);
205 
206     void writeBase(UnicodeString& xmlString);
207 
208 	void writeTimeZoneNames(UnicodeString& xmlString);
209 
210 	void writeBoundary(UnicodeString& xmlString);
211 
212 	void closeFileHandle();
213 
214 	void closeXMLDocument();
215 
216 	void writeTransliteration();
217 
218 	void writeCharBrkRules(UnicodeString& xmlString);
219 
220 	void writeSentBrkRules(UnicodeString& xmlString);
221 
222 	void writeLineBrkRules(UnicodeString& xmlString);
223 
224 	void writeMisc();
225 
226 	void escape(UnicodeString& str);
227 
228     void writeSupplementalData();
229 
230     void writeCurrencyMeta(UnicodeString& xmlString, UResourceBundle* root, UErrorCode& error);
231 
232     void writeCurrencyMap(UnicodeString& xmlString, UResourceBundle* root, UErrorCode& error);
233 
234     void writePosixAdditions();
235     void writeMeasurement(UnicodeString& xmlString);
236     void writeCountryPost(UnicodeString& xmlString);
237     void writeCountryCar(UnicodeString& xmlString);
238     void writeCountryISBNNumber(UnicodeString& xmlString);
239     void writeLanguageLibraryUse(UnicodeString& xmlString);
240     void writePaperSize(UnicodeString& xmlString);
241     void getStringRes(const char* key,UnicodeString& xmlString,UnicodeString pattern);
242     void getStringRes(const char *key,ResourceBundle& bundle,UnicodeString& xmlString,UnicodeString pattern);
243 
244     void writePosixCompData();
245 
246     void writeMessages(ResourceBundle& bundle,UnicodeString& xmlString);
247 
248     void addressFormat(ResourceBundle& bundle,UnicodeString& xmlString);
249 
250     void nameFormat(ResourceBundle& bundle,UnicodeString& xmlString);
251 
252     void identity(ResourceBundle& bundle,UnicodeString& xmlString);
253 
254     void telephoneFormat(ResourceBundle& bundle,UnicodeString& xmlString);
255 
256 	void writeTable(const char* key, const char* resMain, const char* resElement, UnicodeString& xmlString);
257 
258     UnicodeString parseRules(UChar* rules, int32_t ruleLen, UnicodeString& ruleXML);
259 
260 	uint32_t parseRules(Token* src, UBool startOfRules);
261 
262     int32_t copyUnicodeStringToChars(const UnicodeString& str, char* buf,int32_t bufCapacity);
263 
264 	void writeSpecial();
265 
266 	int32_t fillOutputString(const UnicodeString &temp, UChar *dest, int32_t destCapacity) ;
267 
268 	void writeSettings(UnicodeString& src , UnicodeString& xmlString);
269 
270 	void writeReset(UnicodeString& src, UnicodeString& xmlString);
271 
272 	void growBuffer(UChar* src, int32_t len, int32_t size, int32_t requiredCapacity, UErrorCode* status);
273 
274     void writeUCARules(UnicodeString& sequence,UnicodeString& xmlString);
275     int32_t getSettingAndValue(UnicodeString& source, int32_t index, UnicodeString& setting, UnicodeString& value);
276 public:
277 
278 	/* constructor */
279 	GenerateXML(const char* path,const char* locName,const char* destDir, UErrorCode& error);
280 
281 	/* destructor */
282 	~GenerateXML();
283 
284 	void DoIt();
285 
286 };
287 
288 int32_t
289 my_fillOutputString(const UnicodeString &temp,
290                       UChar *dest,
291                       int32_t destCapacity,
292                       UErrorCode *status);
293 #endif