• 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.cpp
9 */
10 
11 #include <time.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include "genldml.h"
15 #include <stdlib.h>
16 #include "unicode/ustring.h"
17 
18 #define MAX_DIGITS 10
19 #ifndef GENLDML_NOSETAPPDATA
20 /*
21  *  Resource Data Reference.  The data is packaged as a dll (or .so or
22  *           whatever, depending on the platform) that exports a data
23  *           symbol.  The application (that's us) references that symbol,
24  *           here, and will pass the data address to ICU, which will then
25  *           be able to fetch resources from the data.
26  */
27 
28 extern "C" {
29 	extern const void U_IMPORT *genldml_resources_dat;
30 }
31 
32 #endif
33 
34 #define XML_END_SLASH "/"
35 enum
36 {
37     HELP1,
38     HELP2,
39     SOURCEDIR,
40 	DESTDIR,
41 	PACKAGE_NAME,
42     IGNORE_COLLATION,
43     BASE,
44     BASE_TYPE,
45     IGNORE_SPECIALS,
46     IGNORE_LAYOUT,
47     DRAFT,
48     ONLY_SPECIALS
49 };
50 
51 
52 UOption options[]={
53                       UOPTION_HELP_H,
54                       UOPTION_HELP_QUESTION_MARK,
55                       UOPTION_SOURCEDIR,
56 					  UOPTION_DESTDIR,
57 					  UOPTION_DEF("package", 'p', UOPT_REQUIRES_ARG),
58                       UOPTION_DEF("ignore-collation", 'i', UOPT_NO_ARG),
59                       UOPTION_DEF("base", 'b', UOPT_REQUIRES_ARG),
60                       UOPTION_DEF("base-type", 't', UOPT_REQUIRES_ARG),
61                       UOPTION_DEF("ignore-specials", 'c', UOPT_NO_ARG),
62                       UOPTION_DEF("ignore-layout", 'l', UOPT_NO_ARG),
63                       UOPTION_DEF("draft", 'r', UOPT_NO_ARG),
64                       UOPTION_DEF("only-specials", 'g', UOPT_NO_ARG)
65                    };
66 
67 const char* usageString =
68                 "Usage: genldml [OPTIONS] [FILES]\n"
69                 "\tConvert the input res file to XML\n"
70                 "Options:\n"
71                 "\t-h or -? or --help       this usage text\n"
72                 "\t-s or --sourcedir        source directory for files followed by path\n"
73                 "\t                         followed by path\n"
74                 "\t-d or --destdir          dest directory for files followed by path\n"
75                 "\t                         followed by path\n"
76 				"\t-p or --package			name of the package that is prepended to the resource bundles\n"
77 				"\t                         defaults to ICU's data\n"
78                 "\t-i or --ignore-collation Ignores collation generation\n"
79                 "\t-b or --base             the base tailoring for collation if any\n"
80                 "\t-t or --base-type        the type of base tailoring for collation in the base. Defaults to standard\n"
81                 "\t-c or --ignore-specials  Ignores specials in collations\n"
82                 "\t-l or --ignore-layout    Ignores layout element\n"
83                 "\t-r or --draft            The LDML file being generated will marked as draft\n"
84                 "\t-g or --only-specials    Produces on special elements\n"
85                ;
86 
87 UBool ignoreCollation = FALSE;
88 const char* baseCollation = NULL;
89 const char* baseType = NULL;
90 UBool ignoreSpecials = FALSE;
91 UBool ignoreLayout = FALSE;
92 UBool isDraft = FALSE;
93 UBool onlySpecials = FALSE;
94 
main(int32_t argc,const char * argv[])95 int main (int32_t argc, const char* argv[]) {
96 	const char* srcDir =NULL;
97 	const char* destDir = NULL;
98 	const char* packageName=NULL;
99 	UErrorCode err= U_ZERO_ERROR;
100 	char* path= NULL;
101 	//initialize the argument list
102     U_MAIN_INIT_ARGS(argc, argv);
103     //parse the arguments
104     int32_t _remainingArgc = u_parseArgs(argc, (char**)argv, (int32_t)(sizeof(options)/sizeof(options[0])), options);
105 
106     // Now setup the arguments
107     if(argc==1 || options[HELP1].doesOccur || options[HELP2].doesOccur) {
108         fprintf(stderr,usageString);
109         return -1;
110     }
111 
112     if(options[SOURCEDIR].doesOccur) {
113         srcDir = options[SOURCEDIR].value;
114     }
115     if(options[DESTDIR].doesOccur) {
116         destDir = options[DESTDIR].value;
117     }
118 	if(options[PACKAGE_NAME].doesOccur) {
119         packageName = options[PACKAGE_NAME].value;
120     }
121     if(options[IGNORE_COLLATION].doesOccur){
122         ignoreCollation = TRUE;
123     }
124     if(options[BASE].doesOccur){
125         baseCollation = options[BASE].value;
126     }
127     if(options[BASE_TYPE].doesOccur){
128         baseCollation = options[BASE_TYPE].value;
129     }
130     if(options[IGNORE_SPECIALS].doesOccur){
131         ignoreSpecials = TRUE;
132     }
133     if(options[IGNORE_LAYOUT].doesOccur){
134         ignoreLayout = TRUE;
135     }
136     if(options[DRAFT].doesOccur){
137         isDraft = TRUE;
138     }
139     if(options[ONLY_SPECIALS].doesOccur){
140         onlySpecials = TRUE;
141     }
142 #ifndef GENLDML_NOSETAPPDATA
143     /* Tell ICU where our resource data is located in memory.
144      *   The data lives in the genldml_resources dll, and we just
145      *   pass the address of an exported symbol from that library
146      *   to ICU.
147      */
148     udata_setAppData("genldml_resources", &genldml_resources_dat, &err);
149     if (U_FAILURE(err)) {
150         fprintf(stderr, "%s: ures_open failed with error \"%s\"\n", argv[0], u_errorName(err));
151         exit(-1);
152     }
153 #endif
154 
155 	if(srcDir!=NULL){
156 		path = (char*) malloc(strlen(srcDir)+((packageName!=NULL) ? strlen(packageName) : 0 )+2);
157 		strcpy(path,srcDir);
158 		if(path[(strlen(srcDir)-1)]!=U_FILE_SEP_CHAR){
159 			strcat(path,U_FILE_SEP_STRING);
160 		}
161 		if(packageName!=NULL){
162 			strcat(path,packageName);
163 		}
164 	}
165     if(_remainingArgc<0) {
166         fprintf(stderr,usageString);
167         return -1;
168     }
169 	for(int i=1; i<_remainingArgc; i++){
170 
171 		GenerateXML gen(path,argv[i],destDir,err);
172 		if(U_FAILURE(err)){
173 			fprintf(stderr,"Reading of resource file failed. Error: %s\n",u_errorName(err));
174 			return -1;
175 		}
176 		gen.DoIt();
177 
178 	}
179 	free(path);
180 	return 0;
181 }
182 
183 static int32_t
itou(UChar * buffer,uint32_t i,uint32_t radix,int32_t pad)184 itou (UChar * buffer, uint32_t i, uint32_t radix, int32_t pad)
185 {
186     int32_t length = 0;
187     int32_t num = 0;
188     int digit;
189     int32_t j;
190     UChar temp;
191 
192     do{
193         digit = (int)(i % radix);
194         buffer[length++]=(UChar)(digit<=9?(0x0030+digit):(0x0030+digit+7));
195         i=i/radix;
196     } while(i);
197 
198     while (length < pad){
199         buffer[length++] = (UChar) 0x0030;/*zero padding */
200     }
201     /* null terminate the buffer */
202     if(length<MAX_DIGITS){
203         buffer[length] = (UChar) 0x0000;
204     }
205     num= (pad>=length) ? pad :length;
206 
207     /* Reverses the string */
208     for (j = 0; j < (num / 2); j++){
209         temp = buffer[(length-1) - j];
210         buffer[(length-1) - j] = buffer[j];
211         buffer[j] = temp;
212     }
213     return length;
214 }
215 
216 
GenerateXML(const char * path,const char * locName,const char * destDir,UErrorCode & err)217 GenerateXML::GenerateXML(const char* path, const char* locName,const char* destDir, UErrorCode& err)
218 						 :  mSourceBundle(path, locName,err), mStringsBundle("genldml_resources","root", err),mError(err){
219     mFile=NULL;
220     if(U_SUCCESS(err)){
221 
222 	    mLocale=Locale(locName);
223 	    mFile=getFileHandle(destDir,locName);
224         GenerateXML::locName = locName;
225         GenerateXML::path = path;
226         GenerateXML::destDir = destDir;
227 //		GenerateXML::packageName = packageName;
228 	    if(mFile==NULL){
229             closeFileHandle();
230 		    exit(U_FILE_ACCESS_ERROR);
231         }
232 
233 	    indentOffset="";
234     }
235 
236 }
~GenerateXML()237 GenerateXML::~GenerateXML()
238 {
239 
240     closeFileHandle();
241 
242 }
243 
closeFileHandle()244 void GenerateXML::closeFileHandle(){
245     if(mFile){
246 	    fclose(mFile);
247     }
248 }
DoIt()249 void GenerateXML::DoIt(){
250     writeXMLVersionAndComments();
251     writeIdentity();
252     if(onlySpecials==FALSE){
253 	    writeDisplayNames();
254 	    writeLayout();
255     }
256 	// WARNING: do not change the order
257     // the generated XML will not validate!!!
258     writeEncodings();
259 
260     if(onlySpecials==FALSE){
261 	    writeDelimiters();
262 	    writeMeasurement();
263 	    writeDates();
264 	    writeNumberFormat();
265     }
266     if(ignoreCollation == FALSE){
267 	    writeCollations();
268     }
269     writeSpecial();
270     //if(strcmp(locName, "root")==0){
271         writeSupplementalData();
272     //}
273 /*
274 	writeTransliteration();
275 	writeBoundary();
276 //	writeMisc();
277     writePosixAdditions();
278     writePosixCompData();
279 */
280  	closeXMLDocument();
281 }
chopIndent()282 void GenerateXML::chopIndent(){
283 
284 	indentOffset.remove((indentOffset.length()-1),1);
285 }
copyUnicodeStringToChars(const UnicodeString & str,char * buf,int32_t bufCapacity)286 int32_t GenerateXML::copyUnicodeStringToChars(const UnicodeString& str,
287                                  char* buf,
288                                  int32_t bufCapacity) {
289     int32_t len = str.length();
290     if (buf != 0) {
291         // copy whatever will fit into buf
292         int32_t len2 =  (len<(bufCapacity - 1))? len : (bufCapacity-1);
293         str.extract(0, len2, buf, "");
294         buf[len2] = 0; // zero-terminate
295     }
296     return len; // return actual length
297 }
closeXMLDocument()298 void GenerateXML::closeXMLDocument(){
299 	chopIndent();
300 	Formattable args[] = {UnicodeString(XML_END_SLASH), ""};
301 	UnicodeString xmlString;
302 	formatString(mStringsBundle.getStringEx("localeData",mError),args,2,xmlString);
303 	printString(&xmlString);
304 }
formatString(UnicodeString & str,UnicodeString & argument,UnicodeString & result)305 UnicodeString GenerateXML::formatString(UnicodeString& str,UnicodeString& argument,UnicodeString& result){
306 	Formattable args[] ={ argument};
307 	MessageFormat format(str,mError);
308 	FieldPosition fpos=0;
309 	result.remove();
310 	format.format(args,1, result,fpos,mError);
311 //	if(U_FAILURE(mError)) {
312 //		return UnicodeString("Illegal argument");
313 //	}
314 
315 	return result;
316 }
317 
318 
formatString(UnicodeString & str,const Formattable * args,int32_t num,UnicodeString & result)319 UnicodeString GenerateXML::formatString(UnicodeString& str,const Formattable* args,int32_t num,UnicodeString& result){
320 	FieldPosition fpos=0;
321 	MessageFormat format(str,mError);
322 	result.remove();
323 	format.format(args,num, result,fpos,mError);
324 //	if(U_FAILURE(mError)) {
325 //		return UnicodeString("Illegal argument");
326 //	}
327 	return result;
328 }
329 
330 
getFileHandle(const char * path,const char * name)331 FILE* GenerateXML::getFileHandle(const char* path, const char* name)
332 {
333 
334 	FILE* file;
335 	char fileName[256];
336     if(!path){
337         path=".";
338     }
339     if(U_FAILURE(mError) ) {
340         return NULL;
341     }
342 	strcpy(fileName,path);
343     if(path[ strlen(path)-1] !='\\'){
344          strcat(fileName,"\\");
345     }
346 	 strcat(fileName, name );
347      strcat(fileName, ".xml");
348 
349     /* open the output file */
350     file=fopen(fileName,"w");
351 
352 
353     if(file==NULL) {
354 
355         mError=U_FILE_ACCESS_ERROR;
356 		printf("Could not open file %s for writing.\n",fileName);
357 		exit(U_FILE_ACCESS_ERROR);
358         return NULL;
359     }else{
360         printf("opened file %s in directory %s\n", fileName, path);
361     }
362 
363 	return file;
364 }
365 
366 
367 int32_t
fillOutputString(const UnicodeString & temp,UChar * dest,int32_t destCapacity)368 GenerateXML::fillOutputString(const UnicodeString &temp,
369                       UChar *dest,
370                       int32_t destCapacity) {
371   int32_t length = temp.length();
372 
373   if (destCapacity > 0) {
374     // copy the contents; extract() will check if it needs to copy anything at all
375     temp.extract(0, destCapacity, dest, 0);
376 
377     // zero-terminate the dest buffer if possible
378     if (length < destCapacity) {
379       dest[length] = 0;
380     }
381   }
382 
383   // set the error code according to the necessary buffer length
384   if (length > destCapacity && U_SUCCESS(mError)) {
385     mError = U_BUFFER_OVERFLOW_ERROR;
386   }
387 
388   // return the full string length
389   return length;
390 }
printString(UnicodeString * uString)391 void GenerateXML::printString(UnicodeString* uString){
392     printString(uString,mFile);
393 }
printString(UnicodeString * uString,FILE * file)394 void GenerateXML::printString(UnicodeString* uString, FILE* file){
395 
396 	//UChar result[256];
397 	char *dest = NULL;
398 	int32_t destLen = 0;
399 	int32_t destCap =0;
400 	const UChar* src = uString->getBuffer();
401     int32_t srcLen=uString->length();
402     if(U_FAILURE(mError)){
403        fprintf(stderr,"Error on entering the printString fucntion. Error: %s. Returning.", u_errorName(mError));
404     }
405 	u_strToUTF8(dest,destCap, &destLen,src,srcLen,&mError);
406 	if(mError == U_BUFFER_OVERFLOW_ERROR){
407 			destCap = destLen+2;
408 			dest = (char*) malloc(destCap);
409 			mError = U_ZERO_ERROR;
410 			dest = u_strToUTF8(dest,destCap, &destLen,src,srcLen,&mError);
411 			fwrite(dest,destLen,sizeof(char),file);
412 	}
413 
414 	uString->releaseBuffer();
415 	free(dest);
416 	if(U_FAILURE(mError)){
417 		fprintf(stderr,"Conversion of string to UTF-8 failed with error: %s\n",u_errorName(mError));
418 		exit(mError);
419 	}
420 }
421 
writeXMLVersionAndComments()422 void GenerateXML::writeXMLVersionAndComments(){
423 
424 	UnicodeString xmlString;
425 	if(U_FAILURE(mError)) {
426         return;
427 	}
428 	UnicodeString temp;
429     if(ignoreSpecials==FALSE){
430         temp = mStringsBundle.getStringEx("declaration",mError);
431     }else{
432         temp = mStringsBundle.getStringEx("declarationNoSpecials",mError);
433     }
434     xmlString.append(temp);
435     Formattable arguments[] = {"", (isDraft==TRUE)? " draft=\"true\"" : ""};
436 	UnicodeString tempStr;
437 	xmlString.append(formatString(mStringsBundle.getStringEx("localeData",mError),arguments,2,tempStr));
438 	printString(&xmlString);
439     mError=U_ZERO_ERROR;
440 }
441 
writeVersion(UnicodeString & xmlString)442 void GenerateXML::writeVersion(UnicodeString& xmlString){
443 	UnicodeString tempStr;
444 	UnicodeString version;
445 	if(U_FAILURE(mError)) {
446         return;
447 	}
448 	version=mSourceBundle.getStringEx("Version",mError);
449 	// if version is not available provide a default version.
450     if( mError == U_USING_DEFAULT_WARNING ||
451 		mError == U_USING_FALLBACK_WARNING ||
452 		mError == U_MISSING_RESOURCE_ERROR){
453         version="1.0";
454         mError = U_ZERO_ERROR;
455     }
456 	Formattable args[] = {indentOffset,""};
457 	UnicodeString result;
458 	if(!version.isEmpty()){
459 		args[0]=indentOffset;
460 		args[1]=version;
461         //TODO: remove this
462         //args[1] = "1.0-alpha";
463        	xmlString.append(formatString(mStringsBundle.getStringEx("version",mError),args,2,result));
464 
465 	}
466 	args[0]=indentOffset;
467 	args[1]= UnicodeString(XML_END_SLASH);
468 	args[2]="";
469 	xmlString.append(formatString(mStringsBundle.getStringEx("versioning",mError), args,3,result));
470 	//printString(&xmlString);
471     mError=U_ZERO_ERROR;
472 
473 }
474 
writeIdentity()475 void GenerateXML::writeIdentity(){
476 	UnicodeString xmlString, tempStr,tempStr1,tempStr2;
477 	indentOffset.append("\t");
478 	Formattable args[]={indentOffset,"",""};
479 
480 	formatString(mStringsBundle.getStringEx("identity",mError),args,2,xmlString);
481 
482 	indentOffset.append("\t");
483 	//version
484 	writeVersion(xmlString);
485 	//genrationDate
486 	SimpleDateFormat format(UnicodeString("yyyy-MM-dd"), mError);
487 	format.format(Calendar::getNow(),tempStr);
488 	args[0]=indentOffset;
489     args[1]=tempStr;
490 	tempStr.remove();
491 
492 
493     xmlString.append(formatString(mStringsBundle.getStringEx("generationDate",mError),args,2,tempStr));
494 
495 	tempStr1=mLocale.getISO3Language() ;
496 	tempStr2=mLocale.getLanguage();
497 
498 	if(! tempStr2.isEmpty()){
499         //if(tempStr2 == "root"){
500         //    tempStr2 ="";
501         //}
502 		Formattable args1[] = {indentOffset, tempStr2,""};
503 		UnicodeString t;
504 		xmlString.append(formatString(mStringsBundle.getStringEx("languageElem",mError),args1,3,t));
505 	}
506 	tempStr1.remove();
507 	tempStr2.remove();
508 
509     mError = U_ZERO_ERROR;
510 
511     tempStr.remove();
512     tempStr = mLocale.getScript();
513 	if(!tempStr.isEmpty() && tempStr!="t"){
514 		Formattable args1[] = {indentOffset, tempStr};
515 		UnicodeString t;
516 		xmlString.append(formatString(mStringsBundle.getStringEx("scriptElem",mError),args1,2,t));
517 	}
518 
519     mError = U_ZERO_ERROR;
520 
521 	tempStr1=mLocale.getCountry();
522 	tempStr2=mLocale.getISO3Country();
523 
524 	if(!(tempStr1.isEmpty() && tempStr2.isEmpty())){
525 		Formattable args1[] = {indentOffset,tempStr1,tempStr2};
526 		UnicodeString t;
527 		xmlString.append(formatString(mStringsBundle.getStringEx("territoryElem",mError),args1,2,t));
528 	}
529 	if(mError==U_MISSING_RESOURCE_ERROR){
530 		mError=U_ZERO_ERROR;
531 	}
532 
533     tempStr.remove();
534 	tempStr=mLocale.getVariant();
535 	if(!tempStr.isEmpty() && tempStr!="t"){
536 		Formattable args1[] = {indentOffset, tempStr};
537 		UnicodeString t;
538 		xmlString.append(formatString(mStringsBundle.getStringEx("variantElem",mError),args1,2,t));
539 	}
540 
541 	ResourceBundle tb  = mSourceBundle.get("LocaleID",mError);
542     UResType type = tb.getType();
543 	chopIndent();
544 	args[0]=indentOffset;
545 	args[1]=	(UnicodeString(XML_END_SLASH));
546 	args[2]= "";
547     mError =U_ZERO_ERROR;
548 	UnicodeString t;
549 	xmlString.append(formatString(mStringsBundle.getStringEx("identity",mError),args,2,t));
550 	printString(&xmlString);
551 }
552 
writeDisplayNames()553 void GenerateXML::writeDisplayNames(){
554 	UnicodeString xmlString;
555 	UBool print = FALSE;
556 	if(U_FAILURE(mError)) {
557 		return;
558 	}
559 	Formattable args[]={indentOffset,"",""};
560 	UnicodeString t;
561 	xmlString= formatString(mStringsBundle.getStringEx("localeDisplayNames",mError),args,3,t);
562 	UnicodeString tempStr;
563 	indentOffset.append("\t");
564 
565 
566 	writeLanguage(tempStr);
567 	if(!tempStr.isEmpty()){
568 		xmlString.append(tempStr);
569 		print = TRUE;
570 	}
571 
572 	writeScript(tempStr);
573 	if(!tempStr.isEmpty()){
574 		xmlString.append(tempStr);
575 		print = TRUE;
576 	}
577 
578 	writeCountryNames(tempStr);
579 	if(!tempStr.isEmpty()){
580 		xmlString.append(tempStr);
581 		print = TRUE;
582 	}
583 
584 	writeVariantNames(tempStr);
585 	if(!tempStr.isEmpty()){
586 		xmlString.append(tempStr);
587 		print = TRUE;
588 	}
589 	writeKeywordNames(tempStr);
590 	if(!tempStr.isEmpty()){
591 		xmlString.append(tempStr);
592 		print = TRUE;
593 	}
594 	writeTypeNames(tempStr);
595 	if(!tempStr.isEmpty()){
596 		xmlString.append(tempStr);
597 		print = TRUE;
598 	}
599 	chopIndent();
600 
601 	Formattable args1[]={indentOffset,(UnicodeString(XML_END_SLASH)),""};
602 	xmlString.append(formatString(mStringsBundle.getStringEx("localeDisplayNames",mError) ,args1,3,t));
603 	if(print)  printString(&xmlString);
604 }
605 
writeTable(const char * key,const char * resMain,const char * resElement,UnicodeString & xmlString)606 void GenerateXML::writeTable(const char* key, const char* resMain, const char* resElement, UnicodeString& xmlString){
607 
608 	if(U_FAILURE(mError)) {
609 		return;
610 	}
611 	Formattable args[]={indentOffset,"",""};
612 	UnicodeString t;
613 	xmlString= formatString(UnicodeString(mStringsBundle.getStringEx(resMain,mError)),args,3,t);
614 
615     ResourceBundle dBundle=mSourceBundle.get(key,mError);
616 
617     if( U_SUCCESS(mError)  &&
618         mError != U_USING_FALLBACK_WARNING &&
619         mError != U_USING_DEFAULT_WARNING){
620 		UnicodeString fallbackName = dBundle.getStringEx("Fallback",mError);
621 		if(U_SUCCESS(mError) && fallbackName.length()>0){
622 			// we know that we are processing ICU bundles
623 			char fbName[100]={0};
624 			int32_t len = fallbackName.extract(0,fallbackName.length(),fbName, 100);
625 			fbName[len]=0;//null terminate the array
626 			ResourceBundle rootBundle(NULL, "root",mError);
627 			ResourceBundle fallbackBundle(NULL, fbName, mError);
628 			ResourceBundle rootDelta = rootBundle.get(key, mError);
629             ResourceBundle fallbackDelta = fallbackBundle.get(key, mError);
630 			indentOffset.append("\t");
631 			while(rootDelta.hasNext()){
632 				ResourceBundle delta1 = rootDelta.getNext(mError);
633 				const char* mykey = delta1.getKey();
634 				UnicodeString string = dBundle.getStringEx(mykey, mError);
635                 if(strcmp(mykey, "Fallback") == 0){
636                     continue;
637                 }
638 				if(fallbackName.length() > 0 &&
639                     (mError == U_MISSING_RESOURCE_ERROR)){
640 					// explicit fallback is set
641                     mError=U_ZERO_ERROR;
642 					string = fallbackDelta.getStringEx(mykey, mError);
643 				}else if(string.length()==0){
644 					string = rootDelta.getStringEx(mykey, mError);
645 				}
646 				Formattable args1[]={indentOffset,mykey,string};
647 				xmlString.append(formatString(mStringsBundle.getStringEx(resElement,mError),args1,3,t));
648 				mError=U_ZERO_ERROR;
649 			}
650 			chopIndent();
651 			Formattable args1[]={indentOffset,(UnicodeString(XML_END_SLASH)),""};
652 			xmlString.append(formatString(mStringsBundle.getStringEx(resMain,mError) ,args1,3,t));
653 			return;
654 
655 		}else{
656 			mError = U_ZERO_ERROR;
657 			indentOffset.append("\t");
658 			while(dBundle.hasNext()){
659 				ResourceBundle dBundle1 = dBundle.getNext(mError);
660 				const char* mykey=dBundle1.getKey();
661                 if(strcmp(mykey, "Fallback")==0){
662                     continue;
663                 }
664 				UnicodeString string = dBundle.getStringEx(mykey,mError);
665 
666 				Formattable args1[]={indentOffset,mykey,string};
667 				xmlString.append(formatString(mStringsBundle.getStringEx(resElement,mError),args1,3,t));
668 				mError=U_ZERO_ERROR;
669 			}
670 			chopIndent();
671 			Formattable args1[]={indentOffset,(UnicodeString(XML_END_SLASH)),""};
672 			xmlString.append(formatString(mStringsBundle.getStringEx(resMain,mError) ,args1,3,t));
673 			return;
674 		}
675     }
676 
677 	mError=U_ZERO_ERROR;
678 	xmlString.remove();
679 }
680 
writeLocaleScript(UnicodeString & xmlString)681 void GenerateXML::writeLocaleScript(UnicodeString& xmlString){
682     if(ignoreSpecials == FALSE){
683         ResourceBundle scripts= mSourceBundle.get("LocaleScript",mError);
684 	    UnicodeString t;
685 
686 	    if( mError!=U_USING_DEFAULT_WARNING &&
687 		    mError!=U_USING_FALLBACK_WARNING &&
688 		    U_SUCCESS(mError)){
689 
690 	        Formattable args[]={indentOffset,mStringsBundle.getStringEx("xmlns_icu",mError),"",""};
691 	        UnicodeString t;
692 	        xmlString.append(formatString(mStringsBundle.getStringEx( "special",mError),args,4,t));
693 	        indentOffset.append("\t");
694 
695             args[0]=indentOffset;
696             args[1]="";
697 		    xmlString.append(formatString(mStringsBundle.getStringEx("icu_scripts",mError),args,2,t));
698 		    indentOffset.append("\t");
699             for(int i=0;scripts.hasNext();i++){
700                 char c[10]={0};
701 			    itoa(i+1,c,10);
702 			    args[0] = indentOffset;
703 			    args[1] = UnicodeString(c);
704 			    args[2] = scripts.getNextString(mError);
705 			    xmlString.append(formatString(mStringsBundle.getStringEx("icu_script",mError),args,3,t));
706 		    }
707 		    chopIndent();
708 		    args[0] = indentOffset;
709 		    args[1] = UnicodeString(XML_END_SLASH);
710 		    xmlString.append(formatString(mStringsBundle.getStringEx("icu_scripts",mError),args,2,t));
711 
712             chopIndent();
713 		    args[0] = indentOffset;
714 		    args[1] = UnicodeString(XML_END_SLASH);
715 		    xmlString.append(formatString(mStringsBundle.getStringEx("specialEnd",mError),args,2,t));
716 
717 		    mError=U_ZERO_ERROR;
718 		    return;
719 	    }
720 	    xmlString.remove();
721 	    mError= U_ZERO_ERROR;
722     }
723 
724 }
725 
writeScript(UnicodeString & xmlString)726 void GenerateXML::writeScript(UnicodeString& xmlString){
727 
728 	writeTable("Scripts","scripts","script",xmlString);
729 }
730 
writeLanguage(UnicodeString & xmlString)731 void GenerateXML::writeLanguage(UnicodeString& xmlString){
732 
733 	writeTable("Languages","languages","language",xmlString);
734 }
735 
736 
737 
writeCountryNames(UnicodeString & xmlString)738 void GenerateXML::writeCountryNames(UnicodeString& xmlString){
739 
740 	writeTable("Countries","territories","territory",xmlString);
741 }
742 
743 
writeVariantNames(UnicodeString & xmlString)744 void GenerateXML::writeVariantNames(UnicodeString& xmlString){
745 
746     writeTable("Variants","variants","variant",xmlString);
747 }
748 
writeKeywordNames(UnicodeString & xmlString)749 void GenerateXML::writeKeywordNames(UnicodeString& xmlString){
750     writeTable("Keys","keys","key",xmlString);
751 }
752 
writeTypeNames(UnicodeString & xmlString)753 void GenerateXML::writeTypeNames(UnicodeString& xmlString){
754 
755 	UnicodeString tempStr;
756 	Formattable args[] = { indentOffset, "","",""};
757     formatString(mStringsBundle.getStringEx("types",mError),args,2,xmlString);
758     ResourceBundle dBundle=mSourceBundle.get("Types",mError);
759 	UnicodeString t;
760 
761     if( U_SUCCESS(mError)  &&
762         mError != U_USING_FALLBACK_WARNING &&
763         mError != U_USING_DEFAULT_WARNING){
764 
765 		mError = U_ZERO_ERROR;
766 		indentOffset.append("\t");
767 		while(dBundle.hasNext()){
768 			ResourceBundle dBundle1 = dBundle.getNext(mError);
769 			const char* key=dBundle1.getKey();
770             if(strcmp(key, "Fallback")==0){
771                 continue;
772             }
773 			ResourceBundle dBundle2 = dBundle.get(key,mError);
774             while(dBundle2.hasNext()){
775                 ResourceBundle dBundle3 = dBundle2.getNext(mError);
776                 const char* type = dBundle3.getKey();
777                 if(strcmp(type, "Fallback")==0){
778                     continue;
779                 }
780                 UnicodeString value = dBundle3.getString(mError);
781 			    Formattable args1[]={indentOffset,type, key, value};
782 
783 			    xmlString.append(formatString(mStringsBundle.getStringEx("type",mError),args1,4,t));
784             }
785 			mError=U_ZERO_ERROR;
786 		}
787 		chopIndent();
788 		Formattable args1[]={indentOffset,(UnicodeString(XML_END_SLASH)),""};
789 		xmlString.append(formatString(mStringsBundle.getStringEx("types",mError) ,args1,3,t));
790 		return;
791 
792 	}
793 	xmlString.append(tempStr);
794 	args[0] = indentOffset;
795 	args[1] = "/";
796 	xmlString.append(formatString(mStringsBundle.getStringEx("types",mError),args,2,t));
797 	if(tempStr.isEmpty()){
798 		xmlString.remove();
799 	}
800     mError =U_ZERO_ERROR;
801 }
802 
writeLayout()803 void GenerateXML::writeLayout(){
804     if(ignoreLayout == FALSE){
805 	    UnicodeString xmlString;
806 	    Formattable args[] = {indentOffset,"",""};
807 	    UnicodeString t;
808 	    xmlString.append(formatString(mStringsBundle.getStringEx("layout", mError), args,2,t));
809 	    UnicodeString lang = mLocale.getLanguage();
810 	    UnicodeString country = mLocale.getCountry();
811 	    indentOffset.append("\t");
812         UBool rightToLeft = FALSE;
813 	    if(lang=="ar" || lang=="he" || lang=="il" || lang=="ps" || lang=="fa" ){
814 		    args[0] = indentOffset;
815 		    args[1] = "top-to-bottom";
816 		    args[2] = "right-to-left";
817 		    xmlString.append(formatString(mStringsBundle.getStringEx("orientation",mError), args,3,t));
818 	        rightToLeft = TRUE;
819         }else if(lang== "root"){
820 		    args[0] = indentOffset;
821 		    args[1] = "top-to-bottom";
822 		    args[2] = "left-to-right";
823 		    xmlString.append(formatString(mStringsBundle.getStringEx("orientation",mError), args,3,t));
824 	    }
825 	    chopIndent();
826 	    args[0] = indentOffset;
827 	    args[1] = "/";
828 	    xmlString.append(formatString(mStringsBundle.getStringEx("layout",mError),args,2,t));
829 	    mError = U_ZERO_ERROR;
830 	    //print this only in the root language locale
831 	    if(lang=="root" || rightToLeft == TRUE){
832 		    printString(&xmlString);
833 	    }
834     }
835 }
writeEncodings()836 void GenerateXML::writeEncodings(){
837 	UnicodeString xmlString;
838 	Formattable args[] = {indentOffset,"",""};
839 	UnicodeString t;
840 	xmlString.append(formatString(mStringsBundle.getStringEx("characters",mError),args,2,t));
841 	indentOffset.append("\t");
842     UnicodeString temp;
843     UBool writeData = FALSE;
844 
845     if(onlySpecials==FALSE){
846         writeExemplarCharacters(temp);
847     }
848     if(temp.length()>0){
849         xmlString.append(temp);
850         writeData = TRUE;
851     }
852     temp.remove();
853     //if(ignoreSpecials==TRUE){
854         writeLocaleScript(temp);
855     //}
856     if(temp.length()>0){
857         xmlString.append(temp);
858         writeData = TRUE;
859     }
860     // currently no mappings are defined in ICU
861     // so we donot add them
862     if(writeData == TRUE){
863         chopIndent();
864         args[0] = indentOffset;
865 	    args[1] = "/";
866 	    xmlString.append(formatString(mStringsBundle.getStringEx("characters",mError),args,2,t));
867 	    printString(&xmlString);
868     }else{
869         xmlString.remove();
870     }
871 
872     mError = U_ZERO_ERROR;
873 }
874 
writeExemplarCharacters(UnicodeString & xmlString)875 void GenerateXML::writeExemplarCharacters(UnicodeString& xmlString){
876     Formattable args[] = {"","",""};
877     args[0] = indentOffset;
878 	args[1] = mSourceBundle.getStringEx("ExemplarCharacters",mError);
879 	UnicodeString t;
880 	if(	mError != U_USING_FALLBACK_WARNING &&
881 		mError != U_USING_DEFAULT_WARNING &&
882 		U_SUCCESS(mError)){
883 
884 		xmlString.append(formatString(mStringsBundle.getStringEx("exemplarCharacters",mError),args,2,t));
885 	}
886     mError = U_ZERO_ERROR;
887 }
writeDelimiters()888 void GenerateXML::writeDelimiters(){
889 // Data not available in ICU
890 }
891 
writeMeasurement()892 void GenerateXML::writeMeasurement(){
893     UnicodeString xmlString;
894     writeMeasurement(xmlString);
895     if(xmlString.length()>0)  printString(&xmlString);
896 }
897 
898 
writeDates()899 void GenerateXML::writeDates(){
900 	UnicodeString xmlString;
901 	UBool print = FALSE;
902 	if(U_FAILURE(mError)) {
903 		return;
904 	}
905 	Formattable args[]={indentOffset,"",""};
906 	formatString(mStringsBundle.getStringEx("dates",mError),args,3,xmlString);
907 	UnicodeString tempStr;
908 	indentOffset.append("\t");
909 
910 	writeLocalePatternChars(tempStr);
911 	if(!tempStr.isEmpty()){
912 		xmlString.append(tempStr);
913 		print = TRUE;
914 	}
915 
916 	tempStr.remove();
917 	writeCalendars(tempStr);
918 	if(!tempStr.isEmpty()){
919 		xmlString.append(tempStr);
920 		print = TRUE;
921 	}
922 
923 	tempStr.remove();
924 	writeTimeZoneNames(tempStr);
925 	if(!tempStr.isEmpty()){
926 		xmlString.append(tempStr);
927 		print = TRUE;
928 	}
929 
930 	chopIndent();
931 
932 	Formattable args1[]={indentOffset,(UnicodeString(XML_END_SLASH)),""};
933 	UnicodeString t;
934 	xmlString.append(formatString(mStringsBundle.getStringEx("dates",mError) ,args1,3,t));
935 	if(print)  printString(&xmlString);
936 }
937 
writeTimeZoneNames(UnicodeString & xmlString)938 void GenerateXML::writeTimeZoneNames(UnicodeString& xmlString){
939 
940 	if(U_FAILURE(mError)) {
941 		return;
942 	}
943 	UBool isDefault =TRUE;
944 	Formattable args[4] ={indentOffset,"","",""};
945 
946 	UnicodeString t;
947 
948     ResourceBundle dBundle = mSourceBundle.get("zoneStrings", mError);
949     UBool remove = TRUE;
950 
951 	if(mError!=U_USING_DEFAULT_WARNING && U_SUCCESS(mError) && mError!=U_USING_FALLBACK_WARNING){
952 
953 		xmlString.append(formatString(mStringsBundle.getStringEx("timeZone",mError),args,2,t));
954 
955 		indentOffset.append("\t");
956         while(dBundle.hasNext()){
957             ResourceBundle dBundle1 = dBundle.getNext(mError);
958 
959             if(U_SUCCESS(mError)){
960 
961                 int i = 0;
962 
963                 UnicodeString data =dBundle1.getStringEx((int32_t)0,mError);
964                 if(U_SUCCESS(mError)){
965                      remove = FALSE;
966              	     args[0] =indentOffset;
967 					 args[1] = data;
968 					 args[2] = "";
969 			        xmlString.append(formatString(mStringsBundle.getStringEx("zoneStart",mError),args,3,t));
970 
971 			        isDefault=FALSE;
972 			        indentOffset.append("\t");
973 
974 					args[0] =indentOffset;
975 					args[1] = "";
976                     //long format
977 			        xmlString.append(formatString(mStringsBundle.getStringEx("long",mError),args,2,t));
978 
979 			        indentOffset.append("\t");
980          	       /*
981                     // Currently ICU does not have support for generic
982                     args[0]=indentOffset;
983 			        args[1]=dBundle1.getStringEx((int32_t)1,mError);
984                     if(U_SUCCESS(mError)){
985 			            xmlString.append(formatString(mStringsBundle.getStringEx("generic",mError),args,2,t));
986                     }
987                     */
988                     mError=U_ZERO_ERROR;
989                     args[1]=dBundle1.getStringEx((int32_t)1,mError);
990                     if(U_SUCCESS(mError)){
991 			            xmlString.append(formatString(mStringsBundle.getStringEx("standard",mError),args,2,t));
992                     }
993                     mError =U_ZERO_ERROR;
994                     args[1]=dBundle1.getStringEx((int32_t)3,mError);
995                     if(U_SUCCESS(mError)){
996 			            xmlString.append(formatString(mStringsBundle.getStringEx("daylight",mError),args,2,t));
997                     }
998                     mError=U_ZERO_ERROR;
999                     chopIndent();
1000 			        args[0]=indentOffset;
1001 					args[1]=UnicodeString(XML_END_SLASH);
1002 			        xmlString.append(formatString(mStringsBundle.getStringEx("long",mError),args,2,t));
1003 
1004 					args[1]="";
1005                     // short format
1006 			        xmlString.append(formatString(mStringsBundle.getStringEx("short",mError),args,2,t));
1007 
1008 			        indentOffset.append("\t");
1009 			        args[0]=indentOffset;
1010                     /*
1011                     // Currently ICU does not have support for generic
1012 
1013                     data=dBundle1.getStringEx((int32_t)0,mError);
1014                     if(U_SUCCESS(mError)){
1015 			            args[1]=data;
1016 			            xmlString.append(formatString(mStringsBundle.getStringEx("generic",mError),args,2,t));
1017                     }
1018                     */
1019                     data=dBundle1.getStringEx((int32_t)2,mError);
1020                     if(U_SUCCESS(mError)){
1021 			            args[1]=data;
1022 			            xmlString.append(formatString(mStringsBundle.getStringEx("standard",mError),args,2,t));
1023                     }
1024                     data = dBundle1.getStringEx((int32_t)4,mError);
1025                     if(U_SUCCESS(mError)){
1026     			        args[1]=data;
1027     			        xmlString.append(formatString(mStringsBundle.getStringEx("daylight",mError),args,2,t));
1028                     }
1029                     mError = U_ZERO_ERROR;
1030 			        chopIndent();
1031 			        args[0]=indentOffset;
1032 					args[1]=UnicodeString(XML_END_SLASH);
1033 			        xmlString.append(formatString(mStringsBundle.getStringEx("short",mError),args,2,t));
1034 
1035 			        args[1].setString(dBundle1.getStringEx((int32_t)5,mError));
1036                     if(U_SUCCESS(mError)){
1037 			            xmlString.append(formatString(mStringsBundle.getStringEx("exemplarCity",mError),args,2,t));
1038                     }
1039                     mError=U_ZERO_ERROR;
1040 			        chopIndent();
1041 			        xmlString.append(formatString(mStringsBundle.getStringEx("zoneEnd",mError),indentOffset,t));
1042 
1043 
1044                 }
1045 		    }
1046             mError=U_ZERO_ERROR;
1047 
1048         }
1049 		chopIndent();
1050 		args[0]=indentOffset;
1051 		args[1]=UnicodeString(XML_END_SLASH);
1052 		xmlString.append(formatString(mStringsBundle.getStringEx("timeZone",mError),args,2,t));
1053 		//printString(&xmlString);
1054         if(remove==TRUE){
1055             xmlString.remove();
1056         }
1057         mError=U_ZERO_ERROR;
1058 		return;
1059     }
1060 	mError=U_ZERO_ERROR;
1061 }
1062 
1063 
writeCalendars(UnicodeString & xmlString)1064 void GenerateXML::writeCalendars(UnicodeString& xmlString){
1065 	UnicodeString tempStr;
1066 	UBool print =FALSE;
1067 	Formattable args[2]={indentOffset,""};
1068 	xmlString.append(formatString(mStringsBundle.getStringEx("calendars",mError),args,2,tempStr));
1069 
1070     ResourceBundle calendars = mSourceBundle.get("calendar", mError);
1071     indentOffset.append("\t");
1072     if( mError!=U_USING_DEFAULT_WARNING &&
1073 		mError!=U_USING_FALLBACK_WARNING &&
1074             U_SUCCESS(mError)){
1075 
1076 
1077         ResourceBundle defaultCalendar = calendars.getWithFallback("default", mError);
1078         UnicodeString defaultC = defaultCalendar.getString(mError);
1079         args[0] = indentOffset;
1080         args[1] = defaultC;
1081         if(U_FAILURE(mError)){
1082             fprintf(stderr, "Could not find the default calendar. Dying.\n");
1083             exit(U_INTERNAL_PROGRAM_ERROR);
1084         }
1085         xmlString.append(formatString(mStringsBundle.getStringEx( "default",mError),args,2,tempStr));
1086 
1087         while(calendars.hasNext()){
1088             ResourceBundle calendar = calendars.getNext(mError);
1089             if(U_SUCCESS(mError)){
1090                 UnicodeString key = UnicodeString(calendar.getKey());
1091                 mError=U_ZERO_ERROR;
1092 	            tempStr.remove();
1093                 writeCalendar(calendar, key, (defaultC==key),tempStr);
1094 	            if(!tempStr.isEmpty()){
1095 		            xmlString.append(tempStr);
1096 		            print = TRUE;
1097 	            }
1098             }
1099         }
1100     }
1101 	chopIndent();
1102     args[0] = indentOffset;
1103 	args[1]=UnicodeString(XML_END_SLASH);
1104     if(print ==TRUE){
1105 	    xmlString.append(formatString(mStringsBundle.getStringEx("calendars",mError),args,2,tempStr));
1106     }else{
1107         xmlString.remove();
1108     }
1109 }
1110 
writeCalendar(ResourceBundle & calendar,UnicodeString & cal,UBool isDefault,UnicodeString & xmlString)1111 void GenerateXML::writeCalendar(ResourceBundle& calendar, UnicodeString& cal,UBool isDefault,UnicodeString& xmlString){
1112 
1113 	UnicodeString tempStr;
1114 	UBool print =FALSE;
1115 	Formattable args[]={indentOffset,cal};
1116 	// TODO : Figure out a way to find default
1117 	// xmlString.append(formatString(mStringsBundle.getStringEx( "default",mError),args,2,tempStr));
1118 	xmlString.append(formatString(mStringsBundle.getStringEx("calendarStart",mError),args,2,tempStr));
1119 
1120 	indentOffset.append("\t");
1121 	tempStr.remove();
1122 	writeMonthNames(calendar, tempStr);
1123 	if(!tempStr.isEmpty()){
1124 		xmlString.append(tempStr);
1125 		print = TRUE;
1126 	}
1127 
1128 	tempStr.remove();
1129 	writeDayNames(calendar, tempStr);
1130 	if(!tempStr.isEmpty()){
1131 		xmlString.append(tempStr);
1132 		print = TRUE;
1133 	}
1134 
1135     tempStr.remove();
1136 	writeWeek(calendar, tempStr);
1137 	if(!tempStr.isEmpty()){
1138 		xmlString.append(tempStr);
1139 		print = TRUE;
1140 	}
1141 	tempStr.remove();
1142 	writeAMPMmarkers(calendar, tempStr);
1143 	if(!tempStr.isEmpty()){
1144 		xmlString.append(tempStr);
1145 		print = TRUE;
1146 	}
1147     tempStr.remove();
1148 	writeEra(calendar, tempStr);
1149 	if(!tempStr.isEmpty()){
1150 		xmlString.append(tempStr);
1151 		print = TRUE;
1152 	}
1153 	tempStr.remove();
1154 	writeDateFormat(calendar,tempStr);
1155 	if(!tempStr.isEmpty()){
1156 		xmlString.append(tempStr);
1157 		print = TRUE;
1158 	}
1159     tempStr.remove();
1160 	writeTimeFormat(calendar, tempStr);
1161 	if(!tempStr.isEmpty()){
1162 		xmlString.append(tempStr);
1163 		print = TRUE;
1164 	}
1165     tempStr.remove();
1166 	writeDateTimeFormat(calendar, tempStr);
1167 	if(!tempStr.isEmpty()){
1168 		xmlString.append(tempStr);
1169 		print = TRUE;
1170 	}
1171 	chopIndent();
1172     mError =U_ZERO_ERROR;
1173     if(print == TRUE){
1174 	    xmlString.append(formatString(mStringsBundle.getStringEx("calendarEnd",mError),indentOffset,tempStr));
1175     }else{
1176         xmlString.remove();
1177     }
1178 }
1179 
getDayName(int index)1180 const char* getDayName(int index){
1181 	switch(index){
1182 	case 0:
1183 		return "sun";
1184 	case 1:
1185 		return "mon";
1186 	case 2:
1187 		return "tue";
1188 	case 3:
1189 		return "wed";
1190 	case 4:
1191 		return "thu";
1192 	case 5:
1193 		return "fri";
1194 	case 6:
1195 		return "sat";
1196 	default:
1197 		return "";
1198 	}
1199 }
getDayNameDTE(int index)1200 const char* getDayNameDTE(int index){
1201 	switch(index){
1202 	case 1:
1203 		return "sun";
1204 	case 2:
1205 		return "mon";
1206 	case 3:
1207 		return "tue";
1208 	case 4:
1209 		return "wed";
1210 	case 5:
1211 		return "thu";
1212 	case 6:
1213 		return "fri";
1214 	case 7:
1215 		return "sat";
1216 	default:
1217 		return "";
1218 	}
1219 }
writeMonthNames(ResourceBundle & calendar,UnicodeString & xmlString)1220 void GenerateXML::writeMonthNames(ResourceBundle& calendar, UnicodeString& xmlString){
1221 
1222     ResourceBundle monthNames = calendar.get("monthNames",mError);
1223 	UnicodeString t;
1224     if( mError!=U_USING_DEFAULT_WARNING &&
1225 		mError!=U_USING_FALLBACK_WARNING &&
1226 		U_SUCCESS(mError)){
1227 
1228         Formattable args[4] ={ indentOffset, "", "", "" };
1229         xmlString.append(formatString(mStringsBundle.getStringEx("months", mError), args, 2, t));
1230         indentOffset.append("\t");
1231 
1232         while(monthNames.hasNext()){
1233             ResourceBundle context = monthNames.getNext(mError);
1234             UnicodeString ctxKey = UnicodeString(context.getKey());
1235             if(U_FAILURE(mError)){
1236                 exit(U_INTERNAL_PROGRAM_ERROR);
1237             }
1238             if(ctxKey=="default"){
1239                 args[0] = indentOffset;
1240                 args[1] = context.getString(mError);
1241                 xmlString.append(formatString(mStringsBundle.getStringEx("default",mError),args,2,t));
1242                 continue;
1243             }
1244             args[0] = indentOffset;
1245             args[1] = ctxKey;
1246             xmlString.append(formatString(mStringsBundle.getStringEx("monthContext",mError),args,2,t));
1247 		    indentOffset.append("\t");
1248 
1249             UnicodeString defaultWidth = context.getStringEx("default", mError);
1250             if(U_SUCCESS(mError)){
1251                 args[0] = indentOffset;
1252                 args[1] = defaultWidth;
1253                 xmlString.append(formatString(mStringsBundle.getStringEx("default",mError),args,2,t));
1254             }
1255             mError = U_ZERO_ERROR;
1256 
1257             while(context.hasNext()){
1258                 ResourceBundle width = context.getNext(mError);
1259                 if(U_FAILURE(mError)){
1260                     fprintf(stderr, "Unexpected Error: %s \n", u_errorName(mError));
1261                     exit(U_INTERNAL_PROGRAM_ERROR);
1262                 }
1263                 UnicodeString widthKey = UnicodeString(width.getKey());
1264                 if(widthKey=="default"){
1265                     continue;
1266                 }
1267                 args[0] = indentOffset;
1268                 args[1] = widthKey;
1269                 xmlString.append(formatString(mStringsBundle.getStringEx("monthWidth",mError),args,2,t));
1270 		        indentOffset.append("\t");
1271 
1272                 for(int i=0;width.hasNext();i++){
1273                     char c[10]={0};
1274 			        itoa(i+1,c,10);
1275 			        args[0] = indentOffset;
1276 			        args[1] = UnicodeString(c);
1277 			        args[2] = width.getNextString(mError);
1278 			        xmlString.append(formatString(mStringsBundle.getStringEx("month",mError),args,3,t));
1279 		        }
1280 		        chopIndent();
1281 		        args[0] = indentOffset;
1282 		        xmlString.append(formatString(mStringsBundle.getStringEx("monthWidthEnd",mError),args,1,t));
1283             }
1284             chopIndent();
1285             args[0] = indentOffset;
1286             xmlString.append(formatString(mStringsBundle.getStringEx("monthContextEnd",mError),args,1,t));
1287         }
1288 
1289         chopIndent();
1290         args[0] = indentOffset;
1291         args[1] = UnicodeString(XML_END_SLASH);
1292         xmlString.append(formatString(mStringsBundle.getStringEx("months",mError),args,2,t));
1293 
1294         mError=U_ZERO_ERROR;
1295 		return;
1296     }
1297 	xmlString.remove();
1298 	mError= U_ZERO_ERROR;
1299 }
1300 
writeDayNames(ResourceBundle & calendar,UnicodeString & xmlString)1301 void GenerateXML::writeDayNames(ResourceBundle& calendar, UnicodeString& xmlString){
1302    ResourceBundle dayNames = calendar.get("dayNames",mError);
1303 	UnicodeString t;
1304     if( mError!=U_USING_DEFAULT_WARNING &&
1305 		mError!=U_USING_FALLBACK_WARNING &&
1306 		U_SUCCESS(mError)){
1307 
1308         Formattable args[4] ={ indentOffset, "", "", "" };
1309         xmlString.append(formatString(mStringsBundle.getStringEx("days", mError), args, 2, t));
1310         indentOffset.append("\t");
1311 
1312         while(dayNames.hasNext()){
1313             ResourceBundle context = dayNames.getNext(mError);
1314             UnicodeString ctxKey = UnicodeString(context.getKey());
1315             if(ctxKey=="default"){
1316                 args[0] = indentOffset;
1317                 args[1] = context.getString(mError);
1318                 xmlString.append(formatString(mStringsBundle.getStringEx("default",mError),args,2,t));
1319                 continue;
1320             }
1321             if(U_FAILURE(mError)){
1322                 exit(U_INTERNAL_PROGRAM_ERROR);
1323             }
1324             args[0] = indentOffset;
1325             args[1] = ctxKey;
1326             xmlString.append(formatString(mStringsBundle.getStringEx("dayContext",mError),args,2,t));
1327 		    indentOffset.append("\t");
1328             UnicodeString defaultWidth = context.getStringEx("default", mError);
1329             if(U_SUCCESS(mError)){
1330                 args[0] = indentOffset;
1331                 args[1] = defaultWidth;
1332                 xmlString.append(formatString(mStringsBundle.getStringEx("default",mError),args,2,t));
1333             }
1334             mError = U_ZERO_ERROR;
1335             while(context.hasNext()){
1336                 ResourceBundle width = context.getNext(mError);
1337                 if(U_FAILURE(mError)){
1338                     fprintf(stderr, "Unexpected Error: %s \n", u_errorName(mError));
1339                     exit(U_INTERNAL_PROGRAM_ERROR);
1340                 }
1341                 UnicodeString widthKey = UnicodeString(width.getKey());
1342                 if(widthKey == "default"){
1343                      continue;
1344                 }
1345                 args[0] = indentOffset;
1346                 args[1] = widthKey;
1347                 xmlString.append(formatString(mStringsBundle.getStringEx("dayWidth",mError),args,2,t));
1348 		        indentOffset.append("\t");
1349 
1350                 for(int i=0;width.hasNext();i++){
1351 
1352 			        args[0] = indentOffset;
1353 			        args[1] = getDayName(i);
1354 			        args[2] = width.getNextString(mError);
1355 			        xmlString.append(formatString(mStringsBundle.getStringEx("day",mError),args,3,t));
1356 		        }
1357 		        chopIndent();
1358 		        args[0] = indentOffset;
1359 		        xmlString.append(formatString(mStringsBundle.getStringEx("dayWidthEnd",mError),args,1,t));
1360             }
1361             chopIndent();
1362             args[0] = indentOffset;
1363             xmlString.append(formatString(mStringsBundle.getStringEx("dayContextEnd",mError),args,1,t));
1364         }
1365 
1366         chopIndent();
1367         args[0] = indentOffset;
1368         args[1] = UnicodeString(XML_END_SLASH);
1369         xmlString.append(formatString(mStringsBundle.getStringEx("days",mError),args,2,t));
1370 
1371         mError=U_ZERO_ERROR;
1372 		return;
1373     }
1374 	xmlString.remove();
1375 	mError= U_ZERO_ERROR;
1376 }
getTimeString(UnicodeString & val,int32_t milliSecs)1377 UnicodeString getTimeString(UnicodeString& val, int32_t milliSecs){
1378     int32_t minutes = milliSecs / (60000); /* number of milli seconds in 1 hr*/
1379     int32_t deltaMin = minutes % 60;
1380     int32_t hours = (minutes-deltaMin)/60;
1381     char c[10]={0};
1382     itoa(hours, c, 10);
1383     if(strcmp(c,"0")==0){
1384         val.append("00");
1385     }else{
1386         if(strlen(c)==1){
1387             val.append("0");
1388         }
1389         val.append(c);
1390     }
1391     val.append(":");
1392     c[0] = 0;
1393     itoa(minutes, c, 10);
1394     if(strcmp(c,"0")==0){
1395         val.append("00");
1396     }else{
1397         if(strlen(c)==1){
1398             val.append("0");
1399         }
1400         val.append(c);
1401     }
1402     return val;
1403 }
writeWeek(ResourceBundle & calendar,UnicodeString & xmlString)1404 void GenerateXML::writeWeek(ResourceBundle& calendar, UnicodeString& xmlString){
1405 	UnicodeString t;
1406     Formattable args[3] = {indentOffset,"",""};
1407 	xmlString.append(formatString(mStringsBundle.getStringEx("week",mError),args,2,t));
1408 	indentOffset.append("\t");
1409 
1410     ResourceBundle dtElements = calendar.get("DateTimeElements", mError);
1411 	UnicodeString temp;
1412 
1413     if( mError!=U_USING_DEFAULT_WARNING &&
1414 		mError!=U_USING_FALLBACK_WARNING &&
1415 		U_SUCCESS(mError)){
1416 	    int32_t len =0;
1417 	    const int32_t* vector = dtElements.getIntVector(len,mError);
1418 
1419 		args[0] = indentOffset;
1420         // write min days in a week
1421         if(len > 1){
1422 		    args[1] = vector[1];
1423         }else{
1424             args[1] = "";
1425         }
1426         temp.append(formatString(mStringsBundle.getStringEx("minDays",mError),args,2,t));
1427 
1428         // write first day of the week
1429         args[1] = getDayNameDTE(vector[0]);
1430 		temp.append(formatString(mStringsBundle.getStringEx("firstDay",mError),args,2,t));
1431 
1432     }
1433 
1434     mError = U_ZERO_ERROR;
1435     // now write weekend information
1436     ResourceBundle weekend = calendar.get("weekend", mError);
1437     if(U_SUCCESS(mError)){
1438         int32_t len = 0;
1439         const int32_t* vector = weekend.getIntVector(len, mError);
1440         UnicodeString time;
1441         args[0] = indentOffset;
1442 
1443         args[1] = getDayNameDTE(vector[0]);
1444         args[2] = getTimeString(time, vector[1]);
1445         temp.append(formatString(mStringsBundle.getStringEx("weekendStart", mError), args, 3, t));
1446 
1447         time.remove();
1448         args[1] = getDayNameDTE(vector[2]);
1449         args[2] = getTimeString(time, vector[3]);
1450         temp.append(formatString(mStringsBundle.getStringEx("weekendEnd", mError), args, 3, t));
1451 
1452     }
1453 
1454     mError = U_ZERO_ERROR;
1455     if(temp.length()>0){
1456         xmlString.append(temp);
1457     	chopIndent();
1458 		args[0] = indentOffset;
1459 		args[1] = UnicodeString(XML_END_SLASH);
1460 		xmlString.append(formatString(mStringsBundle.getStringEx("week",mError),args,2,t));
1461 		mError=U_ZERO_ERROR;
1462 		return;
1463     }
1464     chopIndent();
1465 	xmlString.remove();
1466 	mError= U_ZERO_ERROR;
1467 }
1468 
writeEra(ResourceBundle & calendar,UnicodeString & xmlString)1469 void GenerateXML::writeEra(ResourceBundle& calendar,UnicodeString& xmlString){
1470 
1471     ResourceBundle eras= calendar.get("eras",mError);
1472 	UnicodeString t;
1473 	if( mError!=U_USING_DEFAULT_WARNING &&
1474 		mError!=U_USING_FALLBACK_WARNING &&
1475 		U_SUCCESS(mError)){
1476 
1477 		Formattable args[3] = {indentOffset,"",""};
1478 		xmlString.append(formatString(mStringsBundle.getStringEx("eras",mError),args,2,t));
1479 		indentOffset.append("\t");
1480 
1481         args[0] = indentOffset;
1482         xmlString.append(formatString(mStringsBundle.getStringEx("eraAbbr",mError),args,2,t));
1483 
1484         indentOffset.append("\t");
1485 		args[0] = indentOffset;
1486         for(int i=0;eras.hasNext();i++){
1487             char c[10]={0};
1488 			itoa(i+1,c,10);
1489 			args[1] = UnicodeString(c);
1490 			args[2] = eras.getNextString(mError);
1491 			xmlString.append(formatString(mStringsBundle.getStringEx("era",mError),args,3,t));
1492 		}
1493 		chopIndent();
1494 		args[0] = indentOffset;
1495 		args[1] = UnicodeString(XML_END_SLASH);
1496 		xmlString.append(formatString(mStringsBundle.getStringEx("eraAbbr",mError),args,2,t));
1497 
1498         chopIndent();
1499 		args[0] = indentOffset;
1500 		args[1] = UnicodeString(XML_END_SLASH);
1501 		xmlString.append(formatString(mStringsBundle.getStringEx("eras",mError),args,2,t));
1502 		mError=U_ZERO_ERROR;
1503 		return;
1504 	}
1505 	xmlString.remove();
1506 	mError =U_ZERO_ERROR;
1507 }
1508 
1509 
writeAMPMmarkers(ResourceBundle & calendar,UnicodeString & xmlString)1510 void GenerateXML::writeAMPMmarkers( ResourceBundle& calendar, UnicodeString& xmlString){
1511 	ResourceBundle markers = calendar.get("AmPmMarkers",mError);
1512 	UnicodeString t;
1513 	if( mError!=U_USING_DEFAULT_WARNING &&
1514 		mError!=U_USING_FALLBACK_WARNING &&
1515         U_SUCCESS(mError)){
1516 		Formattable args[] = {indentOffset,markers.getStringEx((int32_t)0,mError)};
1517 		xmlString.append(formatString(mStringsBundle.getStringEx("am",mError),args ,3,t));
1518 		args[1] = markers.getStringEx((int32_t)1,mError);
1519 		xmlString.append(formatString(mStringsBundle.getStringEx("pm",mError),args ,3,t));
1520 		mError= U_ZERO_ERROR;
1521 		return;
1522 	}
1523 	xmlString.remove();
1524 	mError= U_ZERO_ERROR;
1525 
1526 }
1527 
writeFormat(const char * elemName,const char * style,const char * start,const char * end,const char * typeName,UnicodeString & pattern,UnicodeString & xmlString,UBool split)1528 void GenerateXML::writeFormat(const char* elemName, const char* style, const char* start, const char* end, const char* typeName,UnicodeString& pattern,
1529 						      UnicodeString& xmlString, UBool split){
1530 
1531     if( mError!=U_USING_DEFAULT_WARNING &&
1532 		mError!=U_USING_FALLBACK_WARNING &&
1533         U_SUCCESS(mError)){
1534         UnicodeString t;
1535         Formattable args[] = {indentOffset,"",""};
1536         xmlString.append(formatString(mStringsBundle.getStringEx(elemName,mError),args ,3,t));
1537         indentOffset.append("\t");
1538         writeFormat(style, start, end, NULL, pattern, xmlString, split);
1539         chopIndent();
1540 
1541         args[1]=UnicodeString(XML_END_SLASH);
1542         xmlString.append(formatString(mStringsBundle.getStringEx( elemName,mError),args,3,t));
1543 		mError= U_ZERO_ERROR;
1544 		return;
1545      }
1546 	 xmlString.remove();
1547 	 mError= U_ZERO_ERROR;
1548 
1549 
1550 
1551 }
writeFormat(const char * style,const char * start,const char * end,const char * typeName,UnicodeString & pattern,UnicodeString & xmlString,UBool split)1552 void GenerateXML::writeFormat(const char* style, const char* start, const char* end, const char* typeName,UnicodeString& pattern,
1553 						      UnicodeString& xmlString, UBool split){
1554 	UnicodeString t;
1555     UnicodeString type;
1556 
1557     if(typeName!=NULL){
1558         type.append("type=\"");
1559         type.append(typeName);
1560         type.append("\"");
1561     }
1562 	if(!split){
1563 
1564 		Formattable args[4]={indentOffset,"",type,""};
1565         if(*style!=0){
1566             xmlString.append(formatString(mStringsBundle.getStringEx(style,mError),args,3,t));
1567 
1568 
1569 	        indentOffset.append("\t");
1570 		    args[0]= indentOffset;
1571         }else{
1572             args[1] = type;
1573         }
1574 		xmlString.append(formatString(mStringsBundle.getStringEx(start,mError),args,2,t));
1575 
1576 		indentOffset.append("\t");
1577 		args[0]=indentOffset;
1578 		args[1]=pattern;
1579 		xmlString.append(formatString(mStringsBundle.getStringEx("pattern",mError),args,2,t));
1580 
1581 
1582 		chopIndent();
1583 		xmlString.append(formatString(mStringsBundle.getStringEx(end, mError), indentOffset,t));
1584 
1585         if(*style!=0){
1586             chopIndent();
1587             args[0]=indentOffset;
1588             args[1]=UnicodeString(XML_END_SLASH);
1589             args[2]="";
1590             xmlString.append(formatString(mStringsBundle.getStringEx(style,mError),args,3,t));
1591         }
1592 
1593 	}else{
1594 		Formattable args[4]={indentOffset,"",type,""};
1595         if(*style!=0){
1596             xmlString.append(formatString(mStringsBundle.getStringEx(style,mError),args,3,t));
1597 
1598 	        indentOffset.append("\t");
1599 		    args[0]= indentOffset;
1600         }else{
1601             args[1]=type;
1602         }
1603 		xmlString.append(formatString(mStringsBundle.getStringEx(start,mError),args,2,t));
1604 		UnicodeString positive;
1605 		UnicodeString negative;
1606 		pattern.extractBetween(0,pattern.indexOf(";"),positive);
1607 		pattern.extractBetween(pattern.indexOf(";")+1,pattern.length(),negative);
1608 		indentOffset.append("\t");
1609 		args[0]=indentOffset;
1610 		if(!positive.isEmpty()){
1611 			args[1]=positive;
1612 			xmlString.append(formatString(mStringsBundle.getStringEx("pattern",mError),args,2,t));
1613 		}
1614 		if(!negative.isEmpty()){
1615 			args[1]=negative;
1616 			xmlString.append(formatString(mStringsBundle.getStringEx("pattern",mError),args,2,t));
1617 		}
1618 		chopIndent();
1619 		xmlString.append(formatString(mStringsBundle.getStringEx(end, mError), indentOffset,t));
1620 
1621         if(*style!=0){
1622             chopIndent();
1623             args[0]=indentOffset;
1624             args[1]=UnicodeString(XML_END_SLASH);
1625             args[2]="";
1626             xmlString.append(formatString(mStringsBundle.getStringEx(style,mError),args,3,t));
1627         }
1628 
1629     }
1630 
1631 }
1632 
writeDateFormat(ResourceBundle & calendar,UnicodeString & xmlString)1633 void GenerateXML::writeDateFormat(ResourceBundle& calendar, UnicodeString& xmlString){
1634 
1635 	ResourceBundle dtPatterns = calendar.get("DateTimePatterns", mError);
1636 	UnicodeString t;
1637 	if( mError!=U_USING_DEFAULT_WARNING &&
1638 		mError!=U_USING_FALLBACK_WARNING &&
1639         U_SUCCESS(mError)){
1640 
1641 		// hard code default to medium pattern for ICU
1642 		Formattable args[4]= {indentOffset,"","",""};
1643 
1644 		xmlString.append(formatString(mStringsBundle.getStringEx("dateFormats",mError),args,2,t));
1645 
1646 		indentOffset.append("\t");
1647 		args[0]= indentOffset;
1648 		args[1] = "medium";
1649 		xmlString.append(formatString(mStringsBundle.getStringEx( "default",mError),args,2,t));
1650 
1651 		UnicodeString tempStr;
1652 
1653 		writeFormat("dateFormatLength","dateFormatStart","dateFormatEnd","full",dtPatterns.getStringEx((int32_t)4,mError),xmlString);
1654 		writeFormat("dateFormatLength","dateFormatStart","dateFormatEnd","long",dtPatterns.getStringEx((int32_t)5,mError),xmlString);
1655 		writeFormat("dateFormatLength","dateFormatStart","dateFormatEnd","medium",dtPatterns.getStringEx((int32_t)6,mError),xmlString);
1656 		writeFormat("dateFormatLength","dateFormatStart","dateFormatEnd","short",dtPatterns.getStringEx((int32_t)7,mError),xmlString);
1657 
1658 		chopIndent();
1659 
1660 		args[0]=indentOffset;
1661 		args[1]=UnicodeString(XML_END_SLASH);
1662 		xmlString.append(formatString(mStringsBundle.getStringEx("dateFormats",mError),args,2,t));
1663 
1664   	}
1665 
1666 	mError= U_ZERO_ERROR;
1667 //	if(!print) xmlString.remove();
1668 }
1669 
1670 
writeTimeFormat(ResourceBundle & calendar,UnicodeString & xmlString)1671 void GenerateXML::writeTimeFormat(ResourceBundle& calendar, UnicodeString& xmlString){
1672 	ResourceBundle dtPatterns = calendar.get("DateTimePatterns", mError);
1673 	UnicodeString t;
1674 	if( mError!=U_USING_DEFAULT_WARNING &&
1675 		mError!=U_USING_FALLBACK_WARNING &&
1676         U_SUCCESS(mError)){
1677 		// hard code default to medium pattern for ICU
1678 		Formattable args[4]= {indentOffset,"","",""};
1679 		xmlString.append(formatString(mStringsBundle.getStringEx("timeFormats",mError),args,2,t));
1680 
1681 		indentOffset.append("\t");
1682 		args[0]= indentOffset;
1683 		args[1]="medium";
1684 		xmlString.append(formatString(mStringsBundle.getStringEx( "default",mError),args,2,t));
1685 
1686 		UnicodeString tempStr;
1687 
1688 		writeFormat("timeFormatLength","timeFormatStart","timeFormatEnd","full",dtPatterns.getStringEx((int32_t)0,mError),xmlString);
1689 		writeFormat("timeFormatLength","timeFormatStart","timeFormatEnd","long",dtPatterns.getStringEx((int32_t)1,mError),xmlString);
1690 		writeFormat("timeFormatLength","timeFormatStart","timeFormatEnd","medium",dtPatterns.getStringEx((int32_t)2,mError),xmlString);
1691 		writeFormat("timeFormatLength","timeFormatStart","timeFormatEnd","short",dtPatterns.getStringEx((int32_t)3,mError),xmlString);
1692 
1693 		chopIndent();
1694 
1695 		args[0]=indentOffset;
1696 		args[1]=UnicodeString(XML_END_SLASH);
1697 		xmlString.append(formatString(mStringsBundle.getStringEx("timeFormats",mError),args,2,t));
1698 
1699 	}
1700 
1701 	mError= U_ZERO_ERROR;
1702 
1703 //	if(!print) xmlString.remove();
1704 }
1705 
writeDateTimeFormat(ResourceBundle & calendar,UnicodeString & xmlString)1706 void GenerateXML::writeDateTimeFormat(ResourceBundle& calendar, UnicodeString& xmlString){
1707 	ResourceBundle dtPatterns = calendar.get("DateTimePatterns", mError);
1708     UnicodeString t;
1709 	if( mError!=U_USING_DEFAULT_WARNING &&
1710 		mError!=U_USING_FALLBACK_WARNING &&
1711         U_SUCCESS(mError)){
1712 
1713 		Formattable args[4]= {indentOffset,"","",""};
1714 		xmlString.append(formatString(mStringsBundle.getStringEx("dateTimeFormats",mError),args,2,t));
1715 
1716 		indentOffset.append("\t");
1717 		args[0]= indentOffset;
1718 
1719 		UnicodeString tempStr;
1720 
1721 		writeFormat("dateTimeFormatLength","dateTimeFormatStart","dateTimeFormatEnd",NULL,dtPatterns.getStringEx((int32_t)8,mError),xmlString);
1722 
1723         chopIndent();
1724 
1725 		args[0]=indentOffset;
1726 		args[1]=UnicodeString(XML_END_SLASH);
1727 		xmlString.append(formatString(mStringsBundle.getStringEx("dateTimeFormats",mError),args,2,t));
1728 
1729 	}
1730 
1731 	mError= U_ZERO_ERROR;
1732 
1733 //	if(!print) xmlString.remove();
1734 }
1735 
writeLocalePatternChars(UnicodeString & xmlString)1736 void GenerateXML::writeLocalePatternChars(UnicodeString& xmlString){
1737 
1738 	UnicodeString temp=mSourceBundle.getStringEx("localPatternChars",mError);
1739 	Formattable args[]={indentOffset,""};
1740 	UnicodeString t;
1741 	if(U_SUCCESS(mError) && mError!=U_USING_DEFAULT_WARNING && mError!=U_USING_FALLBACK_WARNING){
1742 		args[1] = temp;
1743 		xmlString.append(formatString(mStringsBundle.getStringEx( "localizedChars",mError),args,2,t));
1744 		mError = U_ZERO_ERROR;
1745 		return;
1746 	}
1747 	xmlString.remove();
1748 	mError = U_ZERO_ERROR;
1749 }
1750 
writeNumberFormat()1751 void GenerateXML::writeNumberFormat(){
1752 
1753 	UnicodeString xmlString, tempStr;
1754 	Formattable args[2]={indentOffset,""};
1755 	UnicodeString t;
1756 	xmlString.append(formatString(mStringsBundle.getStringEx( "numbers",mError),args,2,t));
1757 	indentOffset.append("\t");
1758 	UBool print = FALSE;
1759 
1760 	writeNumberElements(tempStr);
1761 	if(!tempStr.isEmpty()){
1762 		xmlString.append(tempStr);
1763 		print = TRUE;
1764 	}
1765 
1766 	tempStr.remove();
1767 	writeNumberPatterns(tempStr);
1768 	if(!tempStr.isEmpty()){
1769 		xmlString.append(tempStr);
1770 		print = TRUE;
1771 	}
1772 
1773 	tempStr.remove();
1774 	writeCurrencies(tempStr);
1775 	if(!tempStr.isEmpty()){
1776 		xmlString.append(tempStr);
1777 		print = TRUE;
1778 	}
1779 
1780 	chopIndent();
1781 	args[1]=UnicodeString(XML_END_SLASH);
1782 	xmlString.append(formatString(mStringsBundle.getStringEx( "numbers",mError),args,2,t));
1783 	if(print) printString(&xmlString);
1784 }
1785 
writeNumberElements(UnicodeString & xmlString)1786 void GenerateXML::writeNumberElements(UnicodeString& xmlString){
1787 
1788 	DecimalFormatSymbols mySymbols(mLocale,mError);
1789 	UnicodeString symbol;
1790 	mError = U_ZERO_ERROR;
1791 	ResourceBundle numFormats = mSourceBundle.get("NumberElements", mError);
1792 	UnicodeString t;
1793 	if( mError!=U_USING_DEFAULT_WARNING &&
1794 		mError != U_USING_FALLBACK_WARNING &&
1795 		U_SUCCESS(mError)){
1796 
1797 		Formattable args[]={indentOffset,""};
1798 
1799 		xmlString.append(formatString(mStringsBundle.getStringEx( "symbols",mError),args,2,t));
1800 
1801 		indentOffset.append("\t");
1802 
1803 		UnicodeString pattern= numFormats.getStringEx((int32_t)0,mError);
1804 
1805 		args[0] = indentOffset;
1806 		args[1] = pattern;
1807 
1808 		xmlString.append(formatString(mStringsBundle.getStringEx( "decimal",mError),args,2,t));
1809 
1810 		args[1]=numFormats.getStringEx((int32_t)1,mError);
1811 		xmlString.append(formatString(mStringsBundle.getStringEx( "group",mError),args,2,t));
1812 
1813 		args[1]=numFormats.getStringEx((int32_t)2,mError);
1814 		xmlString.append(formatString(mStringsBundle.getStringEx( "list",mError),args,2,t));
1815 
1816 		args[1]=numFormats.getStringEx((int32_t)3,mError);
1817 		xmlString.append(formatString(mStringsBundle.getStringEx( "percentSign",mError),args,2,t));
1818 
1819 		args[1]=numFormats.getStringEx((int32_t)4,mError);
1820 		xmlString.append(formatString(mStringsBundle.getStringEx( "negativeZero",mError),args,2,t));
1821 
1822 		args[1]=numFormats.getStringEx((int32_t)5,mError);
1823 		xmlString.append(formatString(mStringsBundle.getStringEx( "patternDigit",mError),args,2,t));
1824 
1825 		args[1]=numFormats.getStringEx((int32_t)11,mError);
1826 		xmlString.append(formatString(mStringsBundle.getStringEx( "plusSign",mError),args,2,t));
1827         if(mError == U_MISSING_RESOURCE_ERROR){
1828             mError = U_ZERO_ERROR;
1829         }
1830 		args[1]=numFormats.getStringEx((int32_t)6,mError);
1831 		xmlString.append(formatString(mStringsBundle.getStringEx( "minusSign",mError),args,2,t));
1832 
1833 		args[1]=numFormats.getStringEx((int32_t)7,mError);
1834 		xmlString.append(formatString(mStringsBundle.getStringEx( "exponential",mError),args,2,t));
1835 
1836         args[1]=numFormats.getStringEx((int32_t)8,mError);
1837 		xmlString.append(formatString(mStringsBundle.getStringEx( "perMille",mError),args,2,t));
1838 
1839 		args[1]=numFormats.getStringEx((int32_t)9,mError);
1840 		xmlString.append(formatString(mStringsBundle.getStringEx( "infinity",mError),args,2,t));
1841 
1842 		args[1]=numFormats.getStringEx((int32_t)10,mError);
1843 		xmlString.append(formatString(mStringsBundle.getStringEx( "nan",mError),args,2,t));
1844 		chopIndent();
1845 		args[0] = indentOffset;
1846 		args[1] = UnicodeString(XML_END_SLASH);
1847 		xmlString.append(formatString(mStringsBundle.getStringEx( "symbols",mError),args,2,t));
1848 		return;
1849 
1850 	}
1851 	mError= U_ZERO_ERROR;
1852 	xmlString.remove();
1853 }
1854 
1855 
writeNumberPatterns(UnicodeString & xmlString)1856 void GenerateXML::writeNumberPatterns(UnicodeString& xmlString){
1857 
1858 	mError =U_ZERO_ERROR;
1859 	ResourceBundle dtPatterns = mSourceBundle.get("NumberPatterns", mError);
1860 	UnicodeString t;
1861 	if( mError!=U_USING_DEFAULT_WARNING &&
1862 		mError!=U_USING_FALLBACK_WARNING &&
1863         U_SUCCESS(mError)){
1864 
1865 		UnicodeString tempStr;
1866 
1867 		writeFormat("decimalFormats","decimalFormatLength","decimalFormatStart","decimalFormatEnd",NULL,dtPatterns.getStringEx((int32_t)0,mError),xmlString,FALSE);
1868 		writeFormat("scientificFormats","scientificFormatLength","scientificFormatStart","scientificFormatEnd",NULL,dtPatterns.getStringEx((int32_t)3,mError),xmlString,FALSE);
1869 		writeFormat("percentFormats","percentFormatLength","percentFormatStart","percentFormatEnd",NULL,dtPatterns.getStringEx((int32_t)2,mError),xmlString,FALSE);
1870 		writeFormat("currencyFormats","currencyFormatLength","currencyFormatStart","currencyFormatEnd",NULL,dtPatterns.getStringEx((int32_t)1,mError),xmlString,FALSE);
1871 
1872         if(mError == U_MISSING_RESOURCE_ERROR){
1873 			mError = U_ZERO_ERROR;
1874 		}
1875 
1876 	}
1877 
1878 	mError= U_ZERO_ERROR;
1879 }
1880 
1881 
writeCurrencies(UnicodeString & xmlString)1882 void GenerateXML::writeCurrencies(UnicodeString& xmlString){
1883 
1884 	UnicodeString tempStr;
1885 	Formattable args[2] = { indentOffset,"" };
1886 	UnicodeString t;
1887 	xmlString.append(formatString(mStringsBundle.getStringEx("currencies",mError),args,2,t));
1888 	indentOffset.append("\t");
1889 	writeCurrency(tempStr);
1890 	if(!tempStr.isEmpty()){
1891 
1892 		xmlString.append(tempStr);
1893 		chopIndent();
1894 		args[0] = indentOffset;
1895 		args[1] = UnicodeString(XML_END_SLASH);
1896 		xmlString.append(formatString(mStringsBundle.getStringEx("currencies",mError),args,2,t));
1897 		//printString(&xmlString);
1898         mError = U_ZERO_ERROR;
1899         return;
1900 	}
1901 
1902 	xmlString.remove();
1903 
1904 	chopIndent();
1905 	mError= U_ZERO_ERROR;
1906 }
1907 
1908 
writeCurrency(UnicodeString & xmlString)1909 void GenerateXML::writeCurrency(UnicodeString& xmlString){
1910 
1911 	UBool isDefault =TRUE;
1912 	ResourceBundle currency =mSourceBundle.get("Currencies", mError);
1913     UnicodeString t;
1914 
1915     if( U_SUCCESS(mError)  &&
1916         mError != U_USING_FALLBACK_WARNING &&
1917         mError != U_USING_DEFAULT_WARNING){
1918 
1919         while(currency.hasNext()){
1920 			ResourceBundle dBundle1 = currency.getNext(mError);
1921             const char* mykey=dBundle1.getKey();
1922 
1923             UnicodeString symbol = dBundle1.getStringEx((int32_t)0, mError);
1924             UnicodeString displayName = dBundle1.getStringEx((int32_t)1, mError);
1925 		    Formattable args[] = {indentOffset,UnicodeString(mykey),""};
1926 
1927 		    //xmlString.append(formatString(mStringsBundle.getStringEx( "default",mError),args,2,t));
1928 		    xmlString.append(formatString(mStringsBundle.getStringEx("currencyStart",mError),args,3,t));
1929 
1930 		    indentOffset.append("\t");
1931 
1932 		    args[0] = indentOffset;
1933 		    args[1] = displayName;
1934 		    xmlString.append(formatString(mStringsBundle.getStringEx("displayName",mError),args,2,t));
1935 
1936             escape(symbol);
1937             args[1] = symbol;
1938 		    xmlString.append(formatString(mStringsBundle.getStringEx("symbol",mError),args,2,t));
1939 
1940             int32_t size = dBundle1.getSize();
1941             if(size>2){
1942                 ResourceBundle elements = dBundle1.get((int32_t)2, mError);
1943                 UnicodeString key = elements.getKey();
1944                 if(elements.getType()!= URES_ARRAY){
1945                     fprintf(stderr,"Did not get the expected type for Elements\n");
1946                     exit(-1);
1947                 }
1948                 if(U_SUCCESS(mError)){
1949                     UnicodeString pattern = elements.getStringEx((int32_t)0, mError);
1950                     UnicodeString decimalSep = elements.getStringEx((int32_t)1, mError);
1951                     UnicodeString groupSep = elements.getStringEx((int32_t)2, mError);
1952 
1953                     args[1] = pattern;
1954                     xmlString.append(formatString(mStringsBundle.getStringEx("pattern",mError),args,2,t));
1955 
1956                     args[1] = decimalSep;
1957                     xmlString.append(formatString(mStringsBundle.getStringEx("decimal",mError),args,2,t));
1958 
1959                     args[1] = groupSep;
1960                     xmlString.append(formatString(mStringsBundle.getStringEx("group",mError),args,2,t));
1961 
1962                 }
1963             }
1964             chopIndent();
1965             args[0] = indentOffset;
1966             args[1] = "";
1967             xmlString.append(formatString(mStringsBundle.getStringEx("currencyEnd",mError),args,2,t));
1968 
1969 
1970 	    }
1971 		return;
1972     }
1973 
1974 	xmlString.remove();
1975 	mError=U_ZERO_ERROR;
1976 }
1977 
writeSpecial()1978 void GenerateXML::writeSpecial(){
1979     if(ignoreSpecials == FALSE){
1980 	    UnicodeString xmlString, tempStr;
1981 	    Formattable args[]={indentOffset,mStringsBundle.getStringEx("xmlns_icu",mError),"",""};
1982 	    UnicodeString t;
1983 	    xmlString.append(formatString(mStringsBundle.getStringEx( "special",mError),args,4,t));
1984 	    indentOffset.append("\t");
1985 	    UBool print = FALSE;
1986 
1987 	    writeBoundary(tempStr);
1988 	    if(!tempStr.isEmpty()){
1989 		    xmlString.append(tempStr);
1990 		    print = TRUE;
1991 	    }
1992 	    tempStr.remove();
1993 	    writeRuleBasedNumberFormat(tempStr);
1994 	    if(!tempStr.isEmpty()){
1995 		    xmlString.append(tempStr);
1996 		    print = TRUE;
1997 	    }
1998 	    chopIndent();
1999 	    args[1]=UnicodeString(XML_END_SLASH);
2000 	    xmlString.append(formatString(mStringsBundle.getStringEx( "specialEnd",mError),args,2,t));
2001 	    if(print) printString(&xmlString);
2002     }
2003 }
2004 
writeRuleBasedNumberFormat(UnicodeString & xmlString)2005 void GenerateXML::writeRuleBasedNumberFormat(UnicodeString& xmlString){
2006     if(ignoreSpecials == FALSE){
2007 	    UnicodeString tempStr;
2008 	    Formattable args[] = {indentOffset,"","",""};
2009 	    UBool print = FALSE;
2010 	    UnicodeString t;
2011 
2012         xmlString.append(formatString(mStringsBundle.getStringEx("ruleBasedNFS",mError),args,2,t));
2013 	    indentOffset.append("\t");
2014 
2015 	    UnicodeString spellout = mSourceBundle.getStringEx("SpelloutRules",mError);
2016 	    if( mError != U_USING_DEFAULT_WARNING &&
2017 		    U_SUCCESS(mError) &&
2018 		    mError != U_USING_FALLBACK_WARNING){
2019 		    escape(spellout);
2020 		    args[0] = indentOffset;
2021 		    args[1] = "spellout";
2022 		    args[2] = spellout;
2023             args[3] = indentOffset;
2024 		    tempStr.append(formatString(mStringsBundle.getStringEx("ruleBasedNF",mError),args,4,t));
2025 
2026 	    }
2027 
2028 	    mError=U_ZERO_ERROR;
2029 	    UnicodeString ordinal = mSourceBundle.getStringEx("OrdinalRules", mError);
2030 	    if( mError != U_USING_DEFAULT_WARNING &&
2031 		    U_SUCCESS(mError) &&
2032 		    mError != U_USING_FALLBACK_WARNING){
2033 		    escape(ordinal);
2034 		    args[0] = indentOffset;
2035 		    args[1] = "ordinal";
2036 		    args[2] = ordinal;
2037             args[3] = indentOffset;
2038 		    tempStr.append(formatString(mStringsBundle.getStringEx("ruleBasedNF",mError),args,4,t));
2039 	    }
2040 
2041 	    mError=U_ZERO_ERROR;
2042 	    UnicodeString duration = mSourceBundle.getStringEx("DurationRules", mError);
2043 	    if( mError != U_USING_DEFAULT_WARNING &&
2044 		    U_SUCCESS(mError) &&
2045 		    mError != U_USING_FALLBACK_WARNING){
2046 		    escape(duration);
2047 		    args[0] = indentOffset;
2048 		    args[1] = "duration";
2049 		    args[2] = duration;
2050             args[3] = indentOffset;
2051 		    tempStr.append(formatString(mStringsBundle.getStringEx("ruleBasedNF",mError),args,4,t));
2052 	    }
2053 	    if(tempStr.isEmpty()){
2054 		    xmlString.remove();
2055 	    }else{
2056 		    chopIndent();
2057 		    xmlString.append(tempStr);
2058 		    args[0] = indentOffset;
2059 		    args[1] = UnicodeString(XML_END_SLASH);
2060 	        xmlString.append(formatString(mStringsBundle.getStringEx("ruleBasedNFS",mError),args,2,t));
2061 	    }
2062 	    mError= U_ZERO_ERROR;
2063     }
2064 }
2065 /*
2066 void GenerateXML::writeTransliteration(){
2067 	UnicodeString xmlString;
2068 	const UnicodeString translit= mSourceBundle.getStringEx("TransliteratorNamePattern",mError);
2069 	if(mError != U_USING_DEFAULT_WARNING && mError!=U_USING_FALLBACK_WARNING && U_SUCCESS(mError)){
2070 		Formattable args[] = {indentOffset,translit};
2071 		xmlString.append(formatString(UnicodeString(TL_NAME),args,2));
2072 		printString(&xmlString);
2073 	}
2074 	mError=U_ZERO_ERROR;
2075 }
2076 */
writeCharBrkRules(UnicodeString & xmlString)2077 void GenerateXML::writeCharBrkRules(UnicodeString& xmlString){
2078 
2079     ResourceBundle brkRules = mSourceBundle.get("CharacterBreakRules",mError);
2080 	UnicodeString t;
2081 	if( mError != U_USING_DEFAULT_WARNING &&
2082 		mError != U_USING_FALLBACK_WARNING &&
2083 		U_SUCCESS(mError)){
2084 
2085 		xmlString.append(formatString(mStringsBundle.getStringEx("graphemeStart",mError),indentOffset,t));
2086 		indentOffset.append("\t");
2087         while(brkRules.hasNext()){
2088 			UnicodeString rule =brkRules.getNextString(mError);
2089 			escape(rule);
2090 			xmlString.append("\n");
2091 			xmlString.append(indentOffset);
2092 			xmlString.append(rule);
2093 		}
2094 		xmlString.append("\n\n");
2095 		chopIndent();
2096 		xmlString.append(formatString(mStringsBundle.getStringEx("graphemeEnd",mError),indentOffset,t));
2097 		return;
2098 	}
2099 	xmlString.remove();
2100 	mError= U_ZERO_ERROR;
2101 
2102 }
2103 
writeSentBrkRules(UnicodeString & xmlString)2104 void GenerateXML::writeSentBrkRules(UnicodeString& xmlString){
2105 
2106 	ResourceBundle brkRules = mSourceBundle.get("SentenceBreakRules",mError);
2107 	UnicodeString t;
2108 	xmlString.append(formatString(mStringsBundle.getStringEx("sentenceStart",mError),indentOffset,t));
2109 	if( mError != U_USING_DEFAULT_WARNING &&
2110 		mError != U_USING_FALLBACK_WARNING &&
2111 		U_SUCCESS(mError)){
2112 		indentOffset.append("\t");
2113         while(brkRules.hasNext()){
2114 			UnicodeString rule =brkRules.getNextString(mError);
2115 			escape(rule);
2116 			xmlString.append("\n");
2117 			xmlString.append(indentOffset);
2118 			xmlString.append(rule);
2119 		}
2120 		xmlString.append("\n\n");
2121 		chopIndent();
2122 		xmlString.append(formatString(mStringsBundle.getStringEx("graphemeEnd",mError),indentOffset,t));
2123 		return;
2124 	}
2125 	xmlString.remove();
2126 	mError= U_ZERO_ERROR;
2127 
2128 }
writeLineBrkRules(UnicodeString & xmlString)2129 void GenerateXML::writeLineBrkRules(UnicodeString& xmlString){
2130 
2131 	ResourceBundle brkRules = mSourceBundle.get("LineBreakRules",mError);
2132 	UnicodeString t;
2133 	xmlString.append(formatString(mStringsBundle.getStringEx("lineStart",mError),indentOffset,t));
2134 
2135 	if( mError != U_USING_DEFAULT_WARNING &&
2136 		mError != U_USING_FALLBACK_WARNING &&
2137 		U_SUCCESS(mError)){
2138 	   indentOffset.append("\t");
2139        while(brkRules.hasNext()){
2140 			UnicodeString rule =brkRules.getNextString(mError);
2141 			escape(rule);
2142 			xmlString.append("\n");
2143 			xmlString.append(indentOffset);
2144 			xmlString.append(rule);
2145 		}
2146 		xmlString.append("\n\n");
2147 		chopIndent();
2148 		xmlString.append(formatString(mStringsBundle.getStringEx("lineEnd",mError),indentOffset,t));
2149 		return;
2150 	}
2151 	xmlString.remove();
2152 	mError= U_ZERO_ERROR;
2153 }
2154 
writeBoundary(UnicodeString & xmlString)2155 void GenerateXML::writeBoundary(UnicodeString& xmlString){
2156 	UnicodeString tempStr;
2157 	UBool print=FALSE;
2158 	Formattable args[3] = { indentOffset,"",""};
2159 	UnicodeString t;
2160 	xmlString.append(formatString(mStringsBundle.getStringEx("boundaries",mError),args,2,t));
2161 	indentOffset.append("\t");
2162 
2163 	writeCharBrkRules(tempStr);
2164 	if(!tempStr.isEmpty()){
2165 		xmlString.append(tempStr);
2166 		print = TRUE;
2167 	}
2168 	tempStr.remove();
2169 	writeSentBrkRules(tempStr);
2170 	if(!tempStr.isEmpty()){
2171 		xmlString.append(tempStr);
2172 		print = TRUE;
2173 	}
2174 	tempStr.remove();
2175 	writeLineBrkRules(tempStr);
2176 	if(!tempStr.isEmpty()){
2177 		xmlString.append(tempStr);
2178 		print = TRUE;
2179 	}
2180 	tempStr.remove();
2181 	chopIndent();
2182 	xmlString.append(formatString(mStringsBundle.getStringEx("boundaries",mError),args,2,t));
2183 
2184 	if(!print) xmlString.remove();
2185 }
2186 
2187 
writeCollations()2188 void GenerateXML::writeCollations(){
2189 	UnicodeString tempStr,xmlString;
2190 	UBool print=FALSE;
2191 	Formattable args[3] = { indentOffset,""};
2192 	UnicodeString t;
2193 	xmlString.append(formatString(mStringsBundle.getStringEx("collations",mError),args,2,t));
2194 	indentOffset.append("\t");
2195 
2196     ResourceBundle dBundle = mSourceBundle.get("collations", mError);
2197 
2198     if(U_SUCCESS(mError)){
2199 
2200         while(dBundle.hasNext()){
2201             writeCollation(dBundle.getNext(mError), tempStr);
2202             if(tempStr.length()!=0){
2203                 xmlString.append(tempStr);
2204                 print =TRUE;
2205             }
2206             tempStr.remove();
2207         }
2208 
2209     }
2210 
2211 	/*writeSentBrkRules(tempStr);
2212 	if(!tempStr.isEmpty()){
2213 		xmlString.append(tempStr);
2214 		print = TRUE;
2215 	}
2216 	tempStr.remove();
2217 	writeLineBrkRules(tempStr);
2218 	if(!tempStr.isEmpty()){
2219 		xmlString.append(tempStr);
2220 		print = TRUE;
2221 	}*/
2222 	chopIndent();
2223 
2224     args[1]=UnicodeString(XML_END_SLASH);
2225 	args[2]="";
2226     xmlString.append(formatString(mStringsBundle.getStringEx("collations",mError),args,3,t));
2227 
2228 	if(print)  printString(&xmlString);
2229     mError =U_ZERO_ERROR;
2230 
2231 }
2232 
writeBase(UnicodeString & xmlString)2233 void GenerateXML::writeBase(UnicodeString& xmlString){
2234     if(baseCollation != NULL){
2235         Formattable args[] = {indentOffset, "", ""};
2236         UnicodeString temp;
2237         xmlString.append(formatString(mStringsBundle.getStringEx("baseStart", mError), args, 1, temp));
2238         indentOffset.append("\t");
2239 
2240         args[0] = indentOffset;
2241         args[1] = baseCollation;
2242         args[2] = (baseType==NULL) ? "standard" : baseType;
2243         xmlString.append(formatString(mStringsBundle.getStringEx("alias", mError), args, 3, temp));
2244 
2245         chopIndent();
2246 
2247         args[0] = indentOffset;
2248         xmlString.append(formatString(mStringsBundle.getStringEx("baseEnd", mError), args, 1, temp));
2249     }
2250 
2251     if(U_FAILURE(mError)){
2252         mError = U_ZERO_ERROR;
2253         xmlString.remove();
2254     }
2255 }
2256 
writeUCARules(UnicodeString & sequence,UnicodeString & xmlString)2257 void GenerateXML::writeUCARules(UnicodeString& sequence,UnicodeString& xmlString){
2258 
2259     UnicodeString rules;
2260     const char* key = "UCA";
2261 
2262     UnicodeString t;
2263     if( mError!=U_USING_DEFAULT_WARNING &&
2264 		U_SUCCESS(mError) &&
2265 		mError!=U_USING_FALLBACK_WARNING){
2266         Formattable args[]={indentOffset,"","","",""};
2267 
2268 		UnicodeString str = "type=\"";
2269 		str.append(key);
2270 		str.append("\"");
2271 		args[2] = str;
2272 
2273 		xmlString.append(formatString(mStringsBundle.getStringEx("collation",mError),args,3,t));
2274 
2275 		indentOffset.append("\t");
2276 
2277         // wirte the base element
2278         writeBase(t.remove());
2279         if(t.length() != 0){
2280             xmlString.append(t);
2281         }
2282 
2283 		rules = parseRules((UChar*)sequence.getBuffer(),sequence.length(),rules);
2284 		xmlString.append(rules);
2285         sequence.releaseBuffer();
2286 
2287         chopIndent();
2288 		args[0] = indentOffset;
2289 		args[1] = "/";
2290 		args[2] ="";
2291 		xmlString.append(formatString(mStringsBundle.getStringEx("collation",mError),args,3,t));
2292         //printString(&xmlString);
2293     }
2294     mError = U_ZERO_ERROR;
2295 }
2296 
writeCollation(ResourceBundle & bundle,UnicodeString & xmlString,UnicodeString * collKey)2297 void GenerateXML::writeCollation(ResourceBundle& bundle,UnicodeString& xmlString, UnicodeString* collKey){
2298 
2299     UnicodeString version;
2300     UnicodeString overide="FALSE";
2301     UnicodeString sequence;
2302     UnicodeString rules;
2303     const char* key = bundle.getKey();
2304     UnicodeString t;
2305     if(stricmp(key, "default") == 0) {
2306         Formattable args[]={indentOffset,"","","",""};
2307                sequence = bundle.getString(mError);
2308                args[0] = indentOffset;
2309                args[1] = sequence;
2310                xmlString.append(formatString(mStringsBundle.getStringEx("default",mError),args,2,t));
2311     }else {
2312         if( mError!=U_USING_DEFAULT_WARNING &&
2313 		    U_SUCCESS(mError) &&
2314 		    mError!=U_USING_FALLBACK_WARNING){
2315             Formattable args[]={indentOffset,"","","",""};
2316 
2317 		    UnicodeString str = "type=\"";
2318 		    str.append(key);
2319 		    str.append("\"");
2320 		    args[2] = str;
2321 
2322 		    xmlString.append(formatString(mStringsBundle.getStringEx("collation",mError),args,3,t));
2323 
2324 		    indentOffset.append("\t");
2325 
2326             // wirte the base element
2327             writeBase(t.remove());
2328             if(t.length() != 0){
2329                 xmlString.append(t);
2330             }
2331 
2332 		    while(bundle.hasNext()){
2333                 ResourceBundle dBundle1 = bundle.getNext(mError);
2334                 const char* mykey=dBundle1.getKey();
2335                 if(stricmp(mykey,"Version")==0 && ignoreSpecials==FALSE){
2336                     version = bundle.getStringEx(mykey,mError);
2337 			        UnicodeString temp = UnicodeString("icu:version=\"").append(version);
2338 			        temp.append("\"");
2339 			        args[0] = indentOffset;
2340                     args[1] = mStringsBundle.getStringEx("xmlns_icu",mError);
2341 			        args[2] = temp;
2342 			        args[3] = UnicodeString(XML_END_SLASH);
2343 			        xmlString.append(formatString(mStringsBundle.getStringEx("special",mError),args,4,t));
2344                 }else if(stricmp(mykey,"Sequence")==0 && onlySpecials==FALSE){
2345                     sequence = bundle.getStringEx(mykey,mError);
2346 				    rules = parseRules((UChar*)sequence.getBuffer(),sequence.length(),rules);
2347 				    xmlString.append(rules);
2348                     sequence.releaseBuffer();
2349 
2350                 }else if(stricmp(mykey,"Override")==0 && onlySpecials==FALSE){
2351                         overide =  bundle.getStringEx(mykey,mError);
2352                 }
2353             }
2354 
2355             chopIndent();
2356 		    args[0] = indentOffset;
2357 		    args[1] = "/";
2358 		    args[2] ="";
2359 		    xmlString.append(formatString(mStringsBundle.getStringEx("collation",mError),args,3,t));
2360             //printString(&xmlString);
2361         }
2362     }
2363     mError = U_ZERO_ERROR;
2364 }
appendHex(uint32_t number,int32_t digits,UnicodeString & target)2365 UnicodeString& appendHex(uint32_t number,
2366             int32_t digits,
2367             UnicodeString& target)
2368 {
2369     static const UChar digitString[] = {
2370         0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
2371         0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0
2372     }; /* "0123456789ABCDEF" */
2373 
2374     switch (digits)
2375     {
2376     case 8:
2377         target += digitString[(number >> 28) & 0xF];
2378     case 7:
2379         target += digitString[(number >> 24) & 0xF];
2380     case 6:
2381         target += digitString[(number >> 20) & 0xF];
2382     case 5:
2383         target += digitString[(number >> 16) & 0xF];
2384     case 4:
2385         target += digitString[(number >> 12) & 0xF];
2386     case 3:
2387         target += digitString[(number >>  8) & 0xF];
2388     case 2:
2389         target += digitString[(number >>  4) & 0xF];
2390     case 1:
2391         target += digitString[(number >>  0) & 0xF];
2392         break;
2393     default:
2394         target += "**";
2395     }
2396     return target;
2397 }
2398 
2399 
2400 // Replace nonprintable characters with unicode escapes
prettify(const UnicodeString & source,UnicodeString & target)2401 UnicodeString& prettify(const UnicodeString &source,UnicodeString &target)
2402 {
2403     int32_t i;
2404 
2405     target.remove();
2406     target += "\"";
2407 
2408     for (i = 0; i < source.length(); )
2409     {
2410         UChar32 ch = source.char32At(i);
2411         i += UTF_CHAR_LENGTH(ch);
2412 
2413         if (ch < 0x09 || (ch > 0x0A && ch < 0x20)|| ch > 0x7E)
2414         {
2415             if (ch <= 0xFFFF) {
2416                 target += "\\u";
2417                 appendHex(ch, 4, target);
2418             } else {
2419                 target += "\\U";
2420                 appendHex(ch, 8, target);
2421             }
2422         }
2423         else
2424         {
2425             target += ch;
2426         }
2427     }
2428 
2429     target += "\"";
2430 
2431     return target;
2432 }
2433 
2434 #define UCOL_TOK_UNSET    0xFFFFFFFF
2435 #define UCOL_TOK_RESET    0xDEADBEEF
2436 #define UCOL_TOK_SETTING  0xFFFFFFFE
2437 #define UCOL_TOK_OVERRIDE 0xFFFFFFFD
2438 #define UCOL_TOK_DONE     0xFFFFFFFC
2439 #define UCOL_TOK_EXPANSION_MARKER 0xFFFF
2440 
2441 UBool
uprv_isRuleWhiteSpace(UChar32 c)2442 uprv_isRuleWhiteSpace(UChar32 c) {
2443     /* "white space" in the sense of ICU rule parsers: Cf+White_Space */
2444     return
2445         u_charType(c)==U_FORMAT_CHAR ||
2446         u_hasBinaryProperty(c, UCHAR_WHITE_SPACE);
2447 }
2448 /*
2449 strength  	    primary (1)         [strength 1] 	                strength = "primary"
2450                 secondary (2)
2451                 tertiary (3)
2452                 quarternary (4)
2453                 identical (5)
2454 
2455 alternate 	    non-ignorable       [alternate non-ignorable] 	    alternate = "non-ignorable"
2456                 shifted
2457 
2458 backwards 	    on                  [backwards on]   	            backwards = "on"
2459                 off
2460 
2461 normalization 	on
2462                 off 	            [normalization on]  	        normalization = "off"
2463 
2464 caseLevel 	    on                  [caseLevel on] 	                caseLevel = "off"
2465                 off
2466 
2467 caseFirst 	    upper               [caseFirst off] 	            caseFirst = "off"
2468                 lower
2469                 off
2470 
2471 hiraganaQ 	    on                  [hiraganaQ on] 	                hiragana�Quarternary = "on"
2472                 off
2473 
2474 numeric 	    on                  [numeric on] 	                numeric = "on"
2475                 off
2476 */
2477 
writeSettings(UnicodeString & src,UnicodeString & xmlString)2478 void GenerateXML::writeSettings(UnicodeString& src , UnicodeString& xmlString){
2479 	const UChar* saveStart = src.getBuffer();
2480     const UChar* start = saveStart;
2481 	const UChar* limit = start + src.length();
2482 	int32_t valueLen=0,settingLen =0;
2483 	UBool isValue = FALSE;
2484 	UnicodeString t;
2485     int32_t index = 0;
2486     UnicodeString setting, value;
2487     Formattable args[] = {indentOffset, "", "" };
2488     while(index < src.length()){
2489         index = getSettingAndValue(src, index, setting, value);
2490         if(setting == "suppressContractions"){
2491 		    args[1] = value;
2492 			xmlString.append(formatString(mStringsBundle.getStringEx("suppressContractions",mError),args,2,t));
2493         }else if(setting =="optimize"){
2494             args[1] = value;
2495             xmlString.append(formatString(mStringsBundle.getStringEx("optimize",mError),args,2,t));
2496         }else{
2497             if(setting == "strength"){
2498                 UChar val = value.charAt(0);
2499                 value.remove();
2500                 switch (val){
2501                     case '1':
2502                         value.append("primary");
2503                         break;
2504                     case '2':
2505                         value.append("secondary");
2506                         break;
2507                     case '3':
2508                         value.append("tertiary");
2509                         break;
2510                     case '4':
2511                         value.append("quaternary");
2512                         break;
2513                     case '5':
2514                         value.append("identical");
2515                         break;
2516                     default:
2517                         mError = U_ILLEGAL_ARGUMENT_ERROR;
2518                         exit (mError);
2519                     }
2520             }else if(setting == "alternate"){
2521             }else if(setting == "backwards"){
2522                 if(value == "2"){
2523                     value.remove();
2524                     value.append ("on");
2525                 }else{
2526                     fprintf(stderr, "Unrecognized value for setting backwards!.");
2527                     exit(-1);
2528                 }
2529             }else if(setting == "normalization"){
2530             }else if(setting == "caseLevel"){
2531             }else if(setting == "casefirst"){
2532                 setting = "caseFirst";
2533             }else if(setting == "hiraganaQ"){
2534                 setting = "hiraganaQuarternary";
2535             }else if(setting == "numeric"){
2536             }else{
2537                 fprintf(stderr,"Could not recogize setting!!");
2538                 exit(-1);
2539             }
2540             mSettings.append(setting);
2541             mSettings.append("=\"");
2542             mSettings.append(value);
2543             mSettings.append("\" ");
2544         }
2545         setting.remove();
2546         value.remove();
2547     }
2548 }
2549 
getSettingAndValue(UnicodeString & source,int32_t index,UnicodeString & setting,UnicodeString & value)2550 int32_t GenerateXML::getSettingAndValue(UnicodeString& source, int32_t index, UnicodeString& setting, UnicodeString& value){
2551     const UChar* src = source.getBuffer();
2552     int32_t start = index;
2553     int32_t end = source.length();
2554     int32_t open=0;
2555     UBool startVal=FALSE, initialSpace = TRUE;
2556     /* [ setting value ]*/
2557     while(start < end){
2558         UChar ch = src[start++];
2559         switch(ch){
2560             case '[':
2561                 open++;
2562                 if(open > 1 && startVal==TRUE){
2563                     value.append(ch);
2564                 }
2565                 break;
2566             case ']':
2567                 if(open > 1 && startVal==TRUE){
2568                     value.append(ch);
2569                 }else if(open == 1){
2570                     goto OUTER;
2571                 }
2572                 open--;
2573 
2574             case ' ':
2575                 if(initialSpace){
2576                     break;
2577                 }
2578                 startVal = TRUE;
2579                 break;
2580             default:
2581                 initialSpace = FALSE;
2582                 if(startVal == TRUE){
2583                     value.append(ch);
2584                 }else{
2585                     setting.append(ch);
2586                 }
2587         }
2588     }
2589 OUTER:
2590     source.releaseBuffer();
2591     return start;
2592 }
writeReset(UnicodeString & src,UnicodeString & xmlString)2593 void GenerateXML::writeReset(UnicodeString& src, UnicodeString& xmlString){
2594 	const UChar* start = src.getBuffer();
2595 	const UChar* limit = start + src.length();
2596 	UChar setting[256];
2597 	UChar value[20];
2598 	UChar chars[20];
2599 	UnicodeString t;
2600 	char* target;
2601 	int32_t valueLen=0,settingLen =0, charsLen=0;
2602 	UBool isValue = FALSE, isChars=FALSE;
2603 	if(src.indexOf("top")>=0 || src.indexOf("last regular")>=0){
2604 		Formattable args[] = {indentOffset, mStringsBundle.getStringEx("lastNonIgnorable",mError)};
2605 		xmlString.append(formatString(mStringsBundle.getStringEx("reset",mError),args,2,t));
2606 
2607     }else if(src.indexOf("first primary ignorable")>=0){
2608 		Formattable args[] = {indentOffset, mStringsBundle.getStringEx("firstPIgnorable",mError)};
2609 		xmlString.append(formatString(mStringsBundle.getStringEx("reset",mError),args,2,t));
2610 
2611     }else if(src.indexOf("first secondary ignorable")>=0){
2612 		Formattable args[] = {indentOffset, mStringsBundle.getStringEx("firstSIgnorable",mError)};
2613 		xmlString.append(formatString(mStringsBundle.getStringEx("reset",mError),args,2,t));
2614 
2615     }else if(src.indexOf("first tertiary ignorable")>=0){
2616 		Formattable args[] = {indentOffset, mStringsBundle.getStringEx("fristTIgnorable",mError)};
2617 		xmlString.append(formatString(mStringsBundle.getStringEx("reset",mError),args,2,t));
2618 
2619     }else if(src.indexOf("last primary ignorable")>=0){
2620 		Formattable args[] = {indentOffset, mStringsBundle.getStringEx("lastPIgnorable",mError)};
2621 		xmlString.append(formatString(mStringsBundle.getStringEx("reset",mError),args,2,t));
2622 
2623     }else if(src.indexOf("last secondary ignorable")>=0){
2624 		Formattable args[] = {indentOffset, mStringsBundle.getStringEx("lastSIgnorable",mError)};
2625 		xmlString.append(formatString(mStringsBundle.getStringEx("reset",mError),args,2,t));
2626 
2627     }else if(src.indexOf("last tertiary ignorable")>=0){
2628 		Formattable args[] = {indentOffset, mStringsBundle.getStringEx("lastTIgnorable",mError)};
2629 		xmlString.append(formatString(mStringsBundle.getStringEx("reset",mError),args,2,t));
2630     }else if(src.indexOf("[")>=0 && src.length() > 1){
2631 		while(start < limit ){
2632 			UChar ch = *start++;
2633 			if(uprv_isRuleWhiteSpace(ch)){
2634 				if(settingLen>0){
2635 					isValue = TRUE;
2636 				}else if(valueLen>0){
2637 					isChars = TRUE;
2638 				}
2639 				continue; //skip white spaces
2640 			}else if(ch == 0x5b){ // skip '[' && ']'
2641 				continue;
2642             }else if( ch == 0x5d ){
2643                 isValue = FALSE;
2644                 isChars = TRUE;
2645                 continue;
2646             }
2647 			if(isValue){
2648 				value[valueLen++] = ch;
2649 			}else if(isChars){
2650 				chars[charsLen++] =ch;
2651 			}else{
2652 				setting[settingLen++] = ch;
2653 			}
2654 		}
2655 		switch(value[0]){
2656 		case 0x31:
2657 			target = "primary";
2658 			break;
2659 		case 0x32:
2660 			target = "secondary";
2661 			break;
2662 		case 0x33:
2663 			target = "tertiary";
2664 			break;
2665 		case 0x34:
2666 			target = "quaternary";
2667 			break;
2668 		default:
2669 			target = "unknown";
2670 			break;
2671 		}
2672 		Formattable args[] = {indentOffset, UnicodeString(setting,settingLen), UnicodeString(target), UnicodeString(chars,charsLen)};
2673 		xmlString.append(formatString(mStringsBundle.getStringEx("resetWithValue",mError),args,4,t));
2674 	}else{
2675 		Formattable args[] = {indentOffset, src};
2676 		xmlString.append(formatString(mStringsBundle.getStringEx("reset",mError),args,2,t));
2677 	}
2678 }
parseRules(UChar * rules,int32_t ruleLen,UnicodeString & xmlString)2679 UnicodeString GenerateXML::parseRules(UChar* rules, int32_t ruleLen, UnicodeString& xmlString){
2680 	Token src;
2681 	src.start = rules;
2682 	src.current = rules;
2683 	src.prevCurrent = rules;
2684 	src.end = rules+ruleLen;
2685 	src.chars=(UChar*) malloc((ruleLen + 10)* U_SIZEOF_UCHAR);
2686 	src.charsCapacity = ruleLen+10;
2687 	UnicodeString collStr ;
2688 	uint32_t prevStrength=UCOL_DEFAULT;
2689 	int32_t count = 0;
2690 	UBool appendedRules = FALSE;
2691     UnicodeString t;
2692 	UBool startOfRules = TRUE;
2693     UBool writtenSettings = FALSE;
2694     UBool isTempStrContraction =FALSE, isCollStrContraction = FALSE;
2695 
2696 	if(src.start != src.end){
2697 		for(;;){
2698 
2699 			  uint32_t strength = parseRules(&src,startOfRules);
2700 			  UnicodeString tempStr;
2701 			  startOfRules = FALSE;
2702 			  tempStr.append(src.chars,src.charsLen);
2703               if(U_FAILURE(mError)){
2704                   fprintf(stderr,"parseRules returned NULL for strength!. Error: %s", u_errorName(mError));
2705                   exit(1);
2706               }
2707             //  int32_t indexOfPipe = tempStr.indexOf((UChar)0x7c);
2708 
2709               if((prevStrength == strength) && (prevStrength == UCOL_TOK_DONE)){
2710                   if(mSettings.length()!=0 && writtenSettings == FALSE){
2711                       Formattable args[]={ indentOffset, mSettings} ;
2712                         xmlString.append(formatString(mStringsBundle.getStringEx("settings",mError),args,2,t));
2713                         writtenSettings = TRUE;
2714                         mSettings.truncate(0);
2715                   }
2716                   break;
2717               }
2718 
2719 
2720               /* verify that tempStr is a contraction */
2721               isTempStrContraction = tempStr.countChar32()>1;
2722 
2723 			  if((prevStrength != strength) ||
2724                   isTempStrContraction==TRUE/* contraction */ ||
2725                   isCollStrContraction==TRUE/* contraction */ ||
2726                   tempStr.indexOf((UChar)UCOL_TOK_EXPANSION_MARKER) >=0 || /* expansion */
2727                   collStr.indexOf((UChar)UCOL_TOK_EXPANSION_MARKER) >=0 ||/* expansion */
2728                   tempStr.indexOf((UChar)0x7c) >=0 || /*context */
2729                   collStr.indexOf((UChar)0x7c) >=0 /*context*/){
2730 
2731 					char* singleKey = NULL;
2732 					char* seqKey = NULL;
2733 					// assume that settings always preceed rule strings
2734 
2735 					Formattable args[] = {indentOffset,collStr,""};
2736 					if(prevStrength != UCOL_DEFAULT){
2737 						if(prevStrength == UCOL_TOK_SETTING){
2738 							writeSettings(collStr,xmlString);
2739 						}else if(prevStrength==UCOL_TOK_RESET){
2740                             if(writtenSettings == FALSE && mSettings.length() > 0){
2741                                 args[0] = indentOffset;
2742                                 args[1] = mSettings;
2743                                 xmlString.append(formatString(mStringsBundle.getStringEx("settings",mError),args,2,t));
2744                                 writtenSettings = TRUE;
2745                                 mSettings.truncate(0);
2746                             }
2747 							if(appendedRules == FALSE){
2748 								args[0] = indentOffset;
2749 								args[1] = "";
2750 								xmlString.append(formatString(mStringsBundle.getStringEx("rules",mError),args,2,t));
2751 								indentOffset.append("\t");
2752 								appendedRules = TRUE;
2753 							}
2754                             escape(collStr);
2755 							writeReset(collStr,xmlString);
2756 						}else if(prevStrength==UCOL_TOK_OVERRIDE){
2757                             UnicodeString temp("[backwards on]");
2758                             writeSettings(temp,xmlString);
2759 						}else{
2760                             if(writtenSettings == FALSE && mSettings.length() > 0){
2761                                 args[0] = indentOffset;
2762                                 args[1] = mSettings;
2763                                 xmlString.append(formatString(mStringsBundle.getStringEx("settings",mError),args,2,t));
2764                                 writtenSettings = TRUE;
2765                                 mSettings.truncate(0);
2766                             }
2767 							if(appendedRules == FALSE){
2768 								args[0] = indentOffset;
2769 								args[1] = "";
2770 								xmlString.append(formatString(mStringsBundle.getStringEx("rules",mError),args,2,t));
2771 								indentOffset.append("\t");
2772 								appendedRules = TRUE;
2773 							}
2774                             args[1] = collStr;
2775 							switch(prevStrength){
2776 							case UCOL_IDENTICAL:
2777 								singleKey = "identical";
2778 								seqKey = "identicalSeq";
2779 								break;
2780 							case UCOL_PRIMARY:
2781 								singleKey = "primary";
2782 								seqKey = "primarySeq";
2783 								break;
2784 							case UCOL_SECONDARY:
2785 								singleKey = "secondary";
2786 								seqKey = "secondarySeq";
2787 								break;
2788 							case UCOL_TERTIARY:
2789 								singleKey = "tertiary";
2790 								seqKey = "tertiarySeq";
2791 								break;
2792 							case UCOL_QUATERNARY:
2793 								singleKey = "quaternary";
2794 								seqKey = "quaternarySeq";
2795 								break;
2796 
2797 							}
2798 							if(count <= 1){
2799 								//xmlString.append(formatString(mStringsBundle.getStringEx(singleKey,mError),args,2,t));
2800                                 writeCollation(args[1].getString(),xmlString, prevStrength, singleKey);
2801 
2802 							}else{
2803 								//xmlString.append(formatString(mStringsBundle.getStringEx(seqKey,mError),args,2,t));
2804 							    writeCollation(args[1].getString(),xmlString, prevStrength, seqKey);
2805                             }
2806                             //if(src.current== src.end){
2807                             //    break;
2808                             //}
2809 
2810 						}
2811                         //reset
2812 
2813                         count = 0;
2814 						collStr.remove();
2815 
2816 					}
2817 			  }
2818 
2819 
2820               isCollStrContraction = isTempStrContraction;
2821               isTempStrContraction = FALSE;
2822 			  collStr.append(tempStr);
2823 
2824 
2825 			  count++;
2826 			  prevStrength = strength;
2827 
2828 		}
2829 	}
2830 	if(appendedRules==TRUE){
2831 		chopIndent();
2832 		Formattable args[]= {indentOffset,UnicodeString(XML_END_SLASH)};
2833 		xmlString.append(formatString(mStringsBundle.getStringEx("rules",mError),args,2,t));
2834 	}
2835 
2836 	free(src.chars);
2837 	return xmlString;
2838 }
2839 
findUChar(const UChar * src,int32_t len,UChar c)2840 int32_t findUChar(const UChar* src, int32_t len, UChar c){
2841     int32_t i=0;
2842     while(i<len){
2843         if(src[i]==c){
2844             return i;
2845         }
2846         i++;
2847     }
2848     return -1;
2849 }
writeCollation(UnicodeString & src,UnicodeString & xmlString,uint32_t prevStrength,const char * keyName)2850 void GenerateXML::writeCollation(UnicodeString& src, UnicodeString &xmlString,uint32_t prevStrength, const char* keyName){
2851 // strength context string extension
2852 // <<<<  <context> | <string> / <extension>
2853     Formattable args[] = {"" , ""};
2854     UnicodeString context, string, extension, temp;
2855     int32_t index =  src.indexOf((UChar) 0x7C);
2856     int32_t contextMarker = (index>-1 && src.length() > 1) ? index : -1 ;
2857     if(contextMarker >=0 ){
2858         src.extract(0, contextMarker, context);
2859         escape(context);
2860         args[1] = context;
2861         context = formatString(mStringsBundle.getStringEx("context", mError), args, 2, temp);
2862     }
2863     int32_t extensionMarker = src.indexOf((UChar) UCOL_TOK_EXPANSION_MARKER);
2864     if(extensionMarker >= 0){
2865         src.extract(extensionMarker+1 /*skip past the extension marker*/,
2866                     src.length(), extension);
2867         escape(extension);
2868         args[1] = extension;
2869         extension = formatString(mStringsBundle.getStringEx("extend",mError),args,2,temp);
2870     }
2871     if(contextMarker >=0 && extensionMarker >=0){
2872         src.extract(contextMarker+1, extensionMarker - (contextMarker+1), string);
2873     }else if(contextMarker >=0){
2874         src.extract(contextMarker+1, src.length()-contextMarker, string);
2875     }else if(extensionMarker >=0){
2876         src.extract(0,extensionMarker, string);
2877     }else{
2878         string = src;
2879     }
2880     escape(string);
2881     args[0] = "";
2882     args[1] = string;
2883     string  = formatString(mStringsBundle.getStringEx(keyName,mError),args,2,temp);
2884     temp.remove();
2885 
2886     if(contextMarker>-1){
2887         temp.append(context);
2888     }
2889     temp.append(string);
2890     if(extensionMarker>-1){
2891         temp.append(extension);
2892     }
2893     if(contextMarker > -1 || extensionMarker > -1){
2894         temp.insert(0,"<x>");
2895         temp.append("</x>");
2896     }
2897     temp.insert(0, indentOffset);
2898     temp.append("\n");
2899     xmlString.append(temp);
2900 }
escape(UnicodeString & str)2901 void GenerateXML::escape(UnicodeString& str){
2902 	UnicodeString temp;
2903     UChar test[10] = {'\0'};
2904 	Formattable args[] = {indentOffset,""};
2905 	UnicodeString t;
2906 	for(int i=0;i<str.length();i++){
2907         UChar32 c = str.char32At(i);
2908         if(c >0xFFFF){
2909             i++;
2910         }
2911         switch(c){
2912         case '<':
2913 			temp.append("&lt;");
2914             break;
2915         case '>':
2916 			temp.append("&gt;");
2917             break;
2918         case '&':
2919 			temp.append("&amp;");
2920             break;
2921         case '"':
2922             temp.append("&quot;");
2923 		    break;
2924 		case 0x00:
2925         case 0x01:
2926         case 0x02:
2927         case 0x03:
2928         case 0x04:
2929         case 0x05:
2930         case 0x06:
2931         case 0x07:
2932         case 0x08:
2933         case 0x09:
2934        /* case 0x0A: */
2935         case 0x0b:
2936         case 0x0c:
2937        /* case 0x0D: */
2938         case 0x0e:
2939         case 0x0f:
2940         case 0x10:
2941         case 0x11:
2942         case 0x12:
2943         case 0x13:
2944         case 0x14:
2945         case 0x15:
2946         case 0x16:
2947         case 0x17:
2948         case 0x18:
2949         case 0x19:
2950         case 0x1A:
2951         case 0x1b:
2952         case 0x1c:
2953         case 0x1d:
2954         case 0x1e:
2955         case 0x1f:
2956             itou(test,c,16,4);
2957 			args[1] = UnicodeString(test);
2958             temp.append(formatString(mStringsBundle.getStringEx("cp",mError),args,2,t));
2959             break;
2960         default:
2961 			temp.append(c);
2962         }
2963 
2964 	}
2965 	str=temp;
2966 }
2967 
2968 
2969 static
u_strncmpNoCase(const UChar * s1,const UChar * s2,int32_t n)2970 int32_t u_strncmpNoCase(const UChar     *s1,
2971      const UChar     *s2,
2972      int32_t     n)
2973 {
2974     if(n > 0) {
2975         int32_t rc;
2976         for(;;) {
2977             rc = (int32_t)u_tolower(*s1) - (int32_t)u_tolower(*s2);
2978             if(rc != 0 || *s1 == 0 || --n == 0) {
2979                 return rc;
2980             }
2981             ++s1;
2982             ++s2;
2983         }
2984     }
2985     return 0;
2986 }
2987 
2988 static inline
syntaxError(const UChar * rules,int32_t pos,int32_t rulesLen,UParseError * parseError)2989 void syntaxError(const UChar* rules,
2990                  int32_t pos,
2991                  int32_t rulesLen,
2992                  UParseError* parseError) {
2993     parseError->offset = pos;
2994     parseError->line = 0 ; /* we are not using line numbers */
2995 
2996     // for pre-context
2997     int32_t start = (pos <=U_PARSE_CONTEXT_LEN)? 0 : (pos - (U_PARSE_CONTEXT_LEN-1));
2998     int32_t stop  = pos;
2999 
3000     u_memcpy(parseError->preContext,rules+start,stop-start);
3001     //null terminate the buffer
3002     parseError->preContext[stop-start] = 0;
3003 
3004     //for post-context
3005     start = pos+1;
3006     stop  = ((pos+U_PARSE_CONTEXT_LEN)<= rulesLen )? (pos+(U_PARSE_CONTEXT_LEN-1)) :
3007                                                             u_strlen(rules);
3008 
3009     u_memcpy(parseError->postContext,rules+start,stop-start);
3010     //null terminate the buffer
3011     parseError->postContext[stop-start]= 0;
3012 
3013     UnicodeString preCon,postCon;
3014 	prettify(UnicodeString(parseError->preContext),preCon);
3015 	prettify(parseError->postContext,postCon);
3016 	char preChar[256], postChar[256];
3017 	preCon.extract(0,preCon.length(),preChar,sizeof(preChar));
3018 	postCon.extract(0,postCon.length(),postChar,sizeof(postChar));
3019 	printf("parseRules() failed. Pre-context: %s \t post-context: %s \n",preChar, postChar);
3020 	exit(-1);
3021 }
3022 
3023 #define ucol_tok_isSpecialChar(ch)              \
3024     (((((ch) <= 0x002F) && ((ch) > 0x0020)) || \
3025       (((ch) <= 0x003F) && ((ch) >= 0x003A)) || \
3026       /* (((ch) <= 0x0060) && ((ch) >= 0x005B)) || \ */ \
3027 	  (((ch) == 0x0060) ||    ((ch) == 0x005c) || ((ch) == 0x005e) || ((ch) == 0x005f) ) || \
3028       (((ch) <= 0x007E) && ((ch) >= 0x007D)) || \
3029       (ch) == 0x007B))
3030 
3031 
3032 
growBuffer(UChar * src,int32_t len,int32_t size,int32_t requiredCapacity,UErrorCode * status)3033 void GenerateXML::growBuffer(UChar* src, int32_t len, int32_t size, int32_t requiredCapacity, UErrorCode* status){
3034 	UChar* temp =NULL;
3035 
3036 	if(status ==NULL || U_FAILURE(*status)){
3037 		return;
3038 	}
3039 	if(requiredCapacity < len ){
3040 		*status = U_ILLEGAL_ARGUMENT_ERROR;
3041 		return;
3042 	}
3043 	temp = (UChar*) malloc ( size * requiredCapacity);
3044 	if(temp ==NULL){
3045 		*status = U_MEMORY_ALLOCATION_ERROR;
3046 		return;
3047 	}
3048 	memmove(temp,src,len*size);
3049 	free(src);
3050 	src = temp;
3051 }
3052 
3053 /*
3054  *
3055  *  "&		a	<<		befg	<<		c		<<		d		<<		d"
3056  *   ^			^				^										^
3057  *   start		prevCurrent		current 								end
3058  */
3059 
parseRules(Token * src,UBool startOfRules)3060 uint32_t GenerateXML::parseRules(Token* src,UBool startOfRules){
3061   /* parsing part */
3062   UBool variableTop = FALSE;
3063   //UBool top = FALSE;
3064   UBool inChars = TRUE;
3065   UBool inQuote = FALSE;
3066   UBool wasInQuote = FALSE;
3067   UChar *optionEnd = NULL;
3068   uint8_t before = 0;
3069   UBool isEscaped = FALSE;
3070   UParseError parseError;
3071   uint32_t newExtensionLen = 0;
3072   uint32_t extensionOffset = 0;
3073   uint32_t newStrength = UCOL_TOK_UNSET;
3074   UBool isSetting = FALSE;
3075   const UChar top[] = {0x005b,0x0074,0x006f,0x0070,0x005d};
3076 
3077   src->prevCurrent = src->current;
3078   src->charsLen = 0;
3079 
3080   while (src->current < src->end) {
3081     UChar ch = *(src->current);
3082 
3083 
3084     if (inQuote) {
3085       if (ch == 0x0027/*'\''*/) {
3086           inQuote = FALSE;
3087       }else{
3088 		  if(src->charsLen >= (src->charsCapacity-1)){
3089 			  src->charsCapacity*=2;
3090 			 growBuffer(src->chars,src->charsLen,U_SIZEOF_UCHAR, src->charsCapacity,&mError);
3091 		  }
3092 		  src->chars[src->charsLen++] =ch;
3093 	  }
3094     }else if(isEscaped){
3095       isEscaped =FALSE;
3096       if (newStrength == UCOL_TOK_UNSET) {
3097 		mError = U_INVALID_FORMAT_ERROR;
3098         syntaxError(src->start,(int32_t)(src->current-src->start),(int32_t)(src->end-src->start),&parseError);
3099         return NULL;
3100         // enabling rules to start with non-tokens a < b
3101 		// newStrength = UCOL_TOK_RESET;
3102       }
3103 
3104     }else if(isSetting==TRUE ||!uprv_isRuleWhiteSpace(ch)) {
3105         /* Sets the strength for this entry */
3106         switch (ch) {
3107           case 0x003D/*'='*/ :
3108             if (newStrength != UCOL_TOK_UNSET) {
3109               goto EndOfLoop;
3110             }
3111 
3112             /* if we start with strength, we'll reset to top */
3113             if(startOfRules == TRUE) {
3114               newStrength = UCOL_TOK_RESET;
3115 			  u_strcpy(src->chars+src->charsLen,top);
3116 			  src->charsLen+=u_strlen(top);
3117               goto EndOfLoop;
3118             }
3119             newStrength = UCOL_IDENTICAL;
3120             break;
3121 
3122           case 0x002C/*','*/:
3123             if (newStrength != UCOL_TOK_UNSET) {
3124               goto EndOfLoop;
3125             }
3126 
3127             /* if we start with strength, we'll reset to top */
3128             if(startOfRules == TRUE) {
3129               newStrength = UCOL_TOK_RESET;
3130 			  u_strcpy(src->chars+src->charsLen,top);
3131 			  src->charsLen+=u_strlen(top);
3132               goto EndOfLoop;
3133             }
3134             newStrength = UCOL_TERTIARY;
3135             break;
3136 
3137 		  case 0x002D: /* - add to src->chars and continue */
3138 			  if(src->charsLen >= (src->charsCapacity-1)){
3139 				src->charsCapacity*=2;
3140 				growBuffer(src->chars,src->charsLen,U_SIZEOF_UCHAR, src->charsCapacity,&mError);
3141 			  }
3142 			  src->chars[src->charsLen++] = ch;
3143 			  break;
3144           case  0x003B/*';'*/:
3145             if (newStrength != UCOL_TOK_UNSET) {
3146               goto EndOfLoop;
3147             }
3148 
3149             /* if we start with strength, we'll reset to top */
3150             if(startOfRules == TRUE) {
3151 			  u_strcpy(src->chars+src->charsLen,top);
3152 			  src->charsLen+=u_strlen(top);
3153               newStrength = UCOL_TOK_RESET;
3154               goto EndOfLoop;
3155             }
3156             newStrength = UCOL_SECONDARY;
3157             break;
3158 
3159           case 0x003C/*'<'*/:
3160             if (newStrength != UCOL_TOK_UNSET) {
3161               goto EndOfLoop;
3162             }
3163 
3164             /* if we start with strength, we'll reset to top */
3165             if(startOfRules == TRUE) {
3166 			  u_strcpy(src->chars+src->charsLen,top);
3167 			  src->charsLen+=u_strlen(top);
3168               newStrength = UCOL_TOK_RESET;
3169               goto EndOfLoop;
3170             }
3171             /* before this, do a scan to verify whether this is */
3172             /* another strength */
3173             if(*(src->current+1) == 0x003C) {
3174               src->current++;
3175               if(*(src->current+1) == 0x003C) {
3176                 src->current++; /* three in a row! */
3177                 newStrength = UCOL_TERTIARY;
3178               } else { /* two in a row */
3179                 newStrength = UCOL_SECONDARY;
3180               }
3181             } else { /* just one */
3182               newStrength = UCOL_PRIMARY;
3183             }
3184             break;
3185 
3186           case 0x0026/*'&'*/:
3187             if (newStrength != UCOL_TOK_UNSET) {
3188               /**/
3189               goto EndOfLoop;
3190             }
3191 
3192             newStrength = UCOL_TOK_RESET; /* PatternEntry::RESET = 0 */
3193             break;
3194 
3195 		  case 0x005B:
3196 			  if (newStrength == UCOL_TOK_UNSET){
3197 				  newStrength = UCOL_TOK_SETTING;
3198 			  }
3199 			  if(!inQuote){
3200 				  isSetting=TRUE;
3201 			  }
3202 			  if(src->charsLen >= (src->charsCapacity-1)){
3203 				src->charsCapacity*=2;
3204 				growBuffer(src->chars,src->charsLen,U_SIZEOF_UCHAR, src->charsCapacity,&mError);
3205 			  }
3206 			  src->chars[src->charsLen++] =ch;
3207 			  break;
3208 		  case 0x005D:
3209 			  if(isSetting==TRUE){
3210 				  isSetting = FALSE;
3211 			  }
3212 			  if(src->charsLen >= (src->charsCapacity-1)){
3213 				src->charsCapacity*=2;
3214 				growBuffer(src->chars,src->charsLen,U_SIZEOF_UCHAR, src->charsCapacity,&mError);
3215 			  }
3216 			  src->chars[src->charsLen++] = ch;
3217 			  break;
3218 		  case 0x0021/*! skip java thai modifier reordering*/:
3219 			  break;
3220           case 0x002F/*'/'*/:
3221             wasInQuote = FALSE; /* if we were copying source characters, we want to stop now */
3222             /* RAM: expansion just add the character back */
3223             src->chars[src->charsLen++] = UCOL_TOK_EXPANSION_MARKER;
3224             inChars = FALSE; /* we're now processing expansion */
3225             break;
3226           case 0x005C /* back slash for escaped chars */:
3227               isEscaped = TRUE;
3228               break;
3229           /* found a quote, we're gonna start copying */
3230           case 0x0027/*'\''*/:
3231             if (newStrength == UCOL_TOK_UNSET) { /* quote is illegal until we have a strength */
3232 			  mError = U_INVALID_FORMAT_ERROR;
3233               syntaxError(src->start,(int32_t)(src->current-src->start),(int32_t)(src->end-src->start),&parseError);
3234               return NULL;
3235 			  // enabling rules to start with a non-token character a < b
3236               // newStrength = UCOL_TOK_RESET;
3237             }
3238 			if(inQuote==FALSE){
3239 				inQuote = TRUE;
3240 				wasInQuote = TRUE;
3241 			}else{
3242 				inQuote =FALSE;
3243 				wasInQuote = FALSE;
3244 			}
3245 			// removed inChars
3246 
3247 
3248 
3249             ch = *(++(src->current));
3250             if(ch == 0x0027) { /* copy the double quote */
3251               //*src->extraCurrent++ = ch;
3252 			  if(src->charsLen >= (src->charsCapacity-1)){
3253 				 src->charsCapacity*=2;
3254 			     growBuffer(src->chars,src->charsLen,U_SIZEOF_UCHAR, src->charsCapacity,&mError);
3255 			  }
3256 			  src->chars[src->charsLen++] = ch;
3257 			  if(*(src->current+1)!=0x0027){
3258 				inQuote = FALSE;
3259 			  }
3260             }else{
3261 				--src->current;
3262 			}
3263             break;
3264 
3265           /* '@' is french only if the strength is not currently set */
3266           /* if it is, it's just a regular character in collation rules */
3267           case 0x0040/*'@'*/:
3268             if (newStrength == UCOL_TOK_UNSET) {
3269               //src->opts->frenchCollation = UCOL_ON;
3270 			  //french secondary
3271 			  newStrength = UCOL_TOK_OVERRIDE;
3272               break;
3273             }
3274 
3275           case 0x007C /*|*/: /* this means we have actually been reading prefix part */
3276             // we want to store read characters to the prefix part and continue reading
3277             // the characters (proper way would be to restart reading the chars, but in
3278             // that case we would have to complicate the token hasher, which I do not
3279             // intend to play with. Instead, we will do prefixes when prefixes are due
3280             // (before adding the elements).
3281 
3282 			//wasInQuote = TRUE;
3283 			if(src->charsLen >= (src->charsCapacity-1)){
3284 			  src->charsCapacity*=2;
3285 			  growBuffer(src->chars,src->charsLen,U_SIZEOF_UCHAR, src->charsCapacity,&mError);
3286 			}
3287 			src->chars[src->charsLen++]=ch;
3288             //ch = *(++(src->current));
3289             break;
3290 
3291             //charsOffset = 0;
3292             //newCharsLen = 0;
3293             //break; // We want to store the whole prefix/character sequence. If we break
3294                      // the '|' is going to get lost.
3295           default:
3296             if (newStrength == UCOL_TOK_UNSET) {
3297 			  mError = U_INVALID_FORMAT_ERROR;
3298               syntaxError(src->start,(int32_t)(src->current-src->start),(int32_t)(src->end-src->start),&parseError);
3299               return NULL;
3300             }
3301 
3302             if (ucol_tok_isSpecialChar(ch) && (inQuote == FALSE)) {
3303               mError = U_INVALID_FORMAT_ERROR;
3304               syntaxError(src->start,(int32_t)(src->current-src->start),(int32_t)(src->end-src->start),&parseError);
3305               return NULL;
3306             }
3307 			if(src->charsLen >= (src->charsCapacity-1)){
3308 			 src->charsCapacity*=2;
3309 			 growBuffer(src->chars,src->charsLen,U_SIZEOF_UCHAR, src->charsCapacity,&mError);
3310 
3311 			}
3312 			src->chars[src->charsLen++] =ch;
3313             if(ch == 0x0000 && src->current+1 == src->end) {
3314               break;
3315             }
3316 
3317             break;
3318           }
3319        }
3320 	   src->current++;
3321     }
3322 
3323 
3324 
3325  EndOfLoop:
3326     if(newStrength == UCOL_TOK_UNSET && src->current == src->end){
3327         return UCOL_TOK_DONE;
3328     }
3329   wasInQuote = FALSE;
3330   return newStrength;
3331 }
3332 
3333 static UnicodeString suppIndent;
addIndent(UnicodeString & indent)3334 void GenerateXML::addIndent(UnicodeString& indent){
3335     indent.append("    ");
3336 }
chopIndent(UnicodeString & indent)3337 void GenerateXML::chopIndent(UnicodeString& indent){
3338     indent.remove(indent.length()-4);
3339 }
3340 
writeSupplementalData()3341 void GenerateXML::writeSupplementalData(){
3342 	FILE* sFile=getFileHandle(destDir,"supplementalData");
3343     UErrorCode error = U_ZERO_ERROR;
3344 
3345     // write the xml version
3346   	UnicodeString xmlString;
3347 
3348 	UnicodeString temp = mStringsBundle.getStringEx("supplementalDeclaration",error);
3349     xmlString.append(temp);
3350 	Formattable arguments[] = {"",""};
3351 	UnicodeString tempStr;
3352 	xmlString.append(formatString(mStringsBundle.getStringEx("supplementalData",error),arguments,1,tempStr));
3353 
3354     // TODO: change later
3355     UResourceBundle* root = ures_openDirect(path, "CurrencyData", &error);
3356 
3357     addIndent(suppIndent);
3358     arguments[0] = suppIndent;
3359     arguments[1] = "";
3360 	xmlString.append(formatString(mStringsBundle.getStringEx("currencyData",error),arguments,2,tempStr));
3361 
3362     tempStr.remove();
3363     writeCurrencyMeta(tempStr, root,error);
3364     if(tempStr.length()!=0){
3365         xmlString.append(tempStr);
3366     }
3367     tempStr.remove();
3368     writeCurrencyMap(tempStr, root, error);
3369     if(tempStr.length()!=0){
3370         xmlString.append(tempStr);
3371     }
3372     arguments[0] = suppIndent;
3373     arguments[1] = UnicodeString(XML_END_SLASH);
3374     xmlString.append(formatString(mStringsBundle.getStringEx("currencyData",error),arguments,2,tempStr));
3375     chopIndent(suppIndent);
3376 
3377     arguments[0] = UnicodeString(XML_END_SLASH);
3378 	xmlString.append(formatString(mStringsBundle.getStringEx("supplementalData",error),arguments,1,tempStr));
3379 	printString(&xmlString, sFile);
3380 
3381     ures_close(root);
3382 
3383 }
writeCurrencyMap(UnicodeString & xmlString,UResourceBundle * root,UErrorCode & error)3384 void GenerateXML::writeCurrencyMap(UnicodeString& xmlString, UResourceBundle* root, UErrorCode& error){
3385     if(U_FAILURE(error)){
3386         return;
3387     }
3388     UResourceBundle* curr = ures_getByKey(root, "CurrencyMap", NULL, &error);
3389     char altKey[100] = {0};
3390     const char* preEuro = "_PREEURO";
3391     const char* euro    = "_EURO";
3392     if(U_SUCCESS(error)){
3393         addIndent(suppIndent);
3394         while(ures_hasNext(curr)){
3395             UResourceBundle* element = ures_getNextResource(curr,NULL, &error);
3396             const char*   country  =  ures_getKey(element);
3397             if(strstr(country, preEuro) != NULL || strstr(country, euro)!=NULL){
3398                 continue;
3399             }
3400             int32_t len =0;
3401             const UChar* temp = ures_getString(element,&len, &error);
3402             UnicodeString currency (temp, len);
3403             Formattable args[] = {suppIndent, country, "" };
3404             UnicodeString tempStr;
3405             xmlString.append(formatString(mStringsBundle.getStringEx("regionStart",error),args,2,tempStr));
3406             addIndent(suppIndent);
3407             args[0] = suppIndent;
3408             args[1] = currency;
3409 
3410             xmlString.append(formatString(mStringsBundle.getStringEx("suppCurrencyStart",mError),args,3,tempStr));
3411 
3412             addIndent(suppIndent);
3413             strcpy(altKey, country);
3414             strcat(altKey, preEuro);
3415             len=0;
3416             temp = ures_getStringByKey(curr, altKey, &len, &error);
3417             UnicodeString altCurrency (temp, len);
3418             if(U_SUCCESS(error)){
3419                 args[0] = suppIndent;
3420                 args[1] = altCurrency;
3421                 xmlString.append(formatString(mStringsBundle.getStringEx("alternate",error),args,2,tempStr));
3422             }else{
3423                 error = U_ZERO_ERROR;
3424             }
3425             chopIndent(suppIndent);
3426 
3427             args[0] = suppIndent;
3428             xmlString.append(formatString(mStringsBundle.getStringEx("suppCurrencyEnd",error),args,1,tempStr));
3429 
3430             chopIndent(suppIndent);
3431 
3432             args[0] = suppIndent;
3433             xmlString.append(formatString(mStringsBundle.getStringEx("regionEnd",error),args,1,tempStr));
3434 
3435         }
3436         chopIndent(suppIndent);
3437     }
3438 
3439 }
writeCurrencyMeta(UnicodeString & xmlString,UResourceBundle * root,UErrorCode & error)3440 void GenerateXML::writeCurrencyMeta(UnicodeString& xmlString, UResourceBundle* root, UErrorCode& error){
3441     if(U_FAILURE(error)){
3442         return;
3443     }
3444     UResourceBundle* curr = ures_getByKey(root, "CurrencyMeta", NULL, &error);
3445     if(U_SUCCESS(error)){
3446         addIndent(suppIndent);
3447         Formattable args[] = {suppIndent, "", "", ""};
3448         Formattable args1[] = {""};
3449         UnicodeString tempStr;
3450         xmlString.append(formatString(mStringsBundle.getStringEx("fractions",error),args,2,tempStr));
3451 
3452         addIndent(suppIndent);
3453         while(ures_hasNext(curr)){
3454             UResourceBundle* element = ures_getNextResource(curr, NULL, &error);
3455             const char* key = ures_getKey(element);
3456             int32_t len =0;
3457             const int32_t* intVector = ures_getIntVector(element,&len, &error);
3458             ures_close(element);
3459             if(len < 2){
3460                 error = U_INTERNAL_PROGRAM_ERROR;
3461                 return;
3462             }
3463             UChar buffer[100] = {0};
3464             len = itou(buffer, intVector[0], 10, 0);
3465 
3466             args[0] = suppIndent;
3467             args[1] = key;
3468             args[2] = formatString(mStringsBundle.getStringEx("digits", error), UnicodeString(buffer, len), tempStr);
3469 
3470             if(intVector!=0){
3471                 len = itou(buffer, intVector[1], 10, 0);
3472                 args[3] = formatString(mStringsBundle.getStringEx("rounding", error), UnicodeString(buffer, len), tempStr);
3473             }else{
3474                 args[3] = "";
3475             }
3476 
3477             xmlString.append(formatString(mStringsBundle.getStringEx("info",mError),args,4,tempStr));
3478 
3479         }
3480         chopIndent(suppIndent);
3481 
3482         args[0] = suppIndent;
3483         args[1] = UnicodeString(XML_END_SLASH);
3484         xmlString.append(formatString(mStringsBundle.getStringEx("fractions",mError),args,2,tempStr));
3485 
3486         chopIndent(suppIndent);
3487     }
3488 }
3489 
writePaperSize(UnicodeString & xmlString)3490 void GenerateXML::writePaperSize(UnicodeString& xmlString){
3491     ResourceBundle paperSize = mSourceBundle.get("PaperSize", mError);
3492     int32_t len=0;
3493     const int32_t* sizes = paperSize.getIntVector(len,mError);
3494     UnicodeString tempStr;
3495 
3496     if( mError!=U_USING_DEFAULT_WARNING &&
3497 		mError!=U_USING_FALLBACK_WARNING &&
3498             U_SUCCESS(mError)){
3499         Formattable args[] = {indentOffset, "", ""};
3500         xmlString.append(formatString( mStringsBundle.getStringEx("paperSize", mError), args, 2, tempStr));
3501         indentOffset.append("\t");
3502 
3503         char c[10] = {0};
3504         itoa(sizes[0], c, 10);
3505         args[0] = indentOffset;
3506         args[1] = UnicodeString(c);
3507         tempStr.remove();
3508         xmlString.append(formatString( mStringsBundle.getStringEx("height", mError), args, 2, tempStr));
3509 
3510         c[0] = 0;
3511         itoa(sizes[1], c, 10);
3512         args[1] = UnicodeString(c);
3513         tempStr.remove();
3514         xmlString.append(formatString( mStringsBundle.getStringEx("width", mError), args, 2, tempStr));
3515 
3516         chopIndent();
3517         tempStr.remove();
3518         args[0] = indentOffset;
3519         args[1] = UnicodeString(XML_END_SLASH);
3520         xmlString.append(formatString( mStringsBundle.getStringEx("paperSize", mError), args, 2, tempStr));
3521         mError = U_ZERO_ERROR;
3522         return;
3523     }
3524     mError = U_ZERO_ERROR;
3525     xmlString.remove();
3526 }
3527 
writeMeasurement(UnicodeString & xmlString)3528 void GenerateXML::writeMeasurement(UnicodeString& xmlString){
3529     UnicodeString tempStr;
3530     Formattable args[] = { indentOffset, "", "" };
3531     xmlString.append(formatString( mStringsBundle.getStringEx("measurement", mError), args, 2, tempStr));
3532     UBool print = FALSE;
3533 
3534     ResourceBundle measurementSystem = mSourceBundle.get("MeasurementSystem", mError);
3535     indentOffset.append("\t");
3536 
3537     if( mError!=U_USING_DEFAULT_WARNING &&
3538 		mError!=U_USING_FALLBACK_WARNING &&
3539             U_SUCCESS(mError)){
3540 
3541         args[0] = indentOffset;
3542         args[1] = (measurementSystem.getInt(mError)== 0) ? "metric" : "US";
3543         if(U_SUCCESS(mError)){
3544             tempStr.remove();
3545             xmlString.append(formatString( mStringsBundle.getStringEx("measurementSystem", mError), args, 2, tempStr));
3546             print = TRUE;
3547         }
3548     }
3549 
3550     tempStr.remove();
3551     writePaperSize(tempStr);
3552     if(tempStr.length()>0){
3553         xmlString.append(tempStr);
3554         print = TRUE;
3555     }
3556     tempStr.remove();
3557     chopIndent();
3558     args[0] = indentOffset;
3559     args[1] = UnicodeString(XML_END_SLASH);
3560     xmlString.append(formatString( mStringsBundle.getStringEx("measurement", mError), args, 2, tempStr));
3561     if(print==FALSE){
3562         xmlString.remove();
3563     }
3564     mError = U_ZERO_ERROR;
3565 }
3566 
3567 /*
3568 void GenerateXML::writePosixCompData(){
3569     char temp[50]={'\0'};
3570     strcpy(temp,locName);
3571     strcat(temp,"_PCD");
3572     Locale loc(temp);
3573     ResourceBundle bundle(path, loc,mError);
3574     if(mError==U_ZERO_ERROR){
3575         UnicodeString xmlString;
3576         xmlString.append(formatString(UnicodeString(POSIX_START),indentOffset));
3577         indentOffset.append("\t");
3578 
3579         writeMessages(bundle,xmlString);
3580         addressFormat(bundle,xmlString);
3581         nameFormat(bundle, xmlString);
3582         identity(bundle, xmlString);
3583         telephoneFormat( bundle, xmlString);
3584 
3585         chopIndent();
3586         xmlString.append(formatString(UnicodeString(POSIX_END), indentOffset));
3587         printString(&xmlString);
3588 
3589     }
3590 
3591 
3592 }
3593 
3594 void GenerateXML::writeMessages(ResourceBundle& bundle, UnicodeString& xmlString){
3595     UnicodeString temp,temp1;
3596     ResourceBundle dBundle = bundle.get("Messages",mError);
3597     if(U_SUCCESS(mError)){
3598         temp.append(formatString(UnicodeString(MSG_START),indentOffset));
3599         indentOffset.append("\t");
3600         getStringRes("yesExpression",dBundle,temp1,UnicodeString(YES));
3601         getStringRes("noExpression",dBundle,temp1, UnicodeString(NO));
3602         if(temp1.length()!=0){
3603             temp.append(temp1);
3604             temp.append(formatString(UnicodeString(MSG_END),indentOffset));
3605         }else{
3606             temp.remove();
3607         }
3608         chopIndent();
3609         xmlString.append(temp);
3610     }
3611 
3612 }
3613 
3614 void GenerateXML::addressFormat(ResourceBundle& bundle,UnicodeString& xmlString){
3615     UnicodeString temp,temp1;
3616     ResourceBundle dBundle = bundle.get("AddressFormat",mError);
3617     if(U_SUCCESS(mError)){
3618         temp.append(formatString(UnicodeString(ADDR_START),indentOffset));
3619         indentOffset.append("\t");
3620         getStringRes("PostalFormat",dBundle,temp1,UnicodeString(POSTAL));
3621         if(temp1.length()!=0){
3622             temp.append(temp1);
3623             temp.append(formatString(UnicodeString(ADDR_END),indentOffset));
3624         }else{
3625             temp.remove();
3626         }
3627         chopIndent();
3628         xmlString.append(temp);
3629     }
3630 }
3631 
3632 void GenerateXML::nameFormat(ResourceBundle& bundle,UnicodeString& xmlString){
3633     UnicodeString temp,temp1;
3634     ResourceBundle dBundle = bundle.get("NameFormat",mError);
3635     if(U_SUCCESS(mError)){
3636         temp.append(formatString(UnicodeString(NF_START),indentOffset));
3637         indentOffset.append("\t");
3638 
3639         getStringRes("NamePattern",dBundle,temp1,UnicodeString(NAME_PAT));
3640         getStringRes("GeneralSalutaion",dBundle,temp1, UnicodeString(GEN_SALUT));
3641         getStringRes("ShortSalutationMr",dBundle,temp1, UnicodeString(SH_SALUT_MR));
3642         getStringRes("ShortSalutationMiss",dBundle,temp1, UnicodeString(SH_SALUT_MS));
3643         getStringRes("ShortSalutationMrs",dBundle,temp1, UnicodeString(SH_SALUT_MI));
3644         getStringRes("LongSalutationMr",dBundle,temp1, UnicodeString(LG_SALUT_MR));
3645         getStringRes("LongSalutationMiss",dBundle,temp1, UnicodeString(LG_SALUT_MS));
3646         getStringRes("LongSalutationMrs",dBundle,temp1, UnicodeString(LG_SALUT_MI));
3647 
3648         if(temp1.length()!=0){
3649             temp.append(temp1);
3650             temp.append(formatString(UnicodeString(NF_END),indentOffset));
3651         }else{
3652             temp.remove();
3653         }
3654         chopIndent();
3655         xmlString.append(temp);
3656     }
3657 }
3658 
3659 void GenerateXML::identity(ResourceBundle& bundle,UnicodeString& xmlString){
3660 	    UnicodeString temp,temp1;
3661 	    ResourceBundle dBundle = bundle.get("Identification",mError);
3662 		if(U_SUCCESS(mError)){
3663 	        temp.append(formatString(UnicodeString(ID_START),indentOffset));
3664         indentOffset.append("\t");
3665 
3666         getStringRes("Title",dBundle,temp1,UnicodeString(TITLE));
3667         getStringRes("Source",dBundle,temp1, UnicodeString(SOURCE));
3668         getStringRes("Address",dBundle,temp1, UnicodeString(ADDR_1));
3669        // getStringRes("Contact",dBundle,temp1, UnicodeString(CONTACT));
3670         getStringRes("Email",dBundle,temp1, UnicodeString(EMAIL));
3671         getStringRes("Telephone",dBundle,temp1, UnicodeString(TELEPH));
3672         getStringRes("Fax",dBundle,temp1, UnicodeString(FAX));
3673         getStringRes("u",dBundle,temp1, UnicodeString(LANG_1));
3674         getStringRes("Territory",dBundle,temp1,UnicodeString(TRTRY));
3675         getStringRes("Audience",dBundle,temp1, UnicodeString(AUDIENCE));
3676         getStringRes("Application",dBundle,temp1, UnicodeString(APPLIC));
3677         getStringRes("Abbreviation",dBundle,temp1, UnicodeString(ABBR_1));
3678         getStringRes("Revision",dBundle,temp1, UnicodeString(REV));
3679         getStringRes("Date",dBundle,temp1, UnicodeString(DATE_1));
3680 
3681         if(temp1.length()!=0){
3682             temp.append(temp1);
3683             temp.append(formatString(UnicodeString(ID_END),indentOffset));
3684         }else{
3685             temp.remove();
3686         }
3687         chopIndent();
3688         xmlString.append(temp);
3689     }
3690 }
3691 
3692 
3693 void GenerateXML::telephoneFormat(ResourceBundle& bundle,UnicodeString& xmlString){
3694     UnicodeString temp,temp1;
3695     ResourceBundle dBundle = bundle.get("TelephoneFormat",mError);
3696     if(U_SUCCESS(mError)){
3697         temp.append(formatString(UnicodeString(TF_START),indentOffset));
3698         indentOffset.append("\t");
3699 
3700         getStringRes("InternationalFormat",dBundle,temp1, UnicodeString(IP_TF));
3701         getStringRes("DomesticFormat",dBundle,temp1, UnicodeString(DP_TF));
3702         getStringRes("InternationalDialCode",dBundle,temp1, UnicodeString(IDC_TF));
3703         getStringRes("InternationalPrefix",dBundle,temp1, UnicodeString(IPF_TF));
3704 
3705         if(temp1.length()!=0){
3706             temp.append(temp1);
3707             temp.append(formatString(UnicodeString(TF_END),indentOffset));
3708         }else{
3709             temp.remove();
3710         }
3711         chopIndent();
3712         xmlString.append(temp);
3713     }
3714 }
3715 
3716 
3717 void GenerateXML::writePosixAdditions(){
3718     UnicodeString xmlString;
3719     writeMeasurement(xmlString);
3720     writeCountryPost(xmlString);
3721     writeCountryCar(xmlString);
3722     writeCountryISBNNumber(xmlString);
3723     writeLanguageLibraryUse(xmlString);
3724     writePaperSize(xmlString);
3725     if(xmlString.length()>0){
3726         printString(&xmlString);
3727     }
3728 }
3729 void GenerateXML::writeCountryPost(UnicodeString& xmlString){
3730     UnicodeString temp;
3731     getStringRes("CountryPost",temp,UnicodeString(POST));
3732     if(temp.length()>0){
3733         xmlString.append(temp);
3734     }
3735 }
3736 void GenerateXML::writeCountryCar(UnicodeString& xmlString){
3737 
3738     UnicodeString temp;
3739     getStringRes("CountryCar",temp,UnicodeString(CNTRY_CAR));
3740     if(temp.length()>0){
3741         xmlString.append(temp);
3742     }
3743 }
3744 void GenerateXML::writeCountryISBNNumber(UnicodeString& xmlString){
3745 
3746     UnicodeString temp;
3747     getStringRes("CountryISBN",temp,UnicodeString(ISBN_NUM));
3748     if(temp.length()>0){
3749         xmlString.append(temp);
3750     }
3751 }
3752 void GenerateXML::writeLanguageLibraryUse(UnicodeString& xmlString){
3753     UnicodeString temp;
3754     getStringRes("LanguageLibUse",temp,UnicodeString(LANG_LIB));
3755     if(temp.length()>0){
3756         xmlString.append(temp);
3757     }
3758 }
3759 
3760 void GenerateXML::getStringRes(const char *key,ResourceBundle& bundle,UnicodeString& xmlString,UnicodeString pattern){
3761     ResourceBundle myBundle = mSourceBundle;
3762     mSourceBundle = bundle;
3763     getStringRes(key,xmlString,pattern);
3764     mSourceBundle = myBundle;
3765 }
3766 void GenerateXML::getStringRes(const char* key,UnicodeString& xmlString,UnicodeString pattern){
3767     UnicodeString temp=mSourceBundle.getStringEx(key,mError);
3768 	Formattable args[]={indentOffset,""};
3769 	if(!U_FAILURE(mError)){
3770 		args[1] = temp;
3771 		xmlString.append(formatString(pattern,args,2));
3772 	}
3773 	mError = U_ZERO_ERROR;
3774 }
3775 
3776 */