update dev300-m58
[ooovba.git] / i18npool / source / localedata / LocaleNode.cxx
blob6ab53ee2aff6c0cae7a82ab57c61799c5e4eb9e2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: LocaleNode.cxx,v $
10 * $Revision: 1.29.24.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_i18npool.hxx"
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <iostream>
37 #include <set>
39 #include <rtl/ustrbuf.hxx>
41 #include "LocaleNode.hxx"
42 #include <com/sun/star/i18n/NumberFormatIndex.hpp>
44 // NOTE: MUST match the Locale versionDTD attribute defined in data/locale.dtd
45 #define LOCALE_VERSION_DTD "2.0.3"
47 typedef ::std::set< ::rtl::OUString > NameSet;
48 typedef ::std::set< sal_Int16 > ValueSet;
50 namespace cssi = ::com::sun::star::i18n;
52 LocaleNode::LocaleNode (const OUString& name, const Reference< XAttributeList > & attr)
53 : aName(name)
54 , xAttribs(new Attr(attr))
55 , parent(0)
56 , children(0)
57 , nChildren(0)
58 , childArrSize(0)
59 , nError(0)
63 int LocaleNode::getError() const
65 int err = nError;
66 for (sal_Int32 i=0;i<nChildren;i++)
67 err += children[i]->getError();
68 return err;
71 void LocaleNode::print () const {
72 printf ("<");
73 ::rtl::OUString str (aName);
74 for(sal_Int32 i = 0; i < str.getLength(); i++)
75 printf( "%c", str[i]);
76 printf (">\n");
79 void LocaleNode::printR () const {
80 print();
81 for (sal_Int32 i=0;i<nChildren;i++)
82 children[i]->printR();
83 printf ("\t");
84 print();
87 void LocaleNode::addChild ( LocaleNode * node) {
88 if (childArrSize <= nChildren) {
89 LocaleNode ** arrN = (LocaleNode **)malloc( sizeof (LocaleNode *)*(childArrSize+10) ) ;
90 for (sal_Int32 i = 0; i<childArrSize ; i++)
91 arrN[i] = children[i];
92 if ( childArrSize > 0 )
93 free(children);
94 childArrSize += 10;
95 children = arrN;
97 children[nChildren++] = node;
98 node->setParent (this);
101 void LocaleNode::setParent ( LocaleNode * node) {
102 parent = node;
105 const LocaleNode* LocaleNode::getRoot() const
107 const LocaleNode* pRoot = 0;
108 const LocaleNode* pParent = this;
109 while ( (pParent = pParent->getParent()) != 0 )
110 pRoot = pParent;
111 return pRoot;
114 const LocaleNode * LocaleNode::findNode ( const sal_Char *name) const {
115 if (aName.equalsAscii(name))
116 return this;
117 for (sal_Int32 i = 0; i< nChildren; i++) {
118 const LocaleNode *n=children[i]->findNode(name);
119 if (n)
120 return n;
122 return 0;
125 LocaleNode::~LocaleNode() {
126 for (sal_Int32 i=0; i<nChildren;i++)
127 delete (children[i]);
130 LocaleNode* LocaleNode::createNode (const OUString& name, const Reference< XAttributeList > & attr)
132 if (name.equalsAscii("LC_INFO"))
133 return new LCInfoNode (name,attr);
134 if (name.equalsAscii("LC_CTYPE"))
135 return new LCCTYPENode (name,attr);
136 if (name.equalsAscii("LC_FORMAT"))
137 return new LCFormatNode (name,attr);
138 if (name.equalsAscii("LC_FORMAT_1"))
139 return new LCFormatNode (name,attr);
140 if (name.equalsAscii("LC_CALENDAR"))
141 return new LCCalendarNode (name,attr);
142 if (name.equalsAscii("LC_CURRENCY"))
143 return new LCCurrencyNode (name,attr);
144 if (name.equalsAscii("LC_TRANSLITERATION"))
145 return new LCTransliterationNode (name,attr);
146 if (name.equalsAscii("LC_COLLATION"))
147 return new LCCollationNode (name,attr);
148 if (name.equalsAscii("LC_INDEX"))
149 return new LCIndexNode (name,attr);
150 if (name.equalsAscii("LC_SEARCH"))
151 return new LCSearchNode (name,attr);
152 if (name.equalsAscii("LC_MISC"))
153 return new LCMiscNode (name,attr);
154 if (name.equalsAscii("LC_NumberingLevel"))
155 return new LCNumberingLevelNode (name, attr);
156 if (name.equalsAscii("LC_OutLineNumberingLevel"))
157 return new LCOutlineNumberingLevelNode (name, attr);
159 return new LocaleNode(name,attr);
163 // printf(" name: '%s'\n", p->getName().pData->buffer );
164 // printf("value: '%s'\n", p->getValue().pData->buffer );
166 void print_OUString( const OUString& s )
168 printf( "%s", OUStringToOString( s, RTL_TEXTENCODING_UTF8).getStr());
171 bool is_empty( const OUString& s )
173 return (s.getLength()==0) || (s.getLength()==1 && s[0]=='\n');
176 void print_indent( int depth )
178 for( int i=0; i<depth; i++ ) printf(" ");
181 void print_color( int color )
183 printf("\033[%dm", color);
186 void print_node( const LocaleNode* p, int depth=0 )
188 if( !p ) return;
190 print_indent( depth );
191 printf("<");
192 print_color(36);
193 print_OUString( p->getName() );
194 print_color(0);
195 const Attr* q = p->getAttr();
196 if( q )
198 for( sal_Int32 j=0; j<q->getLength(); j++ )
200 printf(" ");
201 print_color(33);
202 print_OUString( q->getTypeByIndex(j) );
203 print_color(0);
204 printf("=");
205 print_color(31);
206 printf("'");
207 print_OUString( q->getValueByIndex(j) );
208 printf("'");
209 print_color(0);
212 printf(">");
213 printf("\n");
214 if( !is_empty( p->getValue() ) )
216 print_indent( depth+1 );
217 printf("value: ");
218 print_color(31);
219 printf("'");
220 print_OUString( p->getValue() );
221 printf("'");
222 print_color(0);
223 printf("\n");
225 for( sal_Int32 i=0; i<p->getNumberOfChildren(); i++ )
227 print_node( p->getChildAt(i), depth+1 );
229 print_indent( depth );
230 printf("</");
231 print_OUString( p->getName() );
232 printf(">");
233 printf("\n");
236 void LocaleNode :: generateCode (const OFileWriter &of) const
238 ::rtl::OUString aDTD = getAttr()->getValueByName("versionDTD");
239 if (!aDTD.equalsAscii( LOCALE_VERSION_DTD))
241 ++nError;
242 fprintf( stderr, "Error: Locale versionDTD is not %s, see comment in locale.dtd\n", LOCALE_VERSION_DTD);
244 for (sal_Int32 i=0; i<nChildren;i++)
245 children[i]->generateCode (of);
246 // print_node( this );
250 ::rtl::OUString LocaleNode::writeParameterCheckLen( const OFileWriter &of,
251 const char* pParameterName, const LocaleNode* pNode,
252 sal_Int32 nMinLen, sal_Int32 nMaxLen ) const
254 OUString aVal;
255 if (pNode)
256 aVal = pNode->getValue();
257 else
259 ++nError;
260 fprintf( stderr, "Error: node NULL pointer for parameter %s.\n",
261 pParameterName);
263 // write empty data if error
264 of.writeParameter( pParameterName, aVal);
265 sal_Int32 nLen = aVal.getLength();
266 if (nLen < nMinLen)
268 ++nError;
269 fprintf( stderr, "Error: less than %ld character%s (%ld) in %s '%s'.\n",
270 sal::static_int_cast< long >(nMinLen), (nMinLen > 1 ? "s" : ""),
271 sal::static_int_cast< long >(nLen),
272 (pNode ? OUStringToOString( pNode->getName(), RTL_TEXTENCODING_UTF8).getStr() : ""),
273 OUStringToOString( aVal, RTL_TEXTENCODING_UTF8).getStr());
275 else if (nLen > nMaxLen && nMaxLen >= 0)
276 fprintf( stderr,
277 "Warning: more than %ld character%s (%ld) in %s %s not supported by application.\n",
278 sal::static_int_cast< long >(nMaxLen), (nMaxLen > 1 ? "s" : ""),
279 sal::static_int_cast< long >(nLen),
280 (pNode ? OUStringToOString( pNode->getName(), RTL_TEXTENCODING_UTF8).getStr() : ""),
281 OUStringToOString( aVal, RTL_TEXTENCODING_UTF8).getStr());
282 return aVal;
286 ::rtl::OUString LocaleNode::writeParameterCheckLen( const OFileWriter &of,
287 const char* pNodeName, const char* pParameterName,
288 sal_Int32 nMinLen, sal_Int32 nMaxLen ) const
290 OUString aVal;
291 const LocaleNode * pNode = findNode( pNodeName);
292 if (pNode)
293 aVal = writeParameterCheckLen( of, pParameterName, pNode, nMinLen, nMaxLen);
294 else
296 ++nError;
297 fprintf( stderr, "Error: node %s not found.\n", pNodeName);
298 // write empty data if error
299 of.writeParameter( pParameterName, aVal);
301 return aVal;
304 void LocaleNode::incError( const char* pStr ) const
306 ++nError;
307 fprintf( stderr, "Error: %s\n", pStr);
310 void LocaleNode::incError( const ::rtl::OUString& rStr ) const
312 incError( OUStringToOString( rStr, RTL_TEXTENCODING_UTF8).getStr());
315 char* LocaleNode::prepareErrorFormat( const char* pFormat, const char* pDefaultConversion ) const
317 static char buf[2048];
318 strcpy( buf, "Error: ");
319 strncat( buf, pFormat, 2000);
320 char* p = buf;
321 while (((p = strchr( p, '%')) != 0) && p[1] == '%')
322 p += 2;
323 if (!p)
324 strcat( buf, pDefaultConversion);
325 strcat( buf, "\n");
326 return buf;
329 void LocaleNode::incErrorInt( const char* pStr, int nVal ) const
331 ++nError;
332 fprintf( stderr, prepareErrorFormat( pStr, ": %d"), nVal);
335 void LocaleNode::incErrorStr( const char* pStr, const ::rtl::OUString& rVal ) const
337 ++nError;
338 fprintf( stderr, prepareErrorFormat( pStr, ": %s"), OUStringToOString(
339 rVal, RTL_TEXTENCODING_UTF8).getStr());
342 void LCInfoNode::generateCode (const OFileWriter &of) const
345 const LocaleNode * languageNode = findNode("Language");
346 const LocaleNode * countryNode = findNode("Country");
347 const LocaleNode * variantNode = findNode("Variant");
349 if (languageNode)
351 writeParameterCheckLen( of, "langID", languageNode->getChildAt(0), 2, -1);
352 of.writeParameter("langDefaultName", languageNode->getChildAt(1)->getValue());
354 else
355 incError( "No Language node.");
356 if (countryNode)
358 of.writeParameter("countryID", countryNode->getChildAt(0)->getValue());
359 of.writeParameter("countryDefaultName", countryNode->getChildAt(1)->getValue());
361 else
362 incError( "No Country node.");
363 if (variantNode)
365 of.writeParameter("Variant", variantNode->getValue());
366 fprintf( stderr, "Warning: %s\n",
367 "Variants are not supported by application.");
369 else
370 of.writeParameter("Variant", ::rtl::OUString());
371 of.writeAsciiString("\nstatic const sal_Unicode* LCInfoArray[] = {\n");
372 of.writeAsciiString("\tlangID,\n");
373 of.writeAsciiString("\tlangDefaultName,\n");
374 of.writeAsciiString("\tcountryID,\n");
375 of.writeAsciiString("\tcountryDefaultName,\n");
376 of.writeAsciiString("\tVariant\n");
377 of.writeAsciiString("};\n\n");
378 of.writeFunction("getLCInfo_", "0", "LCInfoArray");
381 void LCCTYPENode::generateCode (const OFileWriter &of) const
383 const LocaleNode * sepNode = 0;
384 ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
385 if (useLocale.getLength() > 0) {
386 of.writeRefFunction("getLocaleItem_", useLocale);
387 return;
389 ::rtl::OUString str = getAttr() -> getValueByName("unoid");
390 of.writeAsciiString("\n\n");
391 of.writeParameter("LC_CTYPE_Unoid", str);;
393 OUString aDateSep =
394 writeParameterCheckLen( of, "DateSeparator", "dateSeparator", 1, 1);
395 OUString aThoSep =
396 writeParameterCheckLen( of, "ThousandSeparator", "thousandSeparator", 1, 1);
397 OUString aDecSep =
398 writeParameterCheckLen( of, "DecimalSeparator", "decimalSeparator", 1, 1);
399 OUString aTimeSep =
400 writeParameterCheckLen( of, "TimeSeparator", "timeSeparator", 1, 1);
401 OUString aTime100Sep =
402 writeParameterCheckLen( of, "Time100SecSeparator", "time100SecSeparator", 1, 1);
403 OUString aListSep =
404 writeParameterCheckLen( of, "ListSeparator", "listSeparator", 1, 1);
406 OUString aLDS;
408 sepNode = findNode("LongDateDayOfWeekSeparator");
409 aLDS = sepNode->getValue();
410 of.writeParameter("LongDateDayOfWeekSeparator", aLDS);
411 if (aLDS.getLength() == 1 && aLDS.getStr()[0] == ',')
412 fprintf( stderr, "Warning: %s\n",
413 "LongDateDayOfWeekSeparator is only a comma not followed by a space. Usually this is not the case and may lead to concatenated display names like \"Wednesday,May 9, 2007\".");
415 sepNode = findNode("LongDateDaySeparator");
416 aLDS = sepNode->getValue();
417 of.writeParameter("LongDateDaySeparator", aLDS);
418 if (aLDS.getLength() == 1 && (aLDS.getStr()[0] == ',' || aLDS.getStr()[0] == '.'))
419 fprintf( stderr, "Warning: %s\n",
420 "LongDateDaySeparator is only a comma or dot not followed by a space. Usually this is not the case and may lead to concatenated display names like \"Wednesday, May 9,2007\".");
422 sepNode = findNode("LongDateMonthSeparator");
423 aLDS = sepNode->getValue();
424 of.writeParameter("LongDateMonthSeparator", aLDS);
425 if (aLDS.getLength() == 0)
426 fprintf( stderr, "Warning: %s\n",
427 "LongDateMonthSeparator is empty. Usually this is not the case and may lead to concatenated display names like \"Wednesday, May9, 2007\".");
429 sepNode = findNode("LongDateYearSeparator");
430 aLDS = sepNode->getValue();
431 of.writeParameter("LongDateYearSeparator", aLDS);
432 if (aLDS.getLength() == 0)
433 fprintf( stderr, "Warning: %s\n",
434 "LongDateYearSeparator is empty. Usually this is not the case and may lead to concatenated display names like \"Wednesday, 2007May 9\".");
437 int nSavErr = nError;
438 int nWarn = 0;
439 if (aDateSep == aTimeSep)
440 incError( "DateSeparator equals TimeSeparator.");
441 if (aDecSep == aThoSep)
442 incError( "DecimalSeparator equals ThousandSeparator.");
443 if (aThoSep.equalsAscii( " "))
444 incError( "ThousandSeparator is an ' ' ordinary space, this should be a non-breaking space U+00A0 instead.");
445 if (aListSep == aDecSep)
446 fprintf( stderr, "Warning: %s\n",
447 "ListSeparator equals DecimalSeparator.");
448 if (aListSep == aThoSep)
449 fprintf( stderr, "Warning: %s\n",
450 "ListSeparator equals ThousandSeparator.");
451 if (aTimeSep == aTime100Sep)
452 ++nWarn, fprintf( stderr, "Warning: %s\n",
453 "Time100SecSeparator equals TimeSeparator, this is probably an error.");
454 if (aDecSep != aTime100Sep)
455 ++nWarn, fprintf( stderr, "Warning: %s\n",
456 "Time100SecSeparator is different from DecimalSeparator, this may be correct or not. Intended?");
457 if (nSavErr != nError || nWarn)
458 fprintf( stderr, "Warning: %s\n",
459 "Don't forget to adapt corresponding FormatCode elements when changing separators.");
461 OUString aQuoteStart =
462 writeParameterCheckLen( of, "QuotationStart", "quotationStart", 1, 1);
463 OUString aQuoteEnd =
464 writeParameterCheckLen( of, "QuotationEnd", "quotationEnd", 1, 1);
465 OUString aDoubleQuoteStart =
466 writeParameterCheckLen( of, "DoubleQuotationStart", "doubleQuotationStart", 1, 1);
467 OUString aDoubleQuoteEnd =
468 writeParameterCheckLen( of, "DoubleQuotationEnd", "doubleQuotationEnd", 1, 1);
470 if (aQuoteStart.toChar() <= 127 && aQuoteEnd.toChar() > 127)
471 fprintf( stderr, "Warning: %s\n",
472 "QuotationStart is an ASCII character but QuotationEnd is not.");
473 if (aQuoteEnd.toChar() <= 127 && aQuoteStart.toChar() > 127)
474 fprintf( stderr, "Warning: %s\n",
475 "QuotationEnd is an ASCII character but QuotationStart is not.");
476 if (aDoubleQuoteStart.toChar() <= 127 && aDoubleQuoteEnd.toChar() > 127)
477 fprintf( stderr, "Warning: %s\n",
478 "DoubleQuotationStart is an ASCII character but DoubleQuotationEnd is not.");
479 if (aDoubleQuoteEnd.toChar() <= 127 && aDoubleQuoteStart.toChar() > 127)
480 fprintf( stderr, "Warning: %s\n",
481 "DoubleQuotationEnd is an ASCII character but DoubleQuotationStart is not.");
482 if (aQuoteStart.toChar() <= 127 && aQuoteEnd.toChar() <= 127)
483 fprintf( stderr, "Warning: %s\n",
484 "QuotationStart and QuotationEnd are both ASCII characters. Not necessarily an error, but unusual.");
485 if (aDoubleQuoteStart.toChar() <= 127 && aDoubleQuoteEnd.toChar() <= 127)
486 fprintf( stderr, "Warning: %s\n",
487 "DoubleQuotationStart and DoubleQuotationEnd are both ASCII characters. Not necessarily an error, but unusual.");
488 if (aQuoteStart == aQuoteEnd)
489 fprintf( stderr, "Warning: %s\n",
490 "QuotationStart equals QuotationEnd. Not necessarily an error, but unusual.");
491 if (aDoubleQuoteStart == aDoubleQuoteEnd)
492 fprintf( stderr, "Warning: %s\n",
493 "DoubleQuotationStart equals DoubleQuotationEnd. Not necessarily an error, but unusual.");
495 writeParameterCheckLen( of, "TimeAM", "timeAM", 1, -1);
496 writeParameterCheckLen( of, "TimePM", "timePM", 1, -1);
497 sepNode = findNode("MeasurementSystem");
498 of.writeParameter("measurementSystem", sepNode->getValue());
500 of.writeAsciiString("\nstatic const sal_Unicode* LCType[] = {\n");
501 of.writeAsciiString("\tLC_CTYPE_Unoid,\n");
502 of.writeAsciiString("\tdateSeparator,\n");
503 of.writeAsciiString("\tthousandSeparator,\n");
504 of.writeAsciiString("\tdecimalSeparator,\n");
505 of.writeAsciiString("\ttimeSeparator,\n");
506 of.writeAsciiString("\ttime100SecSeparator,\n");
507 of.writeAsciiString("\tlistSeparator,\n");
508 of.writeAsciiString("\tquotationStart,\n");
509 of.writeAsciiString("\tquotationEnd,\n");
510 of.writeAsciiString("\tdoubleQuotationStart,\n");
511 of.writeAsciiString("\tdoubleQuotationEnd,\n");
512 of.writeAsciiString("\ttimeAM,\n");
513 of.writeAsciiString("\ttimePM,\n");
514 of.writeAsciiString("\tmeasurementSystem,\n");
515 of.writeAsciiString("\tLongDateDayOfWeekSeparator,\n");
516 of.writeAsciiString("\tLongDateDaySeparator,\n");
517 of.writeAsciiString("\tLongDateMonthSeparator,\n");
518 of.writeAsciiString("\tLongDateYearSeparator\n");
519 of.writeAsciiString("};\n\n");
520 of.writeFunction("getLocaleItem_", "0", "LCType");
524 sal_Int16 LCFormatNode::mnSection = 0;
525 sal_Int16 LCFormatNode::mnFormats = 0;
527 void LCFormatNode::generateCode (const OFileWriter &of) const
529 OUString str;
530 if (mnSection >= 2)
531 incError("more than 2 LC_FORMAT sections");
532 of.writeParameter("replaceFrom", getAttr() -> getValueByName("replaceFrom"), mnSection);
533 str = getAttr() -> getValueByName("replaceTo");
534 // Locale data generator inserts FFFF for LangID, we need to adapt that.
535 if (str.endsWithIgnoreAsciiCaseAsciiL( "-FFFF]", 6))
536 incErrorStr("replaceTo=\"%s\" needs FFFF to be adapted to the real LangID value.", str);
537 of.writeParameter("replaceTo", str, mnSection);
538 ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
539 if (useLocale.getLength() > 0) {
540 switch (mnSection)
542 case 0:
543 of.writeRefFunction("getAllFormats0_", useLocale, "replaceTo0");
544 break;
545 case 1:
546 of.writeRefFunction("getAllFormats1_", useLocale, "replaceTo1");
547 break;
549 return;
551 sal_Int16 formatCount = mnFormats;
552 NameSet aMsgIdSet;
553 ValueSet aFormatIndexSet;
554 NameSet aDefaultsSet;
555 bool bCtypeIsRef = false;
557 for (sal_Int16 i = 0; i< getNumberOfChildren() ; i++,formatCount++) {
558 LocaleNode * currNode = getChildAt (i);
559 OUString aUsage;
560 OUString aType;
561 OUString aFormatIndex;
562 // currNode -> print();
563 const Attr * currNodeAttr = currNode->getAttr();
564 //printf ("getLen() = %d\n", currNode->getAttr()->getLength());
566 str = currNodeAttr -> getValueByName("msgid");
567 if (!aMsgIdSet.insert( str).second)
568 incErrorStr( "Duplicated msgid=\"%s\" in FormatElement.", str);
569 of.writeParameter("FormatKey", str, formatCount);
571 str = currNodeAttr -> getValueByName("default");
572 bool bDefault = str.equalsAscii( "true");
573 of.writeDefaultParameter("FormatElement", str, formatCount);
575 aType = currNodeAttr -> getValueByName("type");
576 of.writeParameter("FormatType", aType, formatCount);
578 aUsage = currNodeAttr -> getValueByName("usage");
579 of.writeParameter("FormatUsage", aUsage, formatCount);
581 aFormatIndex = currNodeAttr -> getValueByName("formatindex");
582 sal_Int16 formatindex = (sal_Int16)aFormatIndex.toInt32();
583 if (!aFormatIndexSet.insert( formatindex).second)
584 incErrorInt( "Duplicated formatindex=\"%d\" in FormatElement.", formatindex);
585 of.writeIntParameter("Formatindex", formatCount, formatindex);
587 // Ensure only one default per usage and type.
588 if (bDefault)
590 OUString aKey( aUsage + OUString( sal_Unicode(',')) + aType);
591 if (!aDefaultsSet.insert( aKey).second)
593 OUString aStr( RTL_CONSTASCII_USTRINGPARAM( "Duplicated default for usage=\""));
594 aStr += aUsage;
595 aStr += OUString( RTL_CONSTASCII_USTRINGPARAM( "\" type=\""));
596 aStr += aType;
597 aStr += OUString( RTL_CONSTASCII_USTRINGPARAM( "\": formatindex=\""));
598 aStr += aFormatIndex;
599 aStr += OUString( RTL_CONSTASCII_USTRINGPARAM( "\"."));
600 incError( aStr);
604 const LocaleNode * n = currNode -> findNode("FormatCode");
605 if (n)
607 of.writeParameter("FormatCode", n->getValue(), formatCount);
608 // Check separator usage for some FormatCode elements.
609 const LocaleNode* pCtype = 0;
610 switch (formatindex)
612 case cssi::NumberFormatIndex::NUMBER_1000DEC2 : // #,##0.00
613 case cssi::NumberFormatIndex::TIME_MMSS00 : // MM:SS.00
614 case cssi::NumberFormatIndex::TIME_HH_MMSS00 : // [HH]:MM:SS.00
616 const LocaleNode* pRoot = getRoot();
617 if (!pRoot)
618 incError( "No root for FormatCode.");
619 else
621 pCtype = pRoot->findNode( "LC_CTYPE");
622 if (!pCtype)
623 incError( "No LC_CTYPE found for FormatCode.");
624 else
626 OUString aRef( pCtype->getAttr()->getValueByName("ref"));
627 if (aRef.getLength() > 0)
629 if (!bCtypeIsRef)
630 fprintf( stderr,
631 "Warning: Can't check separators used in FormatCode due to LC_CTYPE ref=\"%s\".\n"
632 "If these two locales use identical format codes, you should consider to use the ref= mechanism also for the LC_FORMAT element, together with replaceFrom= and replaceTo= for the currency.\n",
633 OUStringToOString( aRef, RTL_TEXTENCODING_UTF8).getStr());
634 bCtypeIsRef = true;
635 pCtype = 0;
640 break;
641 // Currency formats should be something like [C]###0;-[C]###0
642 // and not parenthesized [C]###0;([C]###0) if not en_US.
643 case cssi::NumberFormatIndex::CURRENCY_1000INT :
644 case cssi::NumberFormatIndex::CURRENCY_1000INT_RED :
645 case cssi::NumberFormatIndex::CURRENCY_1000DEC2 :
646 case cssi::NumberFormatIndex::CURRENCY_1000DEC2_RED :
647 case cssi::NumberFormatIndex::CURRENCY_1000DEC2_CCC :
648 case cssi::NumberFormatIndex::CURRENCY_1000DEC2_DASHED :
649 if (strcmp( of.getLocale(), "en_US") != 0)
651 OUString aCode( n->getValue());
652 OUString aPar1( RTL_CONSTASCII_USTRINGPARAM( "0)" ));
653 OUString aPar2( RTL_CONSTASCII_USTRINGPARAM( "-)" ));
654 OUString aPar3( RTL_CONSTASCII_USTRINGPARAM( " )" ));
655 if (aCode.indexOf( aPar1 ) > 0 || aCode.indexOf( aPar2 ) > 0 || aCode.indexOf( aPar3 ) > 0)
656 fprintf( stderr, "Warning: FormatCode formatindex=\"%d\" for currency uses parentheses for negative amounts, which probably is not correct for locales not based on en_US.\n", formatindex);
658 break;
660 if (pCtype)
662 int nSavErr = nError;
663 OUString aCode( n->getValue());
664 if (formatindex == cssi::NumberFormatIndex::NUMBER_1000DEC2)
666 sal_Int32 nDec = -1;
667 sal_Int32 nGrp = -1;
668 const LocaleNode* pSep = pCtype->findNode( "DecimalSeparator");
669 if (!pSep)
670 incError( "No DecimalSeparator found for FormatCode.");
671 else
673 nDec = aCode.indexOf( pSep->getValue());
674 if (nDec < 0)
675 incErrorInt( "DecimalSeparator not present in FormatCode formatindex=\"%d\".",
676 formatindex);
678 pSep = pCtype->findNode( "ThousandSeparator");
679 if (!pSep)
680 incError( "No ThousandSeparator found for FormatCode.");
681 else
683 nGrp = aCode.indexOf( pSep->getValue());
684 if (nGrp < 0)
685 incErrorInt( "ThousandSeparator not present in FormatCode formatindex=\"%d\".",
686 formatindex);
688 if (nDec <= nGrp)
689 incErrorInt( "Ordering of ThousandSeparator and DecimalSeparator not correct in formatindex=\"%d\".",
690 formatindex);
692 if (formatindex == cssi::NumberFormatIndex::TIME_MMSS00 ||
693 formatindex == cssi::NumberFormatIndex::TIME_HH_MMSS00)
695 sal_Int32 nTime = -1;
696 sal_Int32 n100s = -1;
697 const LocaleNode* pSep = pCtype->findNode( "TimeSeparator");
698 if (!pSep)
699 incError( "No TimeSeparator found for FormatCode.");
700 else
702 nTime = aCode.indexOf( pSep->getValue());
703 if (nTime < 0)
704 incErrorInt( "TimeSeparator not present in FormatCode formatindex=\"%d\".",
705 formatindex);
707 pSep = pCtype->findNode( "Time100SecSeparator");
708 if (!pSep)
709 incError( "No Time100SecSeparator found for FormatCode.");
710 else
712 n100s = aCode.indexOf( pSep->getValue());
713 if (n100s < 0)
714 incErrorInt( "Time100SecSeparator not present in FormatCode formatindex=\"%d\".",
715 formatindex);
716 OUStringBuffer a100s( pSep->getValue());
717 a100s.appendAscii( "00");
718 n100s = aCode.indexOf( a100s.makeStringAndClear());
719 if (n100s < 0)
720 incErrorInt( "Time100SecSeparator+00 not present in FormatCode formatindex=\"%d\".",
721 formatindex);
723 if (n100s <= nTime)
724 incErrorInt( "Ordering of Time100SecSeparator and TimeSeparator not correct in formatindex=\"%d\".",
725 formatindex);
727 if (nSavErr != nError)
728 fprintf( stderr,
729 "Warning: formatindex=\"%d\",\"%d\",\"%d\" are the only FormatCode elements checked for separator usage, there may be others that have errors.\n",
730 int(cssi::NumberFormatIndex::NUMBER_1000DEC2),
731 int(cssi::NumberFormatIndex::TIME_MMSS00),
732 int(cssi::NumberFormatIndex::TIME_HH_MMSS00));
736 else
737 incError( "No FormatCode in FormatElement.");
738 n = currNode -> findNode("DefaultName");
739 if (n)
740 of.writeParameter("FormatDefaultName", n->getValue(), formatCount);
741 else
742 of.writeParameter("FormatDefaultName", ::rtl::OUString(), formatCount);
746 // Check presence of all required format codes only in first section
747 // LC_FORMAT, not in optional LC_FORMAT_1
748 if (mnSection == 0)
750 // 0..47 MUST be present, 48,49 MUST NOT be present
751 ValueSet::const_iterator aIter( aFormatIndexSet.begin());
752 for (sal_Int16 nNext = cssi::NumberFormatIndex::NUMBER_START;
753 nNext < cssi::NumberFormatIndex::INDEX_TABLE_ENTRIES; ++nNext)
755 sal_Int16 nHere = ::std::min( ((aIter != aFormatIndexSet.end() ? *aIter :
756 cssi::NumberFormatIndex::INDEX_TABLE_ENTRIES)),
757 cssi::NumberFormatIndex::INDEX_TABLE_ENTRIES);
758 if (aIter != aFormatIndexSet.end()) ++aIter;
759 for ( ; nNext < nHere; ++nNext)
761 switch (nNext)
763 case cssi::NumberFormatIndex::FRACTION_1 :
764 case cssi::NumberFormatIndex::FRACTION_2 :
765 case cssi::NumberFormatIndex::BOOLEAN :
766 case cssi::NumberFormatIndex::TEXT :
767 // generated internally
768 break;
769 default:
770 incErrorInt( "FormatElement formatindex=\"%d\" not present.", nNext);
773 switch (nHere)
775 case cssi::NumberFormatIndex::BOOLEAN :
776 incErrorInt( "FormatElement formatindex=\"%d\" reserved for internal ``BOOLEAN''.", nNext);
777 break;
778 case cssi::NumberFormatIndex::TEXT :
779 incErrorInt( "FormatElement formatindex=\"%d\" reserved for internal ``@'' (TEXT).", nNext);
780 break;
781 default:
782 ; // nothing
787 of.writeAsciiString("\nstatic const sal_Int16 ");
788 of.writeAsciiString("FormatElementsCount");
789 of.writeInt(mnSection);
790 of.writeAsciiString(" = ");
791 of.writeInt( formatCount - mnFormats);
792 of.writeAsciiString(";\n");
793 of.writeAsciiString("static const sal_Unicode* ");
794 of.writeAsciiString("FormatElementsArray");
795 of.writeInt(mnSection);
796 of.writeAsciiString("[] = {\n");
797 for(sal_Int16 i = mnFormats; i < formatCount; i++) {
799 of.writeAsciiString("\t");
800 of.writeAsciiString("FormatCode");
801 of.writeInt(i);
802 of.writeAsciiString(",\n");
804 of.writeAsciiString("\t");
805 of.writeAsciiString("FormatDefaultName");
806 of.writeInt(i);
807 of.writeAsciiString(",\n");
809 of.writeAsciiString("\t");
810 of.writeAsciiString("FormatKey");
811 of.writeInt(i);
812 of.writeAsciiString(",\n");
814 of.writeAsciiString("\t");
815 of.writeAsciiString("FormatType");
816 of.writeInt(i);
817 of.writeAsciiString(",\n");
819 of.writeAsciiString("\t");
820 of.writeAsciiString("FormatUsage");
821 of.writeInt(i);
822 of.writeAsciiString(",\n");
824 of.writeAsciiString("\t");
825 of.writeAsciiString("Formatindex");
826 of.writeInt(i);
827 of.writeAsciiString(",\n");
830 of.writeAsciiString("\tdefaultFormatElement");
831 of.writeInt(i);
832 of.writeAsciiString(",\n");
834 of.writeAsciiString("};\n\n");
836 switch (mnSection)
838 case 0:
839 of.writeFunction("getAllFormats0_", "FormatElementsCount0", "FormatElementsArray0", "replaceFrom0", "replaceTo0");
840 break;
841 case 1:
842 of.writeFunction("getAllFormats1_", "FormatElementsCount1", "FormatElementsArray1", "replaceFrom1", "replaceTo1");
843 break;
846 mnFormats = mnFormats + formatCount;
847 ++mnSection;
850 void LCCollationNode::generateCode (const OFileWriter &of) const
852 ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
853 if (useLocale.getLength() > 0) {
854 of.writeRefFunction("getCollatorImplementation_", useLocale);
855 of.writeRefFunction("getCollationOptions_", useLocale);
856 return;
858 sal_Int16 nbOfCollations = 0;
859 sal_Int16 nbOfCollationOptions = 0;
860 sal_Int16 j;
862 for ( j = 0; j < getNumberOfChildren(); j++ ) {
863 LocaleNode * currNode = getChildAt (j);
864 if( currNode->getName().compareToAscii("Collator") == 0 )
866 ::rtl::OUString str;
867 str = currNode->getAttr() -> getValueByName("unoid");
868 of.writeParameter("CollatorID", str, j);
869 str = currNode->getValue();
870 of.writeParameter("CollatorRule", str, j);
871 str = currNode -> getAttr() -> getValueByName("default");
872 of.writeDefaultParameter("Collator", str, j);
873 of.writeAsciiString("\n");
875 nbOfCollations++;
877 if( currNode->getName().compareToAscii("CollationOptions") == 0 )
879 LocaleNode* pCollationOptions = currNode;
880 nbOfCollationOptions = sal::static_int_cast<sal_Int16>( pCollationOptions->getNumberOfChildren() );
881 for( sal_Int16 i=0; i<nbOfCollationOptions; i++ )
883 of.writeParameter("collationOption", pCollationOptions->getChildAt( i )->getValue(), i );
886 of.writeAsciiString("static const sal_Int16 nbOfCollationOptions = ");
887 of.writeInt( nbOfCollationOptions );
888 of.writeAsciiString(";\n\n");
891 of.writeAsciiString("static const sal_Int16 nbOfCollations = ");
892 of.writeInt(nbOfCollations);
893 of.writeAsciiString(";\n\n");
895 of.writeAsciiString("\nstatic const sal_Unicode* LCCollatorArray[] = {\n");
896 for(j = 0; j < nbOfCollations; j++) {
897 of.writeAsciiString("\tCollatorID");
898 of.writeInt(j);
899 of.writeAsciiString(",\n");
901 of.writeAsciiString("\tdefaultCollator");
902 of.writeInt(j);
903 of.writeAsciiString(",\n");
905 of.writeAsciiString("\tCollatorRule");
906 of.writeInt(j);
907 of.writeAsciiString(",\n");
909 of.writeAsciiString("};\n\n");
911 of.writeAsciiString("static const sal_Unicode* collationOptions[] = {");
912 for( j=0; j<nbOfCollationOptions; j++ )
914 of.writeAsciiString( "collationOption" );
915 of.writeInt( j );
916 of.writeAsciiString( ", " );
918 of.writeAsciiString("NULL };\n");
919 of.writeFunction("getCollatorImplementation_", "nbOfCollations", "LCCollatorArray");
920 of.writeFunction("getCollationOptions_", "nbOfCollationOptions", "collationOptions");
923 void LCSearchNode::generateCode (const OFileWriter &of) const
925 ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
926 if (useLocale.getLength() > 0) {
927 of.writeRefFunction("getSearchOptions_", useLocale);
928 return;
931 if( getNumberOfChildren() != 1 )
933 ++nError;
934 fprintf(
935 stderr, "Error: LC_SEARCH: more than 1 child: %ld\n",
936 sal::static_int_cast< long >(getNumberOfChildren()));
938 sal_Int32 i;
939 LocaleNode* pSearchOptions = getChildAt( 0 );
940 sal_Int32 nSearchOptions = pSearchOptions->getNumberOfChildren();
941 for( i=0; i<nSearchOptions; i++ )
943 of.writeParameter("searchOption", pSearchOptions->getChildAt( i )->getValue(), sal::static_int_cast<sal_Int16>(i) );
946 of.writeAsciiString("static const sal_Int16 nbOfSearchOptions = ");
947 of.writeInt( sal::static_int_cast<sal_Int16>( nSearchOptions ) );
948 of.writeAsciiString(";\n\n");
950 of.writeAsciiString("static const sal_Unicode* searchOptions[] = {");
951 for( i=0; i<nSearchOptions; i++ )
953 of.writeAsciiString( "searchOption" );
954 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
955 of.writeAsciiString( ", " );
957 of.writeAsciiString("NULL };\n");
958 of.writeFunction("getSearchOptions_", "nbOfSearchOptions", "searchOptions");
961 void LCIndexNode::generateCode (const OFileWriter &of) const
963 ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
964 if (useLocale.getLength() > 0) {
965 of.writeRefFunction("getIndexAlgorithm_", useLocale);
966 of.writeRefFunction("getUnicodeScripts_", useLocale);
967 of.writeRefFunction("getFollowPageWords_", useLocale);
968 return;
970 sal_Int16 nbOfIndexs = 0;
971 sal_Int16 nbOfUnicodeScripts = 0;
972 sal_Int16 nbOfPageWords = 0;
973 sal_Int16 i;
974 for (i = 0; i< getNumberOfChildren();i++) {
975 LocaleNode * currNode = getChildAt (i);
976 if( currNode->getName().compareToAscii("IndexKey") == 0 )
978 ::rtl::OUString str;
979 str = currNode->getAttr() -> getValueByName("unoid");
980 of.writeParameter("IndexID", str, nbOfIndexs);
981 str = currNode->getAttr() -> getValueByName("module");
982 of.writeParameter("IndexModule", str, nbOfIndexs);
983 str = currNode->getValue();
984 of.writeParameter("IndexKey", str, nbOfIndexs);
985 str = currNode -> getAttr() -> getValueByName("default");
986 of.writeDefaultParameter("Index", str, nbOfIndexs);
987 str = currNode -> getAttr() -> getValueByName("phonetic");
988 of.writeDefaultParameter("Phonetic", str, nbOfIndexs);
989 of.writeAsciiString("\n");
991 nbOfIndexs++;
993 if( currNode->getName().compareToAscii("UnicodeScript") == 0 )
995 of.writeParameter("unicodeScript", currNode->getValue(), nbOfUnicodeScripts );
996 nbOfUnicodeScripts++;
999 if( currNode->getName().compareToAscii("FollowPageWord") == 0 )
1001 of.writeParameter("followPageWord", currNode->getValue(), nbOfPageWords);
1002 nbOfPageWords++;
1005 of.writeAsciiString("static const sal_Int16 nbOfIndexs = ");
1006 of.writeInt(nbOfIndexs);
1007 of.writeAsciiString(";\n\n");
1009 of.writeAsciiString("\nstatic const sal_Unicode* IndexArray[] = {\n");
1010 for(i = 0; i < nbOfIndexs; i++) {
1011 of.writeAsciiString("\tIndexID");
1012 of.writeInt(i);
1013 of.writeAsciiString(",\n");
1015 of.writeAsciiString("\tIndexModule");
1016 of.writeInt(i);
1017 of.writeAsciiString(",\n");
1019 of.writeAsciiString("\tIndexKey");
1020 of.writeInt(i);
1021 of.writeAsciiString(",\n");
1023 of.writeAsciiString("\tdefaultIndex");
1024 of.writeInt(i);
1025 of.writeAsciiString(",\n");
1027 of.writeAsciiString("\tdefaultPhonetic");
1028 of.writeInt(i);
1029 of.writeAsciiString(",\n");
1031 of.writeAsciiString("};\n\n");
1033 of.writeAsciiString("static const sal_Int16 nbOfUnicodeScripts = ");
1034 of.writeInt( nbOfUnicodeScripts );
1035 of.writeAsciiString(";\n\n");
1037 of.writeAsciiString("static const sal_Unicode* UnicodeScriptArray[] = {");
1038 for( i=0; i<nbOfUnicodeScripts; i++ )
1040 of.writeAsciiString( "unicodeScript" );
1041 of.writeInt( i );
1042 of.writeAsciiString( ", " );
1044 of.writeAsciiString("NULL };\n\n");
1046 of.writeAsciiString("static const sal_Int16 nbOfPageWords = ");
1047 of.writeInt(nbOfPageWords);
1048 of.writeAsciiString(";\n\n");
1050 of.writeAsciiString("static const sal_Unicode* FollowPageWordArray[] = {\n");
1051 for(i = 0; i < nbOfPageWords; i++) {
1052 of.writeAsciiString("\tfollowPageWord");
1053 of.writeInt(i);
1054 of.writeAsciiString(",\n");
1056 of.writeAsciiString("\tNULL\n};\n\n");
1058 of.writeFunction("getIndexAlgorithm_", "nbOfIndexs", "IndexArray");
1059 of.writeFunction("getUnicodeScripts_", "nbOfUnicodeScripts", "UnicodeScriptArray");
1060 of.writeFunction("getFollowPageWords_", "nbOfPageWords", "FollowPageWordArray");
1063 void LCCalendarNode::generateCode (const OFileWriter &of) const
1065 ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
1066 if (useLocale.getLength() > 0) {
1067 of.writeRefFunction("getAllCalendars_", useLocale);
1068 return;
1070 sal_Int16 nbOfCalendars = sal::static_int_cast<sal_Int16>( getNumberOfChildren() );
1071 ::rtl::OUString str;
1072 sal_Int16 * nbOfDays = new sal_Int16[nbOfCalendars];
1073 sal_Int16 * nbOfMonths = new sal_Int16[nbOfCalendars];
1074 sal_Int16 * nbOfEras = new sal_Int16[nbOfCalendars];
1075 sal_Int16 j;
1076 sal_Int16 i;
1077 bool bHasGregorian = false;
1080 for ( i = 0; i < nbOfCalendars; i++) {
1081 LocaleNode * calNode = getChildAt (i);
1082 OUString calendarID = calNode -> getAttr() -> getValueByName("unoid");
1083 of.writeParameter( "calendarID", calendarID, i);
1084 bool bGregorian = calendarID.equalsAscii( "gregorian");
1085 if (!bHasGregorian)
1086 bHasGregorian = bGregorian;
1087 str = calNode -> getAttr() -> getValueByName("default");
1088 of.writeDefaultParameter("Calendar", str, i);
1090 // Generate Days of Week
1091 const sal_Char *elementTag;
1092 LocaleNode * daysNode = NULL;
1093 ::rtl::OUString ref_name = calNode->getChildAt(0)->getAttr()->getValueByName("ref");
1094 if (ref_name.getLength() > 0 && i > 0) {
1095 for (j = 0; j < i; j++) {
1096 str = getChildAt(j)->getAttr()->getValueByName("unoid");
1097 if (str.equals(ref_name))
1098 daysNode = getChildAt(j)->getChildAt(0);
1101 if (ref_name.getLength() > 0 && daysNode == NULL) {
1102 of.writeParameter("dayRef", OUString::createFromAscii("ref"), i);
1103 of.writeParameter("dayRefName", ref_name, i);
1104 nbOfDays[i] = 0;
1105 } else {
1106 if (daysNode == NULL)
1107 daysNode = calNode -> getChildAt(0);
1108 nbOfDays[i] = sal::static_int_cast<sal_Int16>( daysNode->getNumberOfChildren() );
1109 if (bGregorian && nbOfDays[i] != 7)
1110 incErrorInt( "A Gregorian calendar must have 7 days per week, this one has %d", nbOfDays[i]);
1111 elementTag = "day";
1112 for (j = 0; j < nbOfDays[i]; j++) {
1113 LocaleNode *currNode = daysNode -> getChildAt(j);
1114 OUString dayID( currNode->getChildAt(0)->getValue());
1115 of.writeParameter("dayID", dayID, i, j);
1116 if (j == 0 && bGregorian && !dayID.equalsAscii( "sun"))
1117 incError( "First day of a week of a Gregorian calendar must be <DayID>sun</DayID>");
1118 of.writeParameter(elementTag, "DefaultAbbrvName",currNode->getChildAt(1)->getValue() ,i, j);
1119 of.writeParameter(elementTag, "DefaultFullName",currNode->getChildAt(2)->getValue() , i, j);
1123 // Generate Months of Year
1124 LocaleNode * monthsNode = NULL;
1125 ref_name = calNode->getChildAt(1)->getAttr()->getValueByName("ref");
1126 if (ref_name.getLength() > 0 && i > 0) {
1127 for (j = 0; j < i; j++) {
1128 str = getChildAt(j)->getAttr()->getValueByName("unoid");
1129 if (str.equals(ref_name))
1130 monthsNode = getChildAt(j)->getChildAt(1);
1133 if (ref_name.getLength() > 0 && monthsNode == NULL) {
1134 of.writeParameter("monthRef", OUString::createFromAscii("ref"), i);
1135 of.writeParameter("monthRefName", ref_name, i);
1136 nbOfMonths[i] = 0;
1137 } else {
1138 if (monthsNode == NULL)
1139 monthsNode = calNode -> getChildAt(1);
1140 nbOfMonths[i] = sal::static_int_cast<sal_Int16>( monthsNode->getNumberOfChildren() );
1141 if (bGregorian && nbOfMonths[i] != 12)
1142 incErrorInt( "A Gregorian calendar must have 12 months, this one has %d", nbOfMonths[i]);
1143 elementTag = "month";
1144 for (j = 0; j < nbOfMonths[i]; j++) {
1145 LocaleNode *currNode = monthsNode -> getChildAt(j);
1146 OUString monthID( currNode->getChildAt(0)->getValue());
1147 of.writeParameter("monthID", monthID, i, j);
1148 if (j == 0 && bGregorian && !monthID.equalsAscii( "jan"))
1149 incError( "First month of a year of a Gregorian calendar must be <MonthID>jan</MonthID>");
1150 of.writeParameter(elementTag, "DefaultAbbrvName",currNode->getChildAt(1)->getValue() ,i, j);
1151 of.writeParameter(elementTag, "DefaultFullName",currNode->getChildAt(2)->getValue() , i, j);
1155 // Generate Era name
1156 LocaleNode * erasNode = NULL;
1157 ref_name = calNode -> getChildAt(2) ->getAttr()->getValueByName("ref");
1158 if (ref_name.getLength() > 0 && i > 0) {
1159 for (j = 0; j < i; j++) {
1160 str = getChildAt(j)->getAttr()->getValueByName("unoid");
1161 if (str.equals(ref_name))
1162 erasNode = getChildAt(j)->getChildAt(2);
1165 if (ref_name.getLength() > 0 && erasNode == NULL) {
1166 of.writeParameter("eraRef", OUString::createFromAscii("ref"), i);
1167 of.writeParameter("eraRefName", ref_name, i);
1168 nbOfEras[i] = 0;
1169 } else {
1170 if (erasNode == NULL)
1171 erasNode = calNode -> getChildAt(2);
1172 nbOfEras[i] = sal::static_int_cast<sal_Int16>( erasNode->getNumberOfChildren() );
1173 if (bGregorian && nbOfEras[i] != 2)
1174 incErrorInt( "A Gregorian calendar must have 2 eras, this one has %d", nbOfEras[i]);
1175 elementTag = "era";
1176 for (j = 0; j < nbOfEras[i]; j++) {
1177 LocaleNode *currNode = erasNode -> getChildAt(j);
1178 OUString eraID( currNode->getChildAt(0)->getValue());
1179 of.writeParameter("eraID", eraID, i, j);
1180 if (j == 0 && bGregorian && !eraID.equalsAscii( "bc"))
1181 incError( "First era of a Gregorian calendar must be <EraID>bc</EraID>");
1182 if (j == 1 && bGregorian && !eraID.equalsAscii( "ad"))
1183 incError( "Second era of a Gregorian calendar must be <EraID>ad</EraID>");
1184 of.writeAsciiString("\n");
1185 of.writeParameter(elementTag, "DefaultAbbrvName",currNode->getChildAt(1)->getValue() ,i, j);
1186 of.writeParameter(elementTag, "DefaultFullName",currNode->getChildAt(2)->getValue() , i, j);
1189 str = calNode->getChildAt(3)->getChildAt(0)->getValue();
1190 if (nbOfDays[i])
1192 for (j = 0; j < nbOfDays[i]; j++)
1194 LocaleNode *currNode = daysNode->getChildAt(j);
1195 OUString dayID( currNode->getChildAt(0)->getValue());
1196 if (str == dayID)
1197 break; // for
1199 if (j >= nbOfDays[i])
1200 incErrorStr( "<StartDayOfWeek> <DayID> must be one of the <DaysOfWeek>, but is", str);
1202 of.writeParameter("startDayOfWeek", str, i);
1203 str = calNode ->getChildAt(4)-> getValue();
1204 sal_Int16 nDays = sal::static_int_cast<sal_Int16>( str.toInt32() );
1205 if (nDays < 1 || (0 < nbOfDays[i] && nbOfDays[i] < nDays))
1206 incErrorInt( "Bad value of MinimalDaysInFirstWeek: %d, must be 1 <= value <= days_in_week", nDays);
1207 of.writeIntParameter("minimalDaysInFirstWeek", i, nDays);
1209 if (!bHasGregorian)
1210 fprintf( stderr, "Warning: %s\n", "No Gregorian calendar defined, are you sure?");
1212 of.writeAsciiString("static const sal_Int16 calendarsCount = ");
1213 of.writeInt(nbOfCalendars);
1214 of.writeAsciiString(";\n\n");
1216 of.writeAsciiString("static const sal_Unicode nbOfDays[] = {");
1217 for(i = 0; i < nbOfCalendars - 1; i++) {
1218 of.writeInt(nbOfDays[i]);
1219 of.writeAsciiString(", ");
1221 of.writeInt(nbOfDays[i]);
1222 of.writeAsciiString("};\n");
1224 of.writeAsciiString("static const sal_Unicode nbOfMonths[] = {");
1225 for(i = 0; i < nbOfCalendars - 1; i++) {
1226 of.writeInt(nbOfMonths[i]);
1227 of.writeAsciiString(", ");
1229 of.writeInt(nbOfMonths[i]);
1230 of.writeAsciiString("};\n");
1232 of.writeAsciiString("static const sal_Unicode nbOfEras[] = {");
1233 for(i = 0; i < nbOfCalendars - 1; i++) {
1234 of.writeInt(nbOfEras[i]);
1235 of.writeAsciiString(", ");
1237 of.writeInt(nbOfEras[i]);
1238 of.writeAsciiString("};\n");
1241 of.writeAsciiString("static const sal_Unicode* calendars[] = {\n");
1242 of.writeAsciiString("\tnbOfDays,\n");
1243 of.writeAsciiString("\tnbOfMonths,\n");
1244 of.writeAsciiString("\tnbOfEras,\n");
1245 for(i = 0; i < nbOfCalendars; i++) {
1246 of.writeAsciiString("\tcalendarID");
1247 of.writeInt(i);
1248 of.writeAsciiString(",\n");
1249 of.writeAsciiString("\tdefaultCalendar");
1250 of.writeInt(i);
1251 of.writeAsciiString(",\n");
1252 if (nbOfDays[i] == 0) {
1253 of.writeAsciiString("\tdayRef");
1254 of.writeInt(i); of.writeAsciiString(",\n");
1255 of.writeAsciiString("\tdayRefName");
1256 of.writeInt(i); of.writeAsciiString(",\n");
1257 } else {
1258 for(j = 0; j < nbOfDays[i]; j++) {
1259 of.writeAsciiString("\tdayID");
1260 of.writeInt(i); of.writeInt(j); of.writeAsciiString(",\n");
1261 of.writeAsciiString("\tdayDefaultAbbrvName");
1262 of.writeInt(i); of.writeInt(j); of.writeAsciiString(",\n");
1263 of.writeAsciiString("\tdayDefaultFullName");of.writeInt(i); of.writeInt(j); of.writeAsciiString(",\n");
1266 if (nbOfMonths[i] == 0) {
1267 of.writeAsciiString("\tmonthRef");
1268 of.writeInt(i); of.writeAsciiString(",\n");
1269 of.writeAsciiString("\tmonthRefName");
1270 of.writeInt(i); of.writeAsciiString(",\n");
1271 } else {
1272 for(j = 0; j < nbOfMonths[i]; j++) {
1273 of.writeAsciiString("\tmonthID");of.writeInt(i);of.writeInt(j);of.writeAsciiString(",\n");
1274 of.writeAsciiString("\tmonthDefaultAbbrvName");of.writeInt(i);of.writeInt(j);of.writeAsciiString(",\n");
1275 of.writeAsciiString("\tmonthDefaultFullName");of.writeInt(i);of.writeInt(j);of.writeAsciiString(",\n");
1278 if (nbOfEras[i] == 0) {
1279 of.writeAsciiString("\teraRef");
1280 of.writeInt(i); of.writeAsciiString(",\n");
1281 of.writeAsciiString("\teraRefName");
1282 of.writeInt(i); of.writeAsciiString(",\n");
1283 } else {
1284 for(j = 0; j < nbOfEras[i]; j++) {
1285 of.writeAsciiString("\teraID"); of.writeInt(i); of.writeInt(j); of.writeAsciiString(",\n");
1286 of.writeAsciiString("\teraDefaultAbbrvName");of.writeInt(i);of.writeInt(j);of.writeAsciiString(",\n");
1287 of.writeAsciiString("\teraDefaultFullName");of.writeInt(i);of.writeInt(j);of.writeAsciiString(",\n");
1290 of.writeAsciiString("\tstartDayOfWeek");of.writeInt(i); of.writeAsciiString(",\n");
1291 of.writeAsciiString("\tminimalDaysInFirstWeek");of.writeInt(i); of.writeAsciiString(",\n");
1294 of.writeAsciiString("};\n\n");
1295 of.writeFunction("getAllCalendars_", "calendarsCount", "calendars");
1297 delete []nbOfDays;
1298 delete []nbOfMonths;
1299 delete []nbOfEras;
1302 void LCCurrencyNode :: generateCode (const OFileWriter &of) const
1304 ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
1305 if (useLocale.getLength() > 0) {
1306 of.writeRefFunction("getAllCurrencies_", useLocale);
1307 return;
1309 sal_Int16 nbOfCurrencies = 0;
1310 ::rtl::OUString str;
1311 sal_Int16 i;
1313 bool bTheDefault= false;
1314 bool bTheCompatible = false;
1315 for ( i = 0; i < getNumberOfChildren(); i++,nbOfCurrencies++) {
1316 LocaleNode * calNode = getChildAt (i);
1317 str = calNode->getAttr() -> getValueByName("default");
1318 bool bDefault = of.writeDefaultParameter("Currency", str, nbOfCurrencies);
1319 str = calNode->getAttr() -> getValueByName("usedInCompatibleFormatCodes");
1320 bool bCompatible = of.writeDefaultParameter("CurrencyUsedInCompatibleFormatCodes", str, nbOfCurrencies);
1321 str = calNode->getAttr() -> getValueByName("legacyOnly");
1322 bool bLegacy = of.writeDefaultParameter("CurrencyLegacyOnly", str, nbOfCurrencies);
1323 if (bLegacy && (bDefault || bCompatible))
1324 incError( "Currency: if legacyOnly==true, both 'default' and 'usedInCompatibleFormatCodes' must be false.");
1325 if (bDefault)
1327 if (bTheDefault)
1328 incError( "Currency: more than one default currency.");
1329 bTheDefault = true;
1331 if (bCompatible)
1333 if (bTheCompatible)
1334 incError( "Currency: more than one currency flagged as usedInCompatibleFormatCodes.");
1335 bTheCompatible = true;
1337 str = calNode -> findNode ("CurrencyID") -> getValue();
1338 of.writeParameter("currencyID", str, nbOfCurrencies);
1339 str = calNode -> findNode ("CurrencySymbol") -> getValue();
1340 of.writeParameter("currencySymbol", str, nbOfCurrencies);
1341 str = calNode -> findNode ("BankSymbol") -> getValue();
1342 of.writeParameter("bankSymbol", str, nbOfCurrencies);
1343 str = calNode -> findNode ("CurrencyName") -> getValue();
1344 of.writeParameter("currencyName", str, nbOfCurrencies);
1345 str = calNode -> findNode ("DecimalPlaces") -> getValue();
1346 sal_Int16 nDecimalPlaces = (sal_Int16)str.toInt32();
1347 of.writeIntParameter("currencyDecimalPlaces", nbOfCurrencies, nDecimalPlaces);
1348 of.writeAsciiString("\n");
1351 if (!bTheDefault)
1352 incError( "Currency: no default currency.");
1353 if (!bTheCompatible)
1354 incError( "Currency: no currency flagged as usedInCompatibleFormatCodes.");
1356 of.writeAsciiString("static const sal_Int16 currencyCount = ");
1357 of.writeInt(nbOfCurrencies);
1358 of.writeAsciiString(";\n\n");
1359 of.writeAsciiString("static const sal_Unicode* currencies[] = {\n");
1360 for(i = 0; i < nbOfCurrencies; i++) {
1361 of.writeAsciiString("\tcurrencyID");
1362 of.writeInt(i);
1363 of.writeAsciiString(",\n");
1364 of.writeAsciiString("\tcurrencySymbol");
1365 of.writeInt(i);
1366 of.writeAsciiString(",\n");
1367 of.writeAsciiString("\tbankSymbol");
1368 of.writeInt(i);
1369 of.writeAsciiString(",\n");
1370 of.writeAsciiString("\tcurrencyName");
1371 of.writeInt(i);
1372 of.writeAsciiString(",\n");
1373 of.writeAsciiString("\tdefaultCurrency");
1374 of.writeInt(i);
1375 of.writeAsciiString(",\n");
1376 of.writeAsciiString("\tdefaultCurrencyUsedInCompatibleFormatCodes");
1377 of.writeInt(i);
1378 of.writeAsciiString(",\n");
1379 of.writeAsciiString("\tcurrencyDecimalPlaces");
1380 of.writeInt(i);
1381 of.writeAsciiString(",\n");
1382 of.writeAsciiString("\tdefaultCurrencyLegacyOnly");
1383 of.writeInt(i);
1384 of.writeAsciiString(",\n");
1386 of.writeAsciiString("};\n\n");
1387 of.writeFunction("getAllCurrencies_", "currencyCount", "currencies");
1390 void LCTransliterationNode::generateCode (const OFileWriter &of) const
1392 ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
1393 if (useLocale.getLength() > 0) {
1394 of.writeRefFunction("getTransliterations_", useLocale);
1395 return;
1397 sal_Int16 nbOfModules = 0;
1398 ::rtl::OUString str;
1399 sal_Int16 i;
1401 for ( i = 0; i < getNumberOfChildren(); i++,nbOfModules++) {
1402 LocaleNode * calNode = getChildAt (i);
1403 str = calNode->getAttr() -> getValueByIndex(0);
1404 of.writeParameter("Transliteration", str, nbOfModules);
1406 of.writeAsciiString("static const sal_Int16 nbOfTransliterations = ");
1407 of.writeInt(nbOfModules);
1408 of.writeAsciiString(";\n\n");
1410 of.writeAsciiString("\nstatic const sal_Unicode* LCTransliterationsArray[] = {\n");
1411 for( i = 0; i < nbOfModules; i++) {
1412 of.writeAsciiString("\tTransliteration");
1413 of.writeInt(i);
1414 of.writeAsciiString(",\n");
1416 of.writeAsciiString("};\n\n");
1417 of.writeFunction("getTransliterations_", "nbOfTransliterations", "LCTransliterationsArray");
1420 struct NameValuePair {
1421 const sal_Char *name;
1422 const sal_Char *value;
1424 static NameValuePair ReserveWord[] = {
1425 { "trueWord", "true" },
1426 { "falseWord", "false" },
1427 { "quarter1Word", "1st quarter" },
1428 { "quarter2Word", "2nd quarter" },
1429 { "quarter3Word", "3rd quarter" },
1430 { "quarter4Word", "4th quarter" },
1431 { "aboveWord", "above" },
1432 { "belowWord", "below" },
1433 { "quarter1Abbreviation", "Q1" },
1434 { "quarter2Abbreviation", "Q2" },
1435 { "quarter3Abbreviation", "Q3" },
1436 { "quarter4Abbreviation", "Q4" }
1439 void LCMiscNode::generateCode (const OFileWriter &of) const
1441 ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
1442 if (useLocale.getLength() > 0) {
1443 of.writeRefFunction("getForbiddenCharacters_", useLocale);
1444 of.writeRefFunction("getBreakIteratorRules_", useLocale);
1445 of.writeRefFunction("getReservedWords_", useLocale);
1446 return;
1448 const LocaleNode * reserveNode = findNode("ReservedWords");
1449 if (!reserveNode)
1450 incError( "No ReservedWords element."); // should not happen if validated..
1451 const LocaleNode * forbidNode = findNode("ForbiddenCharacters");
1452 const LocaleNode * breakNode = findNode("BreakIteratorRules");
1454 bool bEnglishLocale = (strncmp( of.getLocale(), "en_", 3) == 0);
1456 sal_Int16 nbOfWords = 0;
1457 ::rtl::OUString str;
1458 sal_Int16 i;
1460 for ( i = 0; i < sal_Int16(sizeof(ReserveWord)/sizeof(ReserveWord[0])); i++,nbOfWords++) {
1461 const LocaleNode * curNode = (reserveNode ? reserveNode->findNode(
1462 ReserveWord[i].name) : 0);
1463 if (!curNode)
1464 fprintf( stderr,
1465 "Warning: No %s in ReservedWords, using en_US default: \"%s\".\n",
1466 ReserveWord[i].name, ReserveWord[i].value);
1467 str = curNode ? curNode -> getValue() : OUString::createFromAscii(ReserveWord[i].value);
1468 if (!str.getLength())
1470 ++nError;
1471 fprintf( stderr, "Error: No content for ReservedWords %s.\n", ReserveWord[i].name);
1473 of.writeParameter("ReservedWord", str, nbOfWords);
1474 // "true", ..., "below" trigger untranslated warning.
1475 if (!bEnglishLocale && curNode && (0 <= i && i <= 7) &&
1476 str.equalsIgnoreAsciiCaseAscii( ReserveWord[i].value))
1478 fprintf( stderr,
1479 "Warning: ReservedWord %s seems to be untranslated \"%s\".\n",
1480 ReserveWord[i].name, ReserveWord[i].value);
1483 of.writeAsciiString("static const sal_Int16 nbOfReservedWords = ");
1484 of.writeInt(nbOfWords);
1485 of.writeAsciiString(";\n\n");
1486 of.writeAsciiString("\nstatic const sal_Unicode* LCReservedWordsArray[] = {\n");
1487 for( i = 0; i < nbOfWords; i++) {
1488 of.writeAsciiString("\tReservedWord");
1489 of.writeInt(i);
1490 of.writeAsciiString(",\n");
1492 of.writeAsciiString("};\n\n");
1493 of.writeFunction("getReservedWords_", "nbOfReservedWords", "LCReservedWordsArray");
1495 if (forbidNode) {
1496 of.writeParameter( "forbiddenBegin", forbidNode -> getChildAt(0)->getValue());
1497 of.writeParameter( "forbiddenEnd", forbidNode -> getChildAt(1)->getValue());
1498 of.writeParameter( "hangingChars", forbidNode -> getChildAt(2)->getValue());
1499 } else {
1500 of.writeParameter( "forbiddenBegin", ::rtl::OUString());
1501 of.writeParameter( "forbiddenEnd", ::rtl::OUString());
1502 of.writeParameter( "hangingChars", ::rtl::OUString());
1504 of.writeAsciiString("\nstatic const sal_Unicode* LCForbiddenCharactersArray[] = {\n");
1505 of.writeAsciiString("\tforbiddenBegin,\n");
1506 of.writeAsciiString("\tforbiddenEnd,\n");
1507 of.writeAsciiString("\thangingChars\n");
1508 of.writeAsciiString("};\n\n");
1509 of.writeFunction("getForbiddenCharacters_", "3", "LCForbiddenCharactersArray");
1511 if (breakNode) {
1512 of.writeParameter( "EditMode", breakNode -> getChildAt(0)->getValue());
1513 of.writeParameter( "DictionaryMode", breakNode -> getChildAt(1)->getValue());
1514 of.writeParameter( "WordCountMode", breakNode -> getChildAt(2)->getValue());
1515 of.writeParameter( "CharacterMode", breakNode -> getChildAt(3)->getValue());
1516 of.writeParameter( "LineMode", breakNode -> getChildAt(4)->getValue());
1517 } else {
1518 of.writeParameter( "EditMode", ::rtl::OUString());
1519 of.writeParameter( "DictionaryMode", ::rtl::OUString());
1520 of.writeParameter( "WordCountMode", ::rtl::OUString());
1521 of.writeParameter( "CharacterMode", ::rtl::OUString());
1522 of.writeParameter( "LineMode", ::rtl::OUString());
1524 of.writeAsciiString("\nstatic const sal_Unicode* LCBreakIteratorRulesArray[] = {\n");
1525 of.writeAsciiString("\tEditMode,\n");
1526 of.writeAsciiString("\tDictionaryMode,\n");
1527 of.writeAsciiString("\tWordCountMode,\n");
1528 of.writeAsciiString("\tCharacterMode,\n");
1529 of.writeAsciiString("\tLineMode\n");
1530 of.writeAsciiString("};\n\n");
1531 of.writeFunction("getBreakIteratorRules_", "5", "LCBreakIteratorRulesArray");
1535 void LCNumberingLevelNode::generateCode (const OFileWriter &of) const
1537 of.writeAsciiString("// ---> ContinuousNumbering\n");
1538 ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
1539 if (useLocale.getLength() > 0) {
1540 of.writeRefFunction2("getContinuousNumberingLevels_", useLocale);
1541 return;
1544 // hard code number of attributes per style.
1545 const int nAttributes = 5;
1546 const char* attr[ nAttributes ] = { "Prefix", "NumType", "Suffix", "Transliteration", "NatNum" };
1548 // record each attribute of each style in a static C++ variable.
1549 // determine number of styles on the fly.
1550 sal_Int32 nStyles = getNumberOfChildren();
1551 sal_Int32 i;
1553 for( i = 0; i < nStyles; i++ )
1555 const Attr* q = getChildAt( i )->getAttr();
1556 for( sal_Int32 j=0; j<nAttributes; j++ )
1558 const char* name = attr[j];
1559 OUString value = q->getValueByName( name );
1560 of.writeParameter("continuous", name, value, sal::static_int_cast<sal_Int16>(i) );
1564 // record number of styles and attributes.
1565 of.writeAsciiString("static const sal_Int16 continuousNbOfStyles = ");
1566 of.writeInt( sal::static_int_cast<sal_Int16>( nStyles ) );
1567 of.writeAsciiString(";\n\n");
1568 of.writeAsciiString("static const sal_Int16 continuousNbOfAttributesPerStyle = ");
1569 of.writeInt( nAttributes );
1570 of.writeAsciiString(";\n\n");
1572 // generate code. (intermediate arrays)
1573 for( i=0; i<nStyles; i++ )
1575 of.writeAsciiString("\nstatic const sal_Unicode* continuousStyle" );
1576 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
1577 of.writeAsciiString("[] = {\n");
1578 for( sal_Int32 j=0; j<nAttributes; j++)
1580 of.writeAsciiString("\t");
1581 of.writeAsciiString( "continuous" );
1582 of.writeAsciiString( attr[j] );
1583 of.writeInt(sal::static_int_cast<sal_Int16>(i));
1584 of.writeAsciiString(",\n");
1586 of.writeAsciiString("\t0\n};\n\n");
1589 // generate code. (top-level array)
1590 of.writeAsciiString("\n");
1591 of.writeAsciiString("static const sal_Unicode** LCContinuousNumberingLevelsArray[] = {\n" );
1592 for( i=0; i<nStyles; i++ )
1594 of.writeAsciiString( "\t" );
1595 of.writeAsciiString( "continuousStyle" );
1596 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
1597 of.writeAsciiString( ",\n");
1599 of.writeAsciiString("\t0\n};\n\n");
1600 of.writeFunction2("getContinuousNumberingLevels_", "continuousNbOfStyles",
1601 "continuousNbOfAttributesPerStyle", "LCContinuousNumberingLevelsArray");
1605 void LCOutlineNumberingLevelNode::generateCode (const OFileWriter &of) const
1607 of.writeAsciiString("// ---> OutlineNumbering\n");
1608 ::rtl::OUString useLocale = getAttr() -> getValueByName("ref");
1609 if (useLocale.getLength() > 0) {
1610 of.writeRefFunction3("getOutlineNumberingLevels_", useLocale);
1611 return;
1614 // hardcode number of attributes per level
1615 const int nAttributes = 11;
1616 const char* attr[ nAttributes ] =
1618 "Prefix",
1619 "NumType",
1620 "Suffix",
1621 "BulletChar",
1622 "BulletFontName",
1623 "ParentNumbering",
1624 "LeftMargin",
1625 "SymbolTextDistance",
1626 "FirstLineOffset",
1627 "Transliteration",
1628 "NatNum",
1631 // record each attribute of each level of each style in a static C++ variable.
1632 // determine number of styles and number of levels per style on the fly.
1633 sal_Int32 nStyles = getNumberOfChildren();
1634 vector<sal_Int32> nLevels; // may be different for each style?
1635 for( sal_Int32 i = 0; i < nStyles; i++ )
1637 LocaleNode* p = getChildAt( i );
1638 nLevels.push_back( p->getNumberOfChildren() );
1639 for( sal_Int32 j=0; j<nLevels.back(); j++ )
1641 const Attr* q = p->getChildAt( j )->getAttr();
1642 for( sal_Int32 k=0; k<nAttributes; k++ )
1644 const char* name = attr[k];
1645 OUString value = q->getValueByName( name );
1646 of.writeParameter("outline", name, value,
1647 sal::static_int_cast<sal_Int16>(i),
1648 sal::static_int_cast<sal_Int16>(j) );
1653 // verify that each style has the same number of levels.
1654 for( size_t i=0; i<nLevels.size(); i++ )
1656 if( nLevels[0] != nLevels[i] )
1658 incError( "Numbering levels don't match.");
1662 // record number of attributes, levels, and styles.
1663 of.writeAsciiString("static const sal_Int16 outlineNbOfStyles = ");
1664 of.writeInt( sal::static_int_cast<sal_Int16>( nStyles ) );
1665 of.writeAsciiString(";\n\n");
1666 of.writeAsciiString("static const sal_Int16 outlineNbOfLevelsPerStyle = ");
1667 of.writeInt( sal::static_int_cast<sal_Int16>( nLevels.back() ) );
1668 of.writeAsciiString(";\n\n");
1669 of.writeAsciiString("static const sal_Int16 outlineNbOfAttributesPerLevel = ");
1670 of.writeInt( nAttributes );
1671 of.writeAsciiString(";\n\n");
1673 // too complicated for now...
1674 // of.writeAsciiString("static const sal_Int16 nbOfOutlineNumberingLevels[] = { ");
1675 // for( sal_Int32 j=0; j<nStyles; j++ )
1676 // {
1677 // of.writeInt( nLevels[j] );
1678 // of.writeAsciiString(", ");
1679 // }
1680 // of.writeAsciiString("};\n\n");
1683 for( sal_Int32 i=0; i<nStyles; i++ )
1685 for( sal_Int32 j=0; j<nLevels.back(); j++ )
1687 of.writeAsciiString("static const sal_Unicode* outline");
1688 of.writeAsciiString("Style");
1689 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
1690 of.writeAsciiString("Level");
1691 of.writeInt( sal::static_int_cast<sal_Int16>(j) );
1692 of.writeAsciiString("[] = { ");
1694 for( sal_Int32 k=0; k<nAttributes; k++ )
1696 of.writeAsciiString( "outline" );
1697 of.writeAsciiString( attr[k] );
1698 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
1699 of.writeInt( sal::static_int_cast<sal_Int16>(j) );
1700 of.writeAsciiString(", ");
1702 of.writeAsciiString("NULL };\n");
1706 of.writeAsciiString("\n");
1709 for( sal_Int32 i=0; i<nStyles; i++ )
1711 of.writeAsciiString("static const sal_Unicode** outline");
1712 of.writeAsciiString( "Style" );
1713 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
1714 of.writeAsciiString("[] = { ");
1716 for( sal_Int32 j=0; j<nLevels.back(); j++ )
1718 of.writeAsciiString("outlineStyle");
1719 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
1720 of.writeAsciiString("Level");
1721 of.writeInt( sal::static_int_cast<sal_Int16>(j) );
1722 of.writeAsciiString(", ");
1724 of.writeAsciiString("NULL };\n");
1726 of.writeAsciiString("\n");
1728 of.writeAsciiString("static const sal_Unicode*** LCOutlineNumberingLevelsArray[] = {\n" );
1729 for( sal_Int32 i=0; i<nStyles; i++ )
1731 of.writeAsciiString( "\t" );
1732 of.writeAsciiString( "outlineStyle" );
1733 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
1734 of.writeAsciiString(",\n");
1736 of.writeAsciiString("\tNULL\n};\n\n");
1737 of.writeFunction3("getOutlineNumberingLevels_", "outlineNbOfStyles", "outlineNbOfLevelsPerStyle",
1738 "outlineNbOfAttributesPerLevel", "LCOutlineNumberingLevelsArray");
1741 Attr::Attr (const Reference< XAttributeList > & attr) {
1742 sal_Int16 len = attr->getLength();
1743 name.realloc (len);
1744 value.realloc (len);
1745 for (sal_Int16 i =0; i< len;i++) {
1746 name[i] = attr->getNameByIndex(i);
1747 value[i] = attr -> getValueByIndex(i);
1751 const OUString& Attr::getValueByName (const sal_Char *str) const {
1752 static OUString empty;
1753 sal_Int32 len = name.getLength();
1754 for (sal_Int32 i = 0;i<len;i++)
1755 if (name[i].equalsAscii(str))
1756 return value[i];
1757 return empty;
1760 sal_Int32 Attr::getLength() const{
1761 return name.getLength();
1764 const OUString& Attr::getTypeByIndex (sal_Int32 idx) const {
1765 return name[idx];
1768 const OUString& Attr::getValueByIndex (sal_Int32 idx) const
1770 return value[idx];