Branch libreoffice-5-0-4
[LibreOffice.git] / i18npool / source / localedata / LocaleNode.cxx
blob89325aeaf0ba24747bb35979c271c92a1426f4f6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <algorithm>
24 #include <iostream>
25 #include <set>
26 #include <vector>
28 #include <rtl/ustrbuf.hxx>
29 #include <sal/macros.h>
31 #include "LocaleNode.hxx"
32 #include <com/sun/star/i18n/NumberFormatIndex.hpp>
34 // NOTE: MUST match the Locale versionDTD attribute defined in data/locale.dtd
35 #define LOCALE_VERSION_DTD "2.0.3"
37 typedef ::std::set< OUString > NameSet;
38 typedef ::std::set< sal_Int16 > ValueSet;
40 namespace cssi = ::com::sun::star::i18n;
42 LocaleNode::LocaleNode (const OUString& name, const Reference< XAttributeList > & attr)
43 : aName(name)
44 , aAttribs(attr)
45 , parent(0)
46 , children(0)
47 , nChildren(0)
48 , childArrSize(0)
49 , nError(0)
53 int LocaleNode::getError() const
55 int err = nError;
56 for (sal_Int32 i=0;i<nChildren;i++)
57 err += children[i]->getError();
58 return err;
61 void LocaleNode::print () const {
62 printf ("<");
63 OUString str (aName);
64 for(sal_Int32 i = 0; i < str.getLength(); i++)
65 printf( "%c", str[i]);
66 printf (">\n");
69 void LocaleNode::printR () const {
70 print();
71 for (sal_Int32 i=0;i<nChildren;i++)
72 children[i]->printR();
73 printf ("\t");
74 print();
77 void LocaleNode::addChild ( LocaleNode * node) {
78 if (childArrSize <= nChildren) {
79 LocaleNode ** arrN = new LocaleNode*[childArrSize+10];
80 for (sal_Int32 i = 0; i<childArrSize; ++i)
81 arrN[i] = children[i];
82 delete [] children;
83 childArrSize += 10;
84 children = arrN;
86 children[nChildren++] = node;
87 node->setParent (this);
90 void LocaleNode::setParent ( LocaleNode * node) {
91 parent = node;
94 const LocaleNode* LocaleNode::getRoot() const
96 const LocaleNode* pRoot = 0;
97 const LocaleNode* pParent = this;
98 while ( (pParent = pParent->getParent()) != 0 )
99 pRoot = pParent;
100 return pRoot;
103 const LocaleNode * LocaleNode::findNode ( const sal_Char *name) const {
104 if (aName.equalsAscii(name))
105 return this;
106 for (sal_Int32 i = 0; i< nChildren; i++) {
107 const LocaleNode *n=children[i]->findNode(name);
108 if (n)
109 return n;
111 return 0;
114 LocaleNode::~LocaleNode()
116 for (sal_Int32 i=0; i < nChildren; ++i)
117 delete children[i];
118 delete [] children;
121 LocaleNode* LocaleNode::createNode (const OUString& name, const Reference< XAttributeList > & attr)
123 if ( name == "LC_INFO" )
124 return new LCInfoNode (name,attr);
125 if ( name == "LC_CTYPE" )
126 return new LCCTYPENode (name,attr);
127 if ( name == "LC_FORMAT" )
128 return new LCFormatNode (name,attr);
129 if ( name == "LC_FORMAT_1" )
130 return new LCFormatNode (name,attr);
131 if ( name == "LC_CALENDAR" )
132 return new LCCalendarNode (name,attr);
133 if ( name == "LC_CURRENCY" )
134 return new LCCurrencyNode (name,attr);
135 if ( name == "LC_TRANSLITERATION" )
136 return new LCTransliterationNode (name,attr);
137 if ( name == "LC_COLLATION" )
138 return new LCCollationNode (name,attr);
139 if ( name == "LC_INDEX" )
140 return new LCIndexNode (name,attr);
141 if ( name == "LC_SEARCH" )
142 return new LCSearchNode (name,attr);
143 if ( name == "LC_MISC" )
144 return new LCMiscNode (name,attr);
145 if ( name == "LC_NumberingLevel" )
146 return new LCNumberingLevelNode (name, attr);
147 if ( name == "LC_OutLineNumberingLevel" )
148 return new LCOutlineNumberingLevelNode (name, attr);
150 return new LocaleNode(name,attr);
154 // printf(" name: '%s'\n", p->getName().pData->buffer );
155 // printf("value: '%s'\n", p->getValue().pData->buffer );
157 #define OSTR(s) (OUStringToOString( (s), RTL_TEXTENCODING_UTF8).getStr())
159 void print_OUString( const OUString& s )
161 printf( "%s", OSTR(s));
164 bool is_empty_string( const OUString& s )
166 return s.isEmpty() || s == "\n";
169 void print_indent( int depth )
171 for( int i=0; i<depth; i++ ) printf(" ");
174 void print_color( int color )
176 printf("\033[%dm", color);
179 void print_node( const LocaleNode* p, int depth=0 )
181 if( !p ) return;
183 print_indent( depth );
184 printf("<");
185 print_color(36);
186 print_OUString( p->getName() );
187 print_color(0);
188 const Attr& q = p->getAttr();
189 for( sal_Int32 j = 0; j < q.getLength(); ++j )
191 printf(" ");
192 print_color(33);
193 print_OUString( q.getTypeByIndex(j) );
194 print_color(0);
195 printf("=");
196 print_color(31);
197 printf("'");
198 print_OUString( q.getValueByIndex(j) );
199 printf("'");
200 print_color(0);
202 printf(">");
203 printf("\n");
204 if( !is_empty_string( p->getValue() ) )
206 print_indent( depth+1 );
207 printf("value: ");
208 print_color(31);
209 printf("'");
210 print_OUString( p->getValue() );
211 printf("'");
212 print_color(0);
213 printf("\n");
215 for( sal_Int32 i=0; i<p->getNumberOfChildren(); i++ )
217 print_node( p->getChildAt(i), depth+1 );
219 print_indent( depth );
220 printf("</");
221 print_OUString( p->getName() );
222 printf(">");
223 printf("\n");
226 void LocaleNode :: generateCode (const OFileWriter &of) const
228 OUString aDTD = getAttr().getValueByName("versionDTD");
229 if ( aDTD != LOCALE_VERSION_DTD )
231 ++nError;
232 fprintf( stderr, "Error: Locale versionDTD is not %s, see comment in locale.dtd\n", LOCALE_VERSION_DTD);
234 for (sal_Int32 i=0; i<nChildren;i++)
235 children[i]->generateCode (of);
236 // print_node( this );
240 OUString LocaleNode::writeParameterCheckLen( const OFileWriter &of,
241 const char* pParameterName, const LocaleNode* pNode,
242 sal_Int32 nMinLen, sal_Int32 nMaxLen ) const
244 OUString aVal;
245 if (pNode)
246 aVal = pNode->getValue();
247 else
249 ++nError;
250 fprintf( stderr, "Error: node NULL pointer for parameter %s.\n",
251 pParameterName);
253 // write empty data if error
254 of.writeParameter( pParameterName, aVal);
255 sal_Int32 nLen = aVal.getLength();
256 if (nLen < nMinLen)
258 ++nError;
259 fprintf( stderr, "Error: less than %ld character%s (%ld) in %s '%s'.\n",
260 sal::static_int_cast< long >(nMinLen), (nMinLen > 1 ? "s" : ""),
261 sal::static_int_cast< long >(nLen),
262 (pNode ? OSTR( pNode->getName()) : ""),
263 OSTR( aVal));
265 else if (nLen > nMaxLen && nMaxLen >= 0)
266 fprintf( stderr,
267 "Warning: more than %ld character%s (%ld) in %s %s not supported by application.\n",
268 sal::static_int_cast< long >(nMaxLen), (nMaxLen > 1 ? "s" : ""),
269 sal::static_int_cast< long >(nLen),
270 (pNode ? OSTR( pNode->getName()) : ""),
271 OSTR( aVal));
272 return aVal;
276 OUString LocaleNode::writeParameterCheckLen( const OFileWriter &of,
277 const char* pNodeName, const char* pParameterName,
278 sal_Int32 nMinLen, sal_Int32 nMaxLen ) const
280 OUString aVal;
281 const LocaleNode * pNode = findNode( pNodeName);
282 if (pNode)
283 aVal = writeParameterCheckLen( of, pParameterName, pNode, nMinLen, nMaxLen);
284 else
286 ++nError;
287 fprintf( stderr, "Error: node %s not found.\n", pNodeName);
288 // write empty data if error
289 of.writeParameter( pParameterName, aVal);
291 return aVal;
294 void LocaleNode::incError( const char* pStr ) const
296 ++nError;
297 fprintf( stderr, "Error: %s\n", pStr);
300 void LocaleNode::incError( const OUString& rStr ) const
302 incError( OSTR( rStr));
305 void LocaleNode::incErrorInt( const char* pStr, int nVal ) const
307 ++nError;
308 fprintf( stderr, pStr, nVal);
311 void LocaleNode::incErrorStr( const char* pStr, const OUString& rVal ) const
313 ++nError;
314 fprintf( stderr, pStr, OSTR( rVal));
317 void LocaleNode::incErrorStrStr( const char* pStr, const OUString& rVal1, const OUString& rVal2 ) const
319 ++nError;
320 fprintf(stderr, pStr, OSTR(rVal1), OSTR(rVal2));
323 void LCInfoNode::generateCode (const OFileWriter &of) const
326 const LocaleNode * languageNode = findNode("Language");
327 const LocaleNode * countryNode = findNode("Country");
328 const LocaleNode * variantNode = findNode("Variant");
330 OUString aLanguage;
332 if (languageNode)
334 aLanguage = languageNode->getChildAt(0)->getValue();
335 if (!(aLanguage.getLength() == 2 || aLanguage.getLength() == 3))
336 incErrorStr( "Error: langID '%s' not 2-3 characters\n", aLanguage);
337 of.writeParameter("langID", aLanguage);
338 of.writeParameter("langDefaultName", languageNode->getChildAt(1)->getValue());
340 else
341 incError( "No Language node.");
342 if (countryNode)
344 OUString aCountry( countryNode->getChildAt(0)->getValue());
345 if (!(aCountry.isEmpty() || aCountry.getLength() == 2))
346 incErrorStr( "Error: countryID '%s' not empty or more than 2 characters\n", aCountry);
347 of.writeParameter("countryID", aCountry);
348 of.writeParameter("countryDefaultName", countryNode->getChildAt(1)->getValue());
350 else
351 incError( "No Country node.");
352 if (variantNode)
354 // If given Variant must be at least ll-Ssss and language must be 'qlt'
355 OUString aVariant( variantNode->getValue());
356 if (!(aVariant.isEmpty() || (aVariant.getLength() >= 7 && aVariant.indexOf('-') >= 2)))
357 incErrorStr( "Error: invalid Variant '%s'\n", aVariant);
358 if (!(aVariant.isEmpty() || aLanguage == "qlt"))
359 incErrorStrStr( "Error: Variant '%s' given but Language '%s' is not 'qlt'\n", aVariant, aLanguage);
360 of.writeParameter("Variant", aVariant);
362 else
363 of.writeParameter("Variant", OUString());
364 of.writeAsciiString("\nstatic const sal_Unicode* LCInfoArray[] = {\n");
365 of.writeAsciiString("\tlangID,\n");
366 of.writeAsciiString("\tlangDefaultName,\n");
367 of.writeAsciiString("\tcountryID,\n");
368 of.writeAsciiString("\tcountryDefaultName,\n");
369 of.writeAsciiString("\tVariant\n");
370 of.writeAsciiString("};\n\n");
371 of.writeFunction("getLCInfo_", "0", "LCInfoArray");
375 static OUString aDateSep;
376 static OUString aDecSep;
378 void LCCTYPENode::generateCode (const OFileWriter &of) const
380 const LocaleNode * sepNode = 0;
381 OUString useLocale = getAttr().getValueByName("ref");
382 if (!useLocale.isEmpty()) {
383 useLocale = useLocale.replace( '-', '_');
384 of.writeRefFunction("getLocaleItem_", useLocale);
385 return;
387 OUString str = getAttr().getValueByName("unoid");
388 of.writeAsciiString("\n\n");
389 of.writeParameter("LC_CTYPE_Unoid", str);
391 aDateSep =
392 writeParameterCheckLen( of, "DateSeparator", "dateSeparator", 1, 1);
393 OUString aThoSep =
394 writeParameterCheckLen( of, "ThousandSeparator", "thousandSeparator", 1, 1);
395 aDecSep =
396 writeParameterCheckLen( of, "DecimalSeparator", "decimalSeparator", 1, 1);
397 OUString aTimeSep =
398 writeParameterCheckLen( of, "TimeSeparator", "timeSeparator", 1, 1);
399 OUString aTime100Sep =
400 writeParameterCheckLen( of, "Time100SecSeparator", "time100SecSeparator", 1, 1);
401 OUString aListSep =
402 writeParameterCheckLen( of, "ListSeparator", "listSeparator", 1, 1);
404 OUString aLDS;
406 sepNode = findNode("LongDateDayOfWeekSeparator");
407 aLDS = sepNode->getValue();
408 of.writeParameter("LongDateDayOfWeekSeparator", aLDS);
409 if (aLDS == ",")
410 fprintf( stderr, "Warning: %s\n",
411 "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\".");
413 sepNode = findNode("LongDateDaySeparator");
414 aLDS = sepNode->getValue();
415 of.writeParameter("LongDateDaySeparator", aLDS);
416 if (aLDS == "," || aLDS == ".")
417 fprintf( stderr, "Warning: %s\n",
418 "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\".");
420 sepNode = findNode("LongDateMonthSeparator");
421 aLDS = sepNode->getValue();
422 of.writeParameter("LongDateMonthSeparator", aLDS);
423 if (aLDS.isEmpty())
424 fprintf( stderr, "Warning: %s\n",
425 "LongDateMonthSeparator is empty. Usually this is not the case and may lead to concatenated display names like \"Wednesday, May9, 2007\".");
427 sepNode = findNode("LongDateYearSeparator");
428 aLDS = sepNode->getValue();
429 of.writeParameter("LongDateYearSeparator", aLDS);
430 if (aLDS.isEmpty())
431 fprintf( stderr, "Warning: %s\n",
432 "LongDateYearSeparator is empty. Usually this is not the case and may lead to concatenated display names like \"Wednesday, 2007May 9\".");
435 int nSavErr = nError;
436 int nWarn = 0;
437 if (aDateSep == aTimeSep)
438 incError( "DateSeparator equals TimeSeparator.");
439 if (aDecSep == aThoSep)
440 incError( "DecimalSeparator equals ThousandSeparator.");
441 if ( aThoSep == " " )
442 incError( "ThousandSeparator is an ' ' ordinary space, this should be a non-breaking space U+00A0 instead.");
443 if (aListSep == aDecSep)
444 fprintf( stderr, "Warning: %s\n",
445 "ListSeparator equals DecimalSeparator.");
446 if (aListSep == aThoSep)
447 fprintf( stderr, "Warning: %s\n",
448 "ListSeparator equals ThousandSeparator.");
449 if (aListSep.getLength() != 1 || aListSep[0] != ';')
451 incError( "ListSeparator not ';' semicolon. Strongly recommended. Currently required.");
452 ++nSavErr; // format codes not affected
454 if (aTimeSep == aTime100Sep)
455 ++nWarn, fprintf( stderr, "Warning: %s\n",
456 "Time100SecSeparator equals TimeSeparator, this is probably an error.");
457 if (aDecSep != aTime100Sep)
458 ++nWarn, fprintf( stderr, "Warning: %s\n",
459 "Time100SecSeparator is different from DecimalSeparator, this may be correct or not. Intended?");
460 if (nSavErr != nError || nWarn)
461 fprintf( stderr, "Warning: %s\n",
462 "Don't forget to adapt corresponding FormatCode elements when changing separators.");
464 OUString aQuoteStart =
465 writeParameterCheckLen( of, "QuotationStart", "quotationStart", 1, 1);
466 OUString aQuoteEnd =
467 writeParameterCheckLen( of, "QuotationEnd", "quotationEnd", 1, 1);
468 OUString aDoubleQuoteStart =
469 writeParameterCheckLen( of, "DoubleQuotationStart", "doubleQuotationStart", 1, 1);
470 OUString aDoubleQuoteEnd =
471 writeParameterCheckLen( of, "DoubleQuotationEnd", "doubleQuotationEnd", 1, 1);
473 if (aQuoteStart.toChar() <= 127 && aQuoteEnd.toChar() > 127)
474 fprintf( stderr, "Warning: %s\n",
475 "QuotationStart is an ASCII character but QuotationEnd is not.");
476 if (aQuoteEnd.toChar() <= 127 && aQuoteStart.toChar() > 127)
477 fprintf( stderr, "Warning: %s\n",
478 "QuotationEnd is an ASCII character but QuotationStart is not.");
479 if (aDoubleQuoteStart.toChar() <= 127 && aDoubleQuoteEnd.toChar() > 127)
480 fprintf( stderr, "Warning: %s\n",
481 "DoubleQuotationStart is an ASCII character but DoubleQuotationEnd is not.");
482 if (aDoubleQuoteEnd.toChar() <= 127 && aDoubleQuoteStart.toChar() > 127)
483 fprintf( stderr, "Warning: %s\n",
484 "DoubleQuotationEnd is an ASCII character but DoubleQuotationStart is not.");
485 if (aQuoteStart.toChar() <= 127 && aQuoteEnd.toChar() <= 127)
486 fprintf( stderr, "Warning: %s\n",
487 "QuotationStart and QuotationEnd are both ASCII characters. Not necessarily an issue, but unusual.");
488 if (aDoubleQuoteStart.toChar() <= 127 && aDoubleQuoteEnd.toChar() <= 127)
489 fprintf( stderr, "Warning: %s\n",
490 "DoubleQuotationStart and DoubleQuotationEnd are both ASCII characters. Not necessarily an issue, but unusual.");
491 if (aQuoteStart == aQuoteEnd)
492 fprintf( stderr, "Warning: %s\n",
493 "QuotationStart equals QuotationEnd. Not necessarily an issue, but unusual.");
494 if (aDoubleQuoteStart == aDoubleQuoteEnd)
495 fprintf( stderr, "Warning: %s\n",
496 "DoubleQuotationStart equals DoubleQuotationEnd. Not necessarily an issue, but unusual.");
497 /* TODO: should equalness of single and double quotes be an error? Would
498 * need to adapt quite some locales' data. */
499 if (aQuoteStart == aDoubleQuoteStart)
500 fprintf( stderr, "Warning: %s\n",
501 "QuotationStart equals DoubleQuotationStart. Not necessarily an isue, but unusual.");
502 if (aQuoteEnd == aDoubleQuoteEnd)
503 fprintf( stderr, "Warning: %s\n",
504 "QuotationEnd equals DoubleQuotationEnd. Not necessarily an issue, but unusual.");
505 // Known good values, exclude ASCII single (U+0027, ') and double (U+0022, ") quotes.
506 int ic;
507 switch (ic = aQuoteStart.toChar())
509 case 0x2018: // LEFT SINGLE QUOTATION MARK
510 case 0x201a: // SINGLE LOW-9 QUOTATION MARK
511 case 0x201b: // SINGLE HIGH-REVERSED-9 QUOTATION MARK
512 case 0x2039: // SINGLE LEFT-POINTING ANGLE QUOTATION MARK
513 case 0x203a: // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
514 case 0x300c: // LEFT CORNER BRACKET (Chinese)
516 break;
517 default:
518 fprintf( stderr, "Warning: %s U+%04X %s\n",
519 "QuotationStart may be wrong:", ic, OSTR( aQuoteStart));
521 switch (ic = aQuoteEnd.toChar())
523 case 0x2019: // RIGHT SINGLE QUOTATION MARK
524 case 0x201a: // SINGLE LOW-9 QUOTATION MARK
525 case 0x201b: // SINGLE HIGH-REVERSED-9 QUOTATION MARK
526 case 0x2039: // SINGLE LEFT-POINTING ANGLE QUOTATION MARK
527 case 0x203a: // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
528 case 0x300d: // RIGHT CORNER BRACKET (Chinese)
530 break;
531 default:
532 fprintf( stderr, "Warning: %s U+%04X %s\n",
533 "QuotationEnd may be wrong:", ic, OSTR( aQuoteEnd));
535 switch (ic = aDoubleQuoteStart.toChar())
537 case 0x00ab: // LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
538 case 0x00bb: // RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
539 case 0x201c: // LEFT DOUBLE QUOTATION MARK
540 case 0x201e: // DOUBLE LOW-9 QUOTATION MARK
541 case 0x201f: // DOUBLE HIGH-REVERSED-9 QUOTATION MARK
542 case 0x300e: // LEFT WHITE CORNER BRACKET (Chinese)
544 break;
545 default:
546 fprintf( stderr, "Warning: %s U+%04X %s\n",
547 "DoubleQuotationStart may be wrong:", ic, OSTR( aDoubleQuoteStart));
549 switch (ic = aDoubleQuoteEnd.toChar())
551 case 0x00ab: // LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
552 case 0x00bb: // RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
553 case 0x201d: // RIGHT DOUBLE QUOTATION MARK
554 case 0x201e: // DOUBLE LOW-9 QUOTATION MARK
555 case 0x201f: // DOUBLE HIGH-REVERSED-9 QUOTATION MARK
556 case 0x300f: // RIGHT WHITE CORNER BRACKET (Chinese)
558 break;
559 default:
560 fprintf( stderr, "Warning: %s U+%04X %s\n",
561 "DoubleQuotationEnd may be wrong:", ic, OSTR( aDoubleQuoteEnd));
564 writeParameterCheckLen( of, "TimeAM", "timeAM", 1, -1);
565 writeParameterCheckLen( of, "TimePM", "timePM", 1, -1);
566 sepNode = findNode("MeasurementSystem");
567 of.writeParameter("measurementSystem", sepNode->getValue());
569 of.writeAsciiString("\nstatic const sal_Unicode* LCType[] = {\n");
570 of.writeAsciiString("\tLC_CTYPE_Unoid,\n");
571 of.writeAsciiString("\tdateSeparator,\n");
572 of.writeAsciiString("\tthousandSeparator,\n");
573 of.writeAsciiString("\tdecimalSeparator,\n");
574 of.writeAsciiString("\ttimeSeparator,\n");
575 of.writeAsciiString("\ttime100SecSeparator,\n");
576 of.writeAsciiString("\tlistSeparator,\n");
577 of.writeAsciiString("\tquotationStart,\n");
578 of.writeAsciiString("\tquotationEnd,\n");
579 of.writeAsciiString("\tdoubleQuotationStart,\n");
580 of.writeAsciiString("\tdoubleQuotationEnd,\n");
581 of.writeAsciiString("\ttimeAM,\n");
582 of.writeAsciiString("\ttimePM,\n");
583 of.writeAsciiString("\tmeasurementSystem,\n");
584 of.writeAsciiString("\tLongDateDayOfWeekSeparator,\n");
585 of.writeAsciiString("\tLongDateDaySeparator,\n");
586 of.writeAsciiString("\tLongDateMonthSeparator,\n");
587 of.writeAsciiString("\tLongDateYearSeparator\n");
588 of.writeAsciiString("};\n\n");
589 of.writeFunction("getLocaleItem_", "0", "LCType");
593 static OUString sTheCurrencyReplaceTo;
594 static OUString sTheCompatibleCurrency;
595 static OUString sTheDateEditFormat;
597 sal_Int16 LCFormatNode::mnSection = 0;
598 sal_Int16 LCFormatNode::mnFormats = 0;
600 void LCFormatNode::generateCode (const OFileWriter &of) const
602 if (mnSection >= 2)
603 incError("more than 2 LC_FORMAT sections");
605 ::std::vector< OUString > theDateAcceptancePatterns;
607 OUString useLocale(getAttr().getValueByName("ref"));
609 OUString str;
610 OUString strFrom( getAttr().getValueByName("replaceFrom"));
611 if (useLocale.isEmpty())
613 of.writeParameter("replaceFrom", strFrom, mnSection);
615 str = getAttr().getValueByName("replaceTo");
616 if (!strFrom.isEmpty() && str.isEmpty())
617 incErrorStr("replaceFrom=\"%s\" replaceTo=\"\" is empty replacement.\n", strFrom);
618 // Locale data generator inserts FFFF for LangID, we need to adapt that.
619 if (str.endsWithIgnoreAsciiCase( "-FFFF]"))
620 incErrorStr("replaceTo=\"%s\" needs FFFF to be adapted to the real LangID value.\n", str);
621 of.writeParameter("replaceTo", str, mnSection);
622 // Remember the replaceTo value for "[CURRENCY]" to check format codes.
623 if ( strFrom == "[CURRENCY]" )
624 sTheCurrencyReplaceTo = str;
625 // Remember the currency symbol if present.
626 if (str.startsWith( "[$" ))
628 sal_Int32 nHyphen = str.indexOf( '-');
629 if (nHyphen >= 3)
631 sTheCompatibleCurrency = str.copy( 2, nHyphen - 2);
635 if (!useLocale.isEmpty())
637 if (!strFrom.isEmpty() && strFrom != "[CURRENCY]") //???
639 incErrorStrStr(
640 "Error: non-empty replaceFrom=\"%s\" with non-empty ref=\"%s\".",
641 strFrom, useLocale);
643 useLocale = useLocale.replace( '-', '_');
644 switch (mnSection)
646 case 0:
647 of.writeRefFunction("getAllFormats0_", useLocale, "replaceTo0");
648 break;
649 case 1:
650 of.writeRefFunction("getAllFormats1_", useLocale, "replaceTo1");
651 break;
653 of.writeRefFunction("getDateAcceptancePatterns_", useLocale);
654 return;
657 sal_Int16 formatCount = mnFormats;
658 NameSet aMsgIdSet;
659 ValueSet aFormatIndexSet;
660 NameSet aDefaultsSet;
661 bool bCtypeIsRef = false;
662 bool bHaveEngineering = false;
664 for (sal_Int16 i = 0; i< getNumberOfChildren() ; i++, formatCount++)
666 LocaleNode * currNode = getChildAt (i);
667 if ( currNode->getName() == "DateAcceptancePattern" )
669 if (mnSection > 0)
670 incError( "DateAcceptancePattern only handled in LC_FORMAT, not LC_FORMAT_1");
671 else
672 theDateAcceptancePatterns.push_back( currNode->getValue());
673 --formatCount;
674 continue; // for
676 if ( currNode->getName() != "FormatElement" )
678 incErrorStr( "Error: Undefined element '%s' in LC_FORMAT\n", currNode->getName());
679 --formatCount;
680 continue; // for
683 OUString aUsage;
684 OUString aType;
685 OUString aFormatIndex;
686 // currNode -> print();
687 const Attr &currNodeAttr = currNode->getAttr();
688 //printf ("getLen() = %d\n", currNode->getAttr().getLength());
690 str = currNodeAttr.getValueByName("msgid");
691 if (!aMsgIdSet.insert( str).second)
692 incErrorStr( "Error: Duplicated msgid=\"%s\" in FormatElement.\n", str);
693 of.writeParameter("FormatKey", str, formatCount);
695 str = currNodeAttr.getValueByName("default");
696 bool bDefault = str == "true";
697 of.writeDefaultParameter("FormatElement", str, formatCount);
699 aType = currNodeAttr.getValueByName("type");
700 of.writeParameter("FormatType", aType, formatCount);
702 aUsage = currNodeAttr.getValueByName("usage");
703 of.writeParameter("FormatUsage", aUsage, formatCount);
705 aFormatIndex = currNodeAttr.getValueByName("formatindex");
706 sal_Int16 formatindex = (sal_Int16)aFormatIndex.toInt32();
707 if (!aFormatIndexSet.insert( formatindex).second)
708 incErrorInt( "Error: Duplicated formatindex=\"%d\" in FormatElement.\n", formatindex);
709 of.writeIntParameter("Formatindex", formatCount, formatindex);
711 // Ensure only one default per usage and type.
712 if (bDefault)
714 OUString aKey( aUsage + "," + aType);
715 if (!aDefaultsSet.insert( aKey).second)
717 OUString aStr( "Duplicated default for usage=\"");
718 aStr += aUsage;
719 aStr += "\" type=\"";
720 aStr += aType;
721 aStr += "\": formatindex=\"";
722 aStr += aFormatIndex;
723 aStr += "\".";
724 incError( aStr);
728 const LocaleNode * n = currNode -> findNode("FormatCode");
729 if (n)
731 of.writeParameter("FormatCode", n->getValue(), formatCount);
732 // Check separator usage for some FormatCode elements.
733 const LocaleNode* pCtype = 0;
734 switch (formatindex)
736 case cssi::NumberFormatIndex::DATE_SYS_DDMMYYYY :
737 sTheDateEditFormat = n->getValue();
738 break;
739 case cssi::NumberFormatIndex::NUMBER_1000DEC2 : // #,##0.00
740 case cssi::NumberFormatIndex::TIME_MMSS00 : // MM:SS.00
741 case cssi::NumberFormatIndex::TIME_HH_MMSS00 : // [HH]:MM:SS.00
743 const LocaleNode* pRoot = getRoot();
744 if (!pRoot)
745 incError( "No root for FormatCode.");
746 else
748 pCtype = pRoot->findNode( "LC_CTYPE");
749 if (!pCtype)
750 incError( "No LC_CTYPE found for FormatCode.");
751 else
753 OUString aRef( pCtype->getAttr().getValueByName("ref"));
754 if (!aRef.isEmpty())
756 aRef = aRef.replace( '-', '_');
757 if (!bCtypeIsRef)
758 fprintf( stderr,
759 "Warning: Can't check separators used in FormatCode due to LC_CTYPE ref=\"%s\".\n"
760 "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",
761 OSTR( aRef));
762 bCtypeIsRef = true;
763 pCtype = 0;
768 break;
769 case cssi::NumberFormatIndex::CURRENCY_1000DEC2 :
770 // Remember the currency symbol if present.
772 sal_Int32 nStart;
773 if (sTheCompatibleCurrency.isEmpty() &&
774 ((nStart = n->getValue().indexOf("[$")) >= 0))
776 OUString aCode( n->getValue());
777 sal_Int32 nHyphen = aCode.indexOf( '-', nStart);
778 if (nHyphen >= nStart + 3)
779 sTheCompatibleCurrency = aCode.copy( nStart + 2, nHyphen - nStart - 2);
782 // fallthru
783 case cssi::NumberFormatIndex::CURRENCY_1000INT :
784 case cssi::NumberFormatIndex::CURRENCY_1000INT_RED :
785 case cssi::NumberFormatIndex::CURRENCY_1000DEC2_RED :
786 case cssi::NumberFormatIndex::CURRENCY_1000DEC2_CCC :
787 case cssi::NumberFormatIndex::CURRENCY_1000DEC2_DASHED :
788 // Currency formats should be something like [C]###0;-[C]###0
789 // and not parenthesized [C]###0;([C]###0) if not en_US.
790 if (strcmp( of.getLocale(), "en_US") != 0)
792 OUString aCode( n->getValue());
793 OUString aPar1( "0)");
794 OUString aPar2( "-)" );
795 OUString aPar3( " )" );
796 OUString aPar4( "])" );
797 if (aCode.indexOf( aPar1 ) > 0 || aCode.indexOf( aPar2 ) > 0 ||
798 aCode.indexOf( aPar3 ) > 0 || aCode.indexOf( aPar4 ) > 0)
799 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);
801 // Check if we have replaceTo for "[CURRENCY]" placeholder.
802 if (sTheCurrencyReplaceTo.isEmpty())
804 OUString aCode( n->getValue());
805 if (aCode.indexOf( "[CURRENCY]" ) >= 0)
806 incErrorInt( "Error: [CURRENCY] replaceTo not found for formatindex=\"%d\".\n", formatindex);
808 break;
809 default:
810 if (aUsage == "SCIENTIFIC_NUMBER")
812 // Check for presence of ##0.00E+00
813 OUString aCode( n->getValue());
814 // Simple check without decimal separator (assumed to
815 // be one UTF-16 character). May be prefixed with
816 // [NatNum1] or other tags.
817 sal_Int32 nInt = aCode.indexOf("##0");
818 sal_Int32 nDec = (nInt < 0 ? -1 : aCode.indexOf("00E+00", nInt));
819 if (nInt >= 0 && nDec == nInt+4)
820 bHaveEngineering = true;
822 break;
824 if (pCtype)
826 int nSavErr = nError;
827 OUString aCode( n->getValue());
828 if (formatindex == cssi::NumberFormatIndex::NUMBER_1000DEC2)
830 sal_Int32 nDec = -1;
831 sal_Int32 nGrp = -1;
832 const LocaleNode* pSep = pCtype->findNode( "DecimalSeparator");
833 if (!pSep)
834 incError( "No DecimalSeparator found for FormatCode.");
835 else
837 nDec = aCode.indexOf( pSep->getValue());
838 if (nDec < 0)
839 incErrorInt( "Error: DecimalSeparator not present in FormatCode formatindex=\"%d\".\n",
840 formatindex);
842 pSep = pCtype->findNode( "ThousandSeparator");
843 if (!pSep)
844 incError( "No ThousandSeparator found for FormatCode.");
845 else
847 nGrp = aCode.indexOf( pSep->getValue());
848 if (nGrp < 0)
849 incErrorInt( "Error: ThousandSeparator not present in FormatCode formatindex=\"%d\".\n",
850 formatindex);
852 if (nDec >= 0 && nGrp >= 0 && nDec <= nGrp)
853 incErrorInt( "Error: Ordering of ThousandSeparator and DecimalSeparator not correct in formatindex=\"%d\".\n",
854 formatindex);
856 if (formatindex == cssi::NumberFormatIndex::TIME_MMSS00 ||
857 formatindex == cssi::NumberFormatIndex::TIME_HH_MMSS00)
859 sal_Int32 nTime = -1;
860 sal_Int32 n100s = -1;
861 const LocaleNode* pSep = pCtype->findNode( "TimeSeparator");
862 if (!pSep)
863 incError( "No TimeSeparator found for FormatCode.");
864 else
866 nTime = aCode.indexOf( pSep->getValue());
867 if (nTime < 0)
868 incErrorInt( "Error: TimeSeparator not present in FormatCode formatindex=\"%d\".\n",
869 formatindex);
871 pSep = pCtype->findNode( "Time100SecSeparator");
872 if (!pSep)
873 incError( "No Time100SecSeparator found for FormatCode.");
874 else
876 n100s = aCode.indexOf( pSep->getValue());
877 if (n100s < 0)
878 incErrorInt( "Error: Time100SecSeparator not present in FormatCode formatindex=\"%d\".\n",
879 formatindex);
880 OUStringBuffer a100s( pSep->getValue());
881 a100s.appendAscii( "00");
882 n100s = aCode.indexOf( a100s.makeStringAndClear());
883 if (n100s < 0)
884 incErrorInt( "Error: Time100SecSeparator+00 not present in FormatCode formatindex=\"%d\".\n",
885 formatindex);
887 if (n100s >= 0 && nTime >= 0 && n100s <= nTime)
888 incErrorInt( "Error: Ordering of Time100SecSeparator and TimeSeparator not correct in formatindex=\"%d\".\n",
889 formatindex);
891 if (nSavErr != nError)
892 fprintf( stderr,
893 "Warning: formatindex=\"%d\",\"%d\",\"%d\" are the only FormatCode elements checked for separator usage, there may be others that have errors.\n",
894 int(cssi::NumberFormatIndex::NUMBER_1000DEC2),
895 int(cssi::NumberFormatIndex::TIME_MMSS00),
896 int(cssi::NumberFormatIndex::TIME_HH_MMSS00));
900 else
901 incError( "No FormatCode in FormatElement.");
902 n = currNode -> findNode("DefaultName");
903 if (n)
904 of.writeParameter("FormatDefaultName", n->getValue(), formatCount);
905 else
906 of.writeParameter("FormatDefaultName", OUString(), formatCount);
910 // Check presence of all required format codes only in first section
911 // LC_FORMAT, not in optional LC_FORMAT_1
912 if (mnSection == 0)
914 // At least one abbreviated date acceptance pattern must be present.
915 if (theDateAcceptancePatterns.empty())
916 incError( "No DateAcceptancePattern present.\n");
917 else
919 bool bHaveAbbr = false;
920 for (::std::vector< OUString >::const_iterator it( theDateAcceptancePatterns.begin());
921 !bHaveAbbr && it != theDateAcceptancePatterns.end(); ++it)
923 if ((*it).indexOf('D') > -1 && (*it).indexOf('M') > -1 && (*it).indexOf('Y') <= -1)
924 bHaveAbbr = true;
926 if (!bHaveAbbr)
927 incError( "No abbreviated DateAcceptancePattern present. For example M/D or D.M.\n");
930 // 0..47 MUST be present, 48,49 MUST NOT be present
931 ValueSet::const_iterator aIter( aFormatIndexSet.begin());
932 for (sal_Int16 nNext = cssi::NumberFormatIndex::NUMBER_START;
933 nNext < cssi::NumberFormatIndex::INDEX_TABLE_ENTRIES; ++nNext)
935 sal_Int16 nHere = ::std::min( ((aIter != aFormatIndexSet.end() ? *aIter :
936 cssi::NumberFormatIndex::INDEX_TABLE_ENTRIES)),
937 cssi::NumberFormatIndex::INDEX_TABLE_ENTRIES);
938 if (aIter != aFormatIndexSet.end()) ++aIter;
939 for ( ; nNext < nHere; ++nNext)
941 switch (nNext)
943 case cssi::NumberFormatIndex::FRACTION_1 :
944 case cssi::NumberFormatIndex::FRACTION_2 :
945 case cssi::NumberFormatIndex::BOOLEAN :
946 case cssi::NumberFormatIndex::TEXT :
947 // generated internally
948 break;
949 default:
950 incErrorInt( "Error: FormatElement formatindex=\"%d\" not present.\n", nNext);
953 switch (nHere)
955 case cssi::NumberFormatIndex::BOOLEAN :
956 incErrorInt( "Error: FormatElement formatindex=\"%d\" reserved for internal ``BOOLEAN''.\n", nNext);
957 break;
958 case cssi::NumberFormatIndex::TEXT :
959 incErrorInt( "Error: FormatElement formatindex=\"%d\" reserved for internal ``@'' (TEXT).\n", nNext);
960 break;
961 default:
962 ; // nothing
966 if (!bHaveEngineering)
967 incError("Engineering notation format not present, e.g. ##0.00E+00 or ##0,00E+00 for usage=\"SCIENTIFIC_NUMBER\"\n");
970 of.writeAsciiString("\nstatic const sal_Int16 ");
971 of.writeAsciiString("FormatElementsCount");
972 of.writeInt(mnSection);
973 of.writeAsciiString(" = ");
974 of.writeInt( formatCount - mnFormats);
975 of.writeAsciiString(";\n");
976 of.writeAsciiString("static const sal_Unicode* ");
977 of.writeAsciiString("FormatElementsArray");
978 of.writeInt(mnSection);
979 of.writeAsciiString("[] = {\n");
980 for(sal_Int16 i = mnFormats; i < formatCount; i++) {
982 of.writeAsciiString("\t");
983 of.writeAsciiString("FormatCode");
984 of.writeInt(i);
985 of.writeAsciiString(",\n");
987 of.writeAsciiString("\t");
988 of.writeAsciiString("FormatDefaultName");
989 of.writeInt(i);
990 of.writeAsciiString(",\n");
992 of.writeAsciiString("\t");
993 of.writeAsciiString("FormatKey");
994 of.writeInt(i);
995 of.writeAsciiString(",\n");
997 of.writeAsciiString("\t");
998 of.writeAsciiString("FormatType");
999 of.writeInt(i);
1000 of.writeAsciiString(",\n");
1002 of.writeAsciiString("\t");
1003 of.writeAsciiString("FormatUsage");
1004 of.writeInt(i);
1005 of.writeAsciiString(",\n");
1007 of.writeAsciiString("\t");
1008 of.writeAsciiString("Formatindex");
1009 of.writeInt(i);
1010 of.writeAsciiString(",\n");
1013 of.writeAsciiString("\tdefaultFormatElement");
1014 of.writeInt(i);
1015 of.writeAsciiString(",\n");
1017 of.writeAsciiString("};\n\n");
1019 switch (mnSection)
1021 case 0:
1022 of.writeFunction("getAllFormats0_", "FormatElementsCount0", "FormatElementsArray0", "replaceFrom0", "replaceTo0");
1023 break;
1024 case 1:
1025 of.writeFunction("getAllFormats1_", "FormatElementsCount1", "FormatElementsArray1", "replaceFrom1", "replaceTo1");
1026 break;
1029 mnFormats = mnFormats + formatCount;
1031 if (mnSection == 0)
1033 // Extract and add date acceptance pattern for full date, so we provide
1034 // at least one valid pattern, even if the number parser doesn't need
1035 // that one.
1036 /* XXX NOTE: only simple [...] modifier and "..." quotes detected and
1037 * ignored, not nested, no fancy stuff. */
1038 sal_Int32 nIndex = 0;
1039 // aDateSep can be empty if LC_CTYPE was a ref=..., determine from
1040 // FormatCode then.
1041 sal_uInt32 cDateSep = (aDateSep.isEmpty() ? 0 : aDateSep.iterateCodePoints( &nIndex));
1042 sal_uInt32 cDateSep2 = cDateSep;
1043 nIndex = 0;
1044 OUStringBuffer aPatternBuf(5);
1045 OUStringBuffer aPatternBuf2(5);
1046 sal_uInt8 nDetected = 0; // bits Y,M,D
1047 bool bInModifier = false;
1048 bool bQuoted = false;
1049 while (nIndex < sTheDateEditFormat.getLength() && nDetected < 7)
1051 sal_uInt32 cChar = sTheDateEditFormat.iterateCodePoints( &nIndex);
1052 if (bInModifier)
1054 if (cChar == ']')
1055 bInModifier = false;
1056 continue; // while
1058 if (bQuoted)
1060 if (cChar == '"')
1061 bQuoted = false;
1062 continue; // while
1064 switch (cChar)
1066 case 'Y':
1067 case 'y':
1068 if (!(nDetected & 4))
1070 aPatternBuf.append( 'Y');
1071 if (!aPatternBuf2.isEmpty())
1072 aPatternBuf2.append( 'Y');
1073 nDetected |= 4;
1075 break;
1076 case 'M':
1077 case 'm':
1078 if (!(nDetected & 2))
1080 aPatternBuf.append( 'M');
1081 if (!aPatternBuf2.isEmpty())
1082 aPatternBuf2.append( 'M');
1083 nDetected |= 2;
1085 break;
1086 case 'D':
1087 case 'd':
1088 if (!(nDetected & 1))
1090 aPatternBuf.append( 'D');
1091 if (!aPatternBuf2.isEmpty())
1092 aPatternBuf2.append( 'D');
1093 nDetected |= 1;
1095 break;
1096 case '[':
1097 bInModifier = true;
1098 break;
1099 case '"':
1100 bQuoted = true;
1101 break;
1102 case '\\':
1103 cChar = sTheDateEditFormat.iterateCodePoints( &nIndex);
1104 break;
1105 case '-':
1106 case '.':
1107 case '/':
1108 // There are locales that use an ISO 8601 edit format
1109 // regardless of what the date separator or other formats
1110 // say, for example hu-HU. Generalize this for all cases
1111 // where the used separator differs and is one of the known
1112 // separators and generate a second pattern with the
1113 // format's separator at the current position.
1114 cDateSep2 = cChar;
1115 // fallthru
1116 default:
1117 if (!cDateSep)
1118 cDateSep = cChar;
1119 if (!cDateSep2)
1120 cDateSep2 = cChar;
1121 if (cDateSep != cDateSep2 && aPatternBuf2.isEmpty())
1122 aPatternBuf2 = aPatternBuf;
1123 if (cChar == cDateSep || cChar == cDateSep2)
1124 aPatternBuf.append( OUString( &cDateSep, 1)); // always the defined separator
1125 if (cChar == cDateSep2 && !aPatternBuf2.isEmpty())
1126 aPatternBuf2.append( OUString( &cDateSep2, 1)); // always the format's separator
1127 break;
1128 // The localized legacy:
1129 case 'A':
1130 if (((nDetected & 7) == 3) || ((nDetected & 7) == 0))
1132 // es DD/MM/AAAA
1133 // fr JJ.MM.AAAA
1134 // it GG/MM/AAAA
1135 // fr_CA AAAA-MM-JJ
1136 aPatternBuf.append( 'Y');
1137 if (!aPatternBuf2.isEmpty())
1138 aPatternBuf2.append( 'Y');
1139 nDetected |= 4;
1141 break;
1142 case 'J':
1143 if (((nDetected & 7) == 0) || ((nDetected & 7) == 6))
1145 // fr JJ.MM.AAAA
1146 // fr_CA AAAA-MM-JJ
1147 aPatternBuf.append( 'D');
1148 if (!aPatternBuf2.isEmpty())
1149 aPatternBuf2.append( 'D');
1150 nDetected |= 1;
1152 else if ((nDetected & 7) == 3)
1154 // nl DD-MM-JJJJ
1155 // de TT.MM.JJJJ
1156 aPatternBuf.append( 'Y');
1157 if (!aPatternBuf2.isEmpty())
1158 aPatternBuf2.append( 'Y');
1159 nDetected |= 4;
1161 break;
1162 case 'T':
1163 if ((nDetected & 7) == 0)
1165 // de TT.MM.JJJJ
1166 aPatternBuf.append( 'D');
1167 if (!aPatternBuf2.isEmpty())
1168 aPatternBuf2.append( 'D');
1169 nDetected |= 1;
1171 break;
1172 case 'G':
1173 if ((nDetected & 7) == 0)
1175 // it GG/MM/AAAA
1176 aPatternBuf.append( 'D');
1177 if (!aPatternBuf2.isEmpty())
1178 aPatternBuf2.append( 'D');
1179 nDetected |= 1;
1181 break;
1182 case 'P':
1183 if ((nDetected & 7) == 0)
1185 // fi PP.KK.VVVV
1186 aPatternBuf.append( 'D');
1187 if (!aPatternBuf2.isEmpty())
1188 aPatternBuf2.append( 'D');
1189 nDetected |= 1;
1191 break;
1192 case 'K':
1193 if ((nDetected & 7) == 1)
1195 // fi PP.KK.VVVV
1196 aPatternBuf.append( 'M');
1197 if (!aPatternBuf2.isEmpty())
1198 aPatternBuf2.append( 'M');
1199 nDetected |= 2;
1201 break;
1202 case 'V':
1203 if ((nDetected & 7) == 3)
1205 // fi PP.KK.VVVV
1206 aPatternBuf.append( 'Y');
1207 if (!aPatternBuf2.isEmpty())
1208 aPatternBuf2.append( 'Y');
1209 nDetected |= 4;
1211 break;
1214 OUString aPattern( aPatternBuf.makeStringAndClear());
1215 if (((nDetected & 7) != 7) || aPattern.getLength() < 5)
1217 incErrorStr( "Error: failed to extract full date acceptance pattern: %s\n", aPattern);
1218 fprintf( stderr, " with DateSeparator '%s' from FormatCode '%s' (formatindex=\"%d\")\n",
1219 OSTR( OUString( cDateSep)), OSTR( sTheDateEditFormat),
1220 (int)cssi::NumberFormatIndex::DATE_SYS_DDMMYYYY);
1222 else
1224 fprintf( stderr, "Generated date acceptance pattern: '%s' from '%s' (formatindex=\"%d\" and defined DateSeparator '%s')\n",
1225 OSTR( aPattern), OSTR( sTheDateEditFormat),
1226 (int)cssi::NumberFormatIndex::DATE_SYS_DDMMYYYY,
1227 OSTR( OUString( cDateSep)));
1228 // Insert at front so full date pattern is first in checks.
1229 theDateAcceptancePatterns.insert( theDateAcceptancePatterns.begin(), aPattern);
1231 if (!aPatternBuf2.isEmpty())
1233 OUString aPattern2( aPatternBuf2.makeStringAndClear());
1234 if (aPattern2.getLength() < 5)
1236 incErrorStr( "Error: failed to extract 2nd date acceptance pattern: %s\n", aPattern2);
1237 fprintf( stderr, " with DateSeparator '%s' from FormatCode '%s' (formatindex=\"%d\")\n",
1238 OSTR( OUString( cDateSep2)), OSTR( sTheDateEditFormat),
1239 (int)cssi::NumberFormatIndex::DATE_SYS_DDMMYYYY);
1241 else
1243 fprintf( stderr, "Generated 2nd acceptance pattern: '%s' from '%s' (formatindex=\"%d\")\n",
1244 OSTR( aPattern2), OSTR( sTheDateEditFormat),
1245 (int)cssi::NumberFormatIndex::DATE_SYS_DDMMYYYY);
1246 theDateAcceptancePatterns.insert( theDateAcceptancePatterns.begin(), aPattern2);
1250 // Rudimentary check if a pattern interferes with decimal number.
1251 // But only if not inherited in which case we don't have aDecSep here.
1252 if (!aDecSep.isEmpty())
1254 nIndex = 0;
1255 sal_uInt32 cDecSep = aDecSep.iterateCodePoints( &nIndex);
1256 for (vector<OUString>::const_iterator aIt = theDateAcceptancePatterns.begin();
1257 aIt != theDateAcceptancePatterns.end(); ++aIt)
1259 if ((*aIt).getLength() == (cDecSep <= 0xffff ? 3 : 4))
1261 nIndex = 1;
1262 if ((*aIt).iterateCodePoints( &nIndex) == cDecSep)
1264 ++nError;
1265 fprintf( stderr, "Error: Date acceptance pattern '%s' matches decimal number '#%s#'\n",
1266 OSTR( *aIt), OSTR( aDecSep));
1272 // Check for duplicates.
1273 for (vector<OUString>::const_iterator aIt = theDateAcceptancePatterns.begin();
1274 aIt != theDateAcceptancePatterns.end(); ++aIt)
1276 for (vector<OUString>::iterator aComp = theDateAcceptancePatterns.begin();
1277 aComp != theDateAcceptancePatterns.end(); /*nop*/)
1279 if (aIt != aComp && *aIt == *aComp)
1281 incErrorStr( "Error: Duplicated DateAcceptancePattern: %s\n", *aComp);
1282 aComp = theDateAcceptancePatterns.erase( aComp);
1284 else
1285 ++aComp;
1289 sal_Int16 nbOfDateAcceptancePatterns = static_cast<sal_Int16>(theDateAcceptancePatterns.size());
1291 for (sal_Int16 i = 0; i < nbOfDateAcceptancePatterns; ++i)
1293 of.writeParameter("DateAcceptancePattern", theDateAcceptancePatterns[i], i);
1296 of.writeAsciiString("static const sal_Int16 DateAcceptancePatternsCount = ");
1297 of.writeInt( nbOfDateAcceptancePatterns);
1298 of.writeAsciiString(";\n");
1300 of.writeAsciiString("static const sal_Unicode* DateAcceptancePatternsArray[] = {\n");
1301 for (sal_Int16 i = 0; i < nbOfDateAcceptancePatterns; ++i)
1303 of.writeAsciiString("\t");
1304 of.writeAsciiString("DateAcceptancePattern");
1305 of.writeInt(i);
1306 of.writeAsciiString(",\n");
1308 of.writeAsciiString("};\n\n");
1310 of.writeFunction("getDateAcceptancePatterns_", "DateAcceptancePatternsCount", "DateAcceptancePatternsArray");
1313 ++mnSection;
1316 void LCCollationNode::generateCode (const OFileWriter &of) const
1318 OUString useLocale = getAttr().getValueByName("ref");
1319 if (!useLocale.isEmpty()) {
1320 useLocale = useLocale.replace( '-', '_');
1321 of.writeRefFunction("getCollatorImplementation_", useLocale);
1322 of.writeRefFunction("getCollationOptions_", useLocale);
1323 return;
1325 sal_Int16 nbOfCollations = 0;
1326 sal_Int16 nbOfCollationOptions = 0;
1327 sal_Int16 j;
1329 for ( j = 0; j < getNumberOfChildren(); j++ ) {
1330 LocaleNode * currNode = getChildAt (j);
1331 if( currNode->getName() == "Collator" )
1333 OUString str;
1334 str = currNode->getAttr().getValueByName("unoid");
1335 of.writeParameter("CollatorID", str, j);
1336 str = currNode->getValue();
1337 of.writeParameter("CollatorRule", str, j);
1338 str = currNode -> getAttr().getValueByName("default");
1339 of.writeDefaultParameter("Collator", str, j);
1340 of.writeAsciiString("\n");
1342 nbOfCollations++;
1344 if( currNode->getName() == "CollationOptions" )
1346 LocaleNode* pCollationOptions = currNode;
1347 nbOfCollationOptions = sal::static_int_cast<sal_Int16>( pCollationOptions->getNumberOfChildren() );
1348 for( sal_Int16 i=0; i<nbOfCollationOptions; i++ )
1350 of.writeParameter("collationOption", pCollationOptions->getChildAt( i )->getValue(), i );
1353 of.writeAsciiString("static const sal_Int16 nbOfCollationOptions = ");
1354 of.writeInt( nbOfCollationOptions );
1355 of.writeAsciiString(";\n\n");
1358 of.writeAsciiString("static const sal_Int16 nbOfCollations = ");
1359 of.writeInt(nbOfCollations);
1360 of.writeAsciiString(";\n\n");
1362 of.writeAsciiString("\nstatic const sal_Unicode* LCCollatorArray[] = {\n");
1363 for(j = 0; j < nbOfCollations; j++) {
1364 of.writeAsciiString("\tCollatorID");
1365 of.writeInt(j);
1366 of.writeAsciiString(",\n");
1368 of.writeAsciiString("\tdefaultCollator");
1369 of.writeInt(j);
1370 of.writeAsciiString(",\n");
1372 of.writeAsciiString("\tCollatorRule");
1373 of.writeInt(j);
1374 of.writeAsciiString(",\n");
1376 of.writeAsciiString("};\n\n");
1378 of.writeAsciiString("static const sal_Unicode* collationOptions[] = {");
1379 for( j=0; j<nbOfCollationOptions; j++ )
1381 of.writeAsciiString( "collationOption" );
1382 of.writeInt( j );
1383 of.writeAsciiString( ", " );
1385 of.writeAsciiString("NULL };\n");
1386 of.writeFunction("getCollatorImplementation_", "nbOfCollations", "LCCollatorArray");
1387 of.writeFunction("getCollationOptions_", "nbOfCollationOptions", "collationOptions");
1390 void LCSearchNode::generateCode (const OFileWriter &of) const
1392 OUString useLocale = getAttr().getValueByName("ref");
1393 if (!useLocale.isEmpty()) {
1394 useLocale = useLocale.replace( '-', '_');
1395 of.writeRefFunction("getSearchOptions_", useLocale);
1396 return;
1399 if( getNumberOfChildren() != 1 )
1401 ++nError;
1402 fprintf(
1403 stderr, "Error: LC_SEARCH: more than 1 child: %ld\n",
1404 sal::static_int_cast< long >(getNumberOfChildren()));
1406 sal_Int32 i;
1407 LocaleNode* pSearchOptions = getChildAt( 0 );
1408 sal_Int32 nSearchOptions = pSearchOptions->getNumberOfChildren();
1409 for( i=0; i<nSearchOptions; i++ )
1411 of.writeParameter("searchOption", pSearchOptions->getChildAt( i )->getValue(), sal::static_int_cast<sal_Int16>(i) );
1414 of.writeAsciiString("static const sal_Int16 nbOfSearchOptions = ");
1415 of.writeInt( sal::static_int_cast<sal_Int16>( nSearchOptions ) );
1416 of.writeAsciiString(";\n\n");
1418 of.writeAsciiString("static const sal_Unicode* searchOptions[] = {");
1419 for( i=0; i<nSearchOptions; i++ )
1421 of.writeAsciiString( "searchOption" );
1422 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
1423 of.writeAsciiString( ", " );
1425 of.writeAsciiString("NULL };\n");
1426 of.writeFunction("getSearchOptions_", "nbOfSearchOptions", "searchOptions");
1429 void LCIndexNode::generateCode (const OFileWriter &of) const
1431 OUString useLocale = getAttr().getValueByName("ref");
1432 if (!useLocale.isEmpty()) {
1433 useLocale = useLocale.replace( '-', '_');
1434 of.writeRefFunction("getIndexAlgorithm_", useLocale);
1435 of.writeRefFunction("getUnicodeScripts_", useLocale);
1436 of.writeRefFunction("getFollowPageWords_", useLocale);
1437 return;
1439 sal_Int16 nbOfIndexs = 0;
1440 sal_Int16 nbOfUnicodeScripts = 0;
1441 sal_Int16 nbOfPageWords = 0;
1442 sal_Int16 i;
1443 for (i = 0; i< getNumberOfChildren();i++) {
1444 LocaleNode * currNode = getChildAt (i);
1445 if( currNode->getName() == "IndexKey" )
1447 OUString str;
1448 str = currNode->getAttr().getValueByName("unoid");
1449 of.writeParameter("IndexID", str, nbOfIndexs);
1450 str = currNode->getAttr().getValueByName("module");
1451 of.writeParameter("IndexModule", str, nbOfIndexs);
1452 str = currNode->getValue();
1453 of.writeParameter("IndexKey", str, nbOfIndexs);
1454 str = currNode -> getAttr().getValueByName("default");
1455 of.writeDefaultParameter("Index", str, nbOfIndexs);
1456 str = currNode -> getAttr().getValueByName("phonetic");
1457 of.writeDefaultParameter("Phonetic", str, nbOfIndexs);
1458 of.writeAsciiString("\n");
1460 nbOfIndexs++;
1462 if( currNode->getName() == "UnicodeScript" )
1464 of.writeParameter("unicodeScript", currNode->getValue(), nbOfUnicodeScripts );
1465 nbOfUnicodeScripts++;
1468 if( currNode->getName() == "FollowPageWord" )
1470 of.writeParameter("followPageWord", currNode->getValue(), nbOfPageWords);
1471 nbOfPageWords++;
1474 of.writeAsciiString("static const sal_Int16 nbOfIndexs = ");
1475 of.writeInt(nbOfIndexs);
1476 of.writeAsciiString(";\n\n");
1478 of.writeAsciiString("\nstatic const sal_Unicode* IndexArray[] = {\n");
1479 for(i = 0; i < nbOfIndexs; i++) {
1480 of.writeAsciiString("\tIndexID");
1481 of.writeInt(i);
1482 of.writeAsciiString(",\n");
1484 of.writeAsciiString("\tIndexModule");
1485 of.writeInt(i);
1486 of.writeAsciiString(",\n");
1488 of.writeAsciiString("\tIndexKey");
1489 of.writeInt(i);
1490 of.writeAsciiString(",\n");
1492 of.writeAsciiString("\tdefaultIndex");
1493 of.writeInt(i);
1494 of.writeAsciiString(",\n");
1496 of.writeAsciiString("\tdefaultPhonetic");
1497 of.writeInt(i);
1498 of.writeAsciiString(",\n");
1500 of.writeAsciiString("};\n\n");
1502 of.writeAsciiString("static const sal_Int16 nbOfUnicodeScripts = ");
1503 of.writeInt( nbOfUnicodeScripts );
1504 of.writeAsciiString(";\n\n");
1506 of.writeAsciiString("static const sal_Unicode* UnicodeScriptArray[] = {");
1507 for( i=0; i<nbOfUnicodeScripts; i++ )
1509 of.writeAsciiString( "unicodeScript" );
1510 of.writeInt( i );
1511 of.writeAsciiString( ", " );
1513 of.writeAsciiString("NULL };\n\n");
1515 of.writeAsciiString("static const sal_Int16 nbOfPageWords = ");
1516 of.writeInt(nbOfPageWords);
1517 of.writeAsciiString(";\n\n");
1519 of.writeAsciiString("static const sal_Unicode* FollowPageWordArray[] = {\n");
1520 for(i = 0; i < nbOfPageWords; i++) {
1521 of.writeAsciiString("\tfollowPageWord");
1522 of.writeInt(i);
1523 of.writeAsciiString(",\n");
1525 of.writeAsciiString("\tNULL\n};\n\n");
1527 of.writeFunction("getIndexAlgorithm_", "nbOfIndexs", "IndexArray");
1528 of.writeFunction("getUnicodeScripts_", "nbOfUnicodeScripts", "UnicodeScriptArray");
1529 of.writeFunction("getFollowPageWords_", "nbOfPageWords", "FollowPageWordArray");
1533 static void lcl_writeAbbrFullNarrNames( const OFileWriter & of, const LocaleNode* currNode,
1534 const sal_Char* elementTag, sal_Int16 i, sal_Int16 j )
1536 OUString aAbbrName = currNode->getChildAt(1)->getValue();
1537 OUString aFullName = currNode->getChildAt(2)->getValue();
1538 OUString aNarrName;
1539 LocaleNode* p = (currNode->getNumberOfChildren() > 3 ? currNode->getChildAt(3) : 0);
1540 if ( p && p->getName() == "DefaultNarrowName" )
1541 aNarrName = p->getValue();
1542 else
1544 sal_Int32 nIndex = 0;
1545 sal_uInt32 nChar = aFullName.iterateCodePoints( &nIndex);
1546 aNarrName = OUString( &nChar, 1);
1548 of.writeParameter( elementTag, "DefaultAbbrvName", aAbbrName, i, j);
1549 of.writeParameter( elementTag, "DefaultFullName", aFullName, i, j);
1550 of.writeParameter( elementTag, "DefaultNarrowName", aNarrName, i, j);
1553 static void lcl_writeTabTagString( const OFileWriter & of, const sal_Char* pTag, const sal_Char* pStr )
1555 of.writeAsciiString("\t");
1556 of.writeAsciiString( pTag);
1557 of.writeAsciiString( pStr);
1560 static void lcl_writeTabTagStringNums( const OFileWriter & of,
1561 const sal_Char* pTag, const sal_Char* pStr, sal_Int16 i, sal_Int16 j )
1563 lcl_writeTabTagString( of, pTag, pStr);
1564 of.writeInt(i); of.writeInt(j); of.writeAsciiString(",\n");
1567 static void lcl_writeAbbrFullNarrArrays( const OFileWriter & of, sal_Int16 nCount,
1568 const sal_Char* elementTag, sal_Int16 i, bool bNarrow )
1570 if (nCount == 0)
1572 lcl_writeTabTagString( of, elementTag, "Ref");
1573 of.writeInt(i); of.writeAsciiString(",\n");
1574 lcl_writeTabTagString( of, elementTag, "RefName");
1575 of.writeInt(i); of.writeAsciiString(",\n");
1577 else
1579 for (sal_Int16 j = 0; j < nCount; j++)
1581 lcl_writeTabTagStringNums( of, elementTag, "ID", i, j);
1582 lcl_writeTabTagStringNums( of, elementTag, "DefaultAbbrvName", i, j);
1583 lcl_writeTabTagStringNums( of, elementTag, "DefaultFullName", i, j);
1584 if (bNarrow)
1585 lcl_writeTabTagStringNums( of, elementTag, "DefaultNarrowName", i, j);
1590 void LCCalendarNode::generateCode (const OFileWriter &of) const
1592 OUString useLocale = getAttr().getValueByName("ref");
1593 if (!useLocale.isEmpty()) {
1594 useLocale = useLocale.replace( '-', '_');
1595 of.writeRefFunction("getAllCalendars_", useLocale);
1596 return;
1598 sal_Int16 nbOfCalendars = sal::static_int_cast<sal_Int16>( getNumberOfChildren() );
1599 OUString str;
1600 sal_Int16 * nbOfDays = new sal_Int16[nbOfCalendars];
1601 sal_Int16 * nbOfMonths = new sal_Int16[nbOfCalendars];
1602 sal_Int16 * nbOfGenitiveMonths = new sal_Int16[nbOfCalendars];
1603 sal_Int16 * nbOfPartitiveMonths = new sal_Int16[nbOfCalendars];
1604 sal_Int16 * nbOfEras = new sal_Int16[nbOfCalendars];
1605 sal_Int16 j;
1606 sal_Int16 i;
1607 bool bHasGregorian = false;
1610 for ( i = 0; i < nbOfCalendars; i++) {
1611 LocaleNode * calNode = getChildAt (i);
1612 OUString calendarID = calNode -> getAttr().getValueByName("unoid");
1613 of.writeParameter( "calendarID", calendarID, i);
1614 bool bGregorian = calendarID == "gregorian";
1615 if (!bHasGregorian)
1616 bHasGregorian = bGregorian;
1617 str = calNode -> getAttr().getValueByName("default");
1618 of.writeDefaultParameter("Calendar", str, i);
1620 sal_Int16 nChild = 0;
1622 // Generate Days of Week
1623 const sal_Char *elementTag;
1624 LocaleNode * daysNode = NULL;
1625 OUString ref_name = calNode->getChildAt(nChild)->getAttr().getValueByName("ref");
1626 ref_name = ref_name.replace( '-', '_');
1627 if (!ref_name.isEmpty() && i > 0) {
1628 for (j = 0; j < i; j++) {
1629 str = getChildAt(j)->getAttr().getValueByName("unoid");
1630 if (str.equals(ref_name))
1631 daysNode = getChildAt(j)->getChildAt(0);
1634 if (!ref_name.isEmpty() && daysNode == NULL) {
1635 of.writeParameter("dayRef", OUString("ref"), i);
1636 of.writeParameter("dayRefName", ref_name, i);
1637 nbOfDays[i] = 0;
1638 } else {
1639 if (daysNode == NULL)
1640 daysNode = calNode -> getChildAt(nChild);
1641 nbOfDays[i] = sal::static_int_cast<sal_Int16>( daysNode->getNumberOfChildren() );
1642 if (bGregorian && nbOfDays[i] != 7)
1643 incErrorInt( "Error: A Gregorian calendar must have 7 days per week, this one has %d\n", nbOfDays[i]);
1644 elementTag = "day";
1645 for (j = 0; j < nbOfDays[i]; j++) {
1646 LocaleNode *currNode = daysNode -> getChildAt(j);
1647 OUString dayID( currNode->getChildAt(0)->getValue());
1648 of.writeParameter("dayID", dayID, i, j);
1649 if ( j == 0 && bGregorian && dayID != "sun" )
1650 incError( "First day of a week of a Gregorian calendar must be <DayID>sun</DayID>");
1651 lcl_writeAbbrFullNarrNames( of, currNode, elementTag, i, j);
1654 ++nChild;
1656 // Generate Months of Year
1657 LocaleNode * monthsNode = NULL;
1658 ref_name = calNode->getChildAt(nChild)->getAttr().getValueByName("ref");
1659 ref_name = ref_name.replace( '-', '_');
1660 if (!ref_name.isEmpty() && i > 0) {
1661 for (j = 0; j < i; j++) {
1662 str = getChildAt(j)->getAttr().getValueByName("unoid");
1663 if (str.equals(ref_name))
1664 monthsNode = getChildAt(j)->getChildAt(1);
1667 if (!ref_name.isEmpty() && monthsNode == NULL) {
1668 of.writeParameter("monthRef", OUString("ref"), i);
1669 of.writeParameter("monthRefName", ref_name, i);
1670 nbOfMonths[i] = 0;
1671 } else {
1672 if (monthsNode == NULL)
1673 monthsNode = calNode -> getChildAt(nChild);
1674 nbOfMonths[i] = sal::static_int_cast<sal_Int16>( monthsNode->getNumberOfChildren() );
1675 if (bGregorian && nbOfMonths[i] != 12)
1676 incErrorInt( "Error: A Gregorian calendar must have 12 months, this one has %d\n", nbOfMonths[i]);
1677 elementTag = "month";
1678 for (j = 0; j < nbOfMonths[i]; j++) {
1679 LocaleNode *currNode = monthsNode -> getChildAt(j);
1680 OUString monthID( currNode->getChildAt(0)->getValue());
1681 of.writeParameter("monthID", monthID, i, j);
1682 if ( j == 0 && bGregorian && monthID != "jan" )
1683 incError( "First month of a year of a Gregorian calendar must be <MonthID>jan</MonthID>");
1684 lcl_writeAbbrFullNarrNames( of, currNode, elementTag, i, j);
1687 ++nChild;
1689 // Generate genitive Months of Year
1690 // Optional, if not present fall back to month nouns.
1691 if ( calNode->getChildAt(nChild)->getName() != "GenitiveMonths" )
1692 --nChild;
1693 LocaleNode * genitiveMonthsNode = NULL;
1694 ref_name = calNode->getChildAt(nChild)->getAttr().getValueByName("ref");
1695 ref_name = ref_name.replace( '-', '_');
1696 if (!ref_name.isEmpty() && i > 0) {
1697 for (j = 0; j < i; j++) {
1698 str = getChildAt(j)->getAttr().getValueByName("unoid");
1699 if (str.equals(ref_name))
1700 genitiveMonthsNode = getChildAt(j)->getChildAt(1);
1703 if (!ref_name.isEmpty() && genitiveMonthsNode == NULL) {
1704 of.writeParameter("genitiveMonthRef", OUString("ref"), i);
1705 of.writeParameter("genitiveMonthRefName", ref_name, i);
1706 nbOfGenitiveMonths[i] = 0;
1707 } else {
1708 if (genitiveMonthsNode == NULL)
1709 genitiveMonthsNode = calNode -> getChildAt(nChild);
1710 nbOfGenitiveMonths[i] = sal::static_int_cast<sal_Int16>( genitiveMonthsNode->getNumberOfChildren() );
1711 if (bGregorian && nbOfGenitiveMonths[i] != 12)
1712 incErrorInt( "Error: A Gregorian calendar must have 12 genitive months, this one has %d\n", nbOfGenitiveMonths[i]);
1713 elementTag = "genitiveMonth";
1714 for (j = 0; j < nbOfGenitiveMonths[i]; j++) {
1715 LocaleNode *currNode = genitiveMonthsNode -> getChildAt(j);
1716 OUString genitiveMonthID( currNode->getChildAt(0)->getValue());
1717 of.writeParameter("genitiveMonthID", genitiveMonthID, i, j);
1718 if ( j == 0 && bGregorian && genitiveMonthID != "jan" )
1719 incError( "First genitive month of a year of a Gregorian calendar must be <MonthID>jan</MonthID>");
1720 lcl_writeAbbrFullNarrNames( of, currNode, elementTag, i, j);
1723 ++nChild;
1725 // Generate partitive Months of Year
1726 // Optional, if not present fall back to genitive months, or nominative
1727 // months (nouns) if that isn't present either.
1728 if ( calNode->getChildAt(nChild)->getName() != "PartitiveMonths" )
1729 --nChild;
1730 LocaleNode * partitiveMonthsNode = NULL;
1731 ref_name = calNode->getChildAt(nChild)->getAttr().getValueByName("ref");
1732 ref_name = ref_name.replace( '-', '_');
1733 if (!ref_name.isEmpty() && i > 0) {
1734 for (j = 0; j < i; j++) {
1735 str = getChildAt(j)->getAttr().getValueByName("unoid");
1736 if (str.equals(ref_name))
1737 partitiveMonthsNode = getChildAt(j)->getChildAt(1);
1740 if (!ref_name.isEmpty() && partitiveMonthsNode == NULL) {
1741 of.writeParameter("partitiveMonthRef", OUString("ref"), i);
1742 of.writeParameter("partitiveMonthRefName", ref_name, i);
1743 nbOfPartitiveMonths[i] = 0;
1744 } else {
1745 if (partitiveMonthsNode == NULL)
1746 partitiveMonthsNode = calNode -> getChildAt(nChild);
1747 nbOfPartitiveMonths[i] = sal::static_int_cast<sal_Int16>( partitiveMonthsNode->getNumberOfChildren() );
1748 if (bGregorian && nbOfPartitiveMonths[i] != 12)
1749 incErrorInt( "Error: A Gregorian calendar must have 12 partitive months, this one has %d\n", nbOfPartitiveMonths[i]);
1750 elementTag = "partitiveMonth";
1751 for (j = 0; j < nbOfPartitiveMonths[i]; j++) {
1752 LocaleNode *currNode = partitiveMonthsNode -> getChildAt(j);
1753 OUString partitiveMonthID( currNode->getChildAt(0)->getValue());
1754 of.writeParameter("partitiveMonthID", partitiveMonthID, i, j);
1755 if ( j == 0 && bGregorian && partitiveMonthID != "jan" )
1756 incError( "First partitive month of a year of a Gregorian calendar must be <MonthID>jan</MonthID>");
1757 lcl_writeAbbrFullNarrNames( of, currNode, elementTag, i, j);
1760 ++nChild;
1762 // Generate Era name
1763 LocaleNode * erasNode = NULL;
1764 ref_name = calNode -> getChildAt(nChild) ->getAttr().getValueByName("ref");
1765 ref_name = ref_name.replace( '-', '_');
1766 if (!ref_name.isEmpty() && i > 0) {
1767 for (j = 0; j < i; j++) {
1768 str = getChildAt(j)->getAttr().getValueByName("unoid");
1769 if (str.equals(ref_name))
1770 erasNode = getChildAt(j)->getChildAt(2);
1773 if (!ref_name.isEmpty() && erasNode == NULL) {
1774 of.writeParameter("eraRef", OUString("ref"), i);
1775 of.writeParameter("eraRefName", ref_name, i);
1776 nbOfEras[i] = 0;
1777 } else {
1778 if (erasNode == NULL)
1779 erasNode = calNode -> getChildAt(nChild);
1780 nbOfEras[i] = sal::static_int_cast<sal_Int16>( erasNode->getNumberOfChildren() );
1781 if (bGregorian && nbOfEras[i] != 2)
1782 incErrorInt( "Error: A Gregorian calendar must have 2 eras, this one has %d\n", nbOfEras[i]);
1783 elementTag = "era";
1784 for (j = 0; j < nbOfEras[i]; j++) {
1785 LocaleNode *currNode = erasNode -> getChildAt(j);
1786 OUString eraID( currNode->getChildAt(0)->getValue());
1787 of.writeParameter("eraID", eraID, i, j);
1788 if ( j == 0 && bGregorian && eraID != "bc" )
1789 incError( "First era of a Gregorian calendar must be <EraID>bc</EraID>");
1790 if ( j == 1 && bGregorian && eraID != "ad" )
1791 incError( "Second era of a Gregorian calendar must be <EraID>ad</EraID>");
1792 of.writeAsciiString("\n");
1793 of.writeParameter(elementTag, "DefaultAbbrvName",currNode->getChildAt(1)->getValue() ,i, j);
1794 of.writeParameter(elementTag, "DefaultFullName",currNode->getChildAt(2)->getValue() , i, j);
1797 ++nChild;
1799 str = calNode->getChildAt(nChild)->getChildAt(0)->getValue();
1800 if (nbOfDays[i])
1802 for (j = 0; j < nbOfDays[i]; j++)
1804 LocaleNode *currNode = daysNode->getChildAt(j);
1805 OUString dayID( currNode->getChildAt(0)->getValue());
1806 if (str == dayID)
1807 break; // for
1809 if (j >= nbOfDays[i])
1810 incErrorStr( "Error: <StartDayOfWeek> <DayID> must be one of the <DaysOfWeek>, but is: %s\n", str);
1812 of.writeParameter("startDayOfWeek", str, i);
1813 ++nChild;
1815 str = calNode ->getChildAt(nChild)-> getValue();
1816 sal_Int16 nDays = sal::static_int_cast<sal_Int16>( str.toInt32() );
1817 if (nDays < 1 || (0 < nbOfDays[i] && nbOfDays[i] < nDays))
1818 incErrorInt( "Error: Bad value of MinimalDaysInFirstWeek: %d, must be 1 <= value <= days_in_week\n", nDays);
1819 of.writeIntParameter("minimalDaysInFirstWeek", i, nDays);
1821 if (!bHasGregorian)
1822 fprintf( stderr, "Warning: %s\n", "No Gregorian calendar defined, are you sure?");
1824 of.writeAsciiString("static const sal_Int16 calendarsCount = ");
1825 of.writeInt(nbOfCalendars);
1826 of.writeAsciiString(";\n\n");
1828 of.writeAsciiString("static const sal_Unicode nbOfDays[] = {");
1829 for(i = 0; i < nbOfCalendars - 1; i++) {
1830 of.writeInt(nbOfDays[i]);
1831 of.writeAsciiString(", ");
1833 of.writeInt(nbOfDays[i]);
1834 of.writeAsciiString("};\n");
1836 of.writeAsciiString("static const sal_Unicode nbOfMonths[] = {");
1837 for(i = 0; i < nbOfCalendars - 1; i++) {
1838 of.writeInt(nbOfMonths[i]);
1839 of.writeAsciiString(", ");
1841 of.writeInt(nbOfMonths[i]);
1842 of.writeAsciiString("};\n");
1844 of.writeAsciiString("static const sal_Unicode nbOfGenitiveMonths[] = {");
1845 for(i = 0; i < nbOfCalendars - 1; i++) {
1846 of.writeInt(nbOfGenitiveMonths[i]);
1847 of.writeAsciiString(", ");
1849 of.writeInt(nbOfGenitiveMonths[i]);
1850 of.writeAsciiString("};\n");
1852 of.writeAsciiString("static const sal_Unicode nbOfPartitiveMonths[] = {");
1853 for(i = 0; i < nbOfCalendars - 1; i++) {
1854 of.writeInt(nbOfPartitiveMonths[i]);
1855 of.writeAsciiString(", ");
1857 of.writeInt(nbOfPartitiveMonths[i]);
1858 of.writeAsciiString("};\n");
1860 of.writeAsciiString("static const sal_Unicode nbOfEras[] = {");
1861 for(i = 0; i < nbOfCalendars - 1; i++) {
1862 of.writeInt(nbOfEras[i]);
1863 of.writeAsciiString(", ");
1865 of.writeInt(nbOfEras[i]);
1866 of.writeAsciiString("};\n");
1869 of.writeAsciiString("static const sal_Unicode* calendars[] = {\n");
1870 of.writeAsciiString("\tnbOfDays,\n");
1871 of.writeAsciiString("\tnbOfMonths,\n");
1872 of.writeAsciiString("\tnbOfGenitiveMonths,\n");
1873 of.writeAsciiString("\tnbOfPartitiveMonths,\n");
1874 of.writeAsciiString("\tnbOfEras,\n");
1875 for(i = 0; i < nbOfCalendars; i++) {
1876 of.writeAsciiString("\tcalendarID");
1877 of.writeInt(i);
1878 of.writeAsciiString(",\n");
1879 of.writeAsciiString("\tdefaultCalendar");
1880 of.writeInt(i);
1881 of.writeAsciiString(",\n");
1882 lcl_writeAbbrFullNarrArrays( of, nbOfDays[i], "day", i, true);
1883 lcl_writeAbbrFullNarrArrays( of, nbOfMonths[i], "month", i, true);
1884 lcl_writeAbbrFullNarrArrays( of, nbOfGenitiveMonths[i], "genitiveMonth", i, true);
1885 lcl_writeAbbrFullNarrArrays( of, nbOfPartitiveMonths[i], "partitiveMonth", i, true);
1886 lcl_writeAbbrFullNarrArrays( of, nbOfEras[i], "era", i, false /*noNarrow*/);
1887 of.writeAsciiString("\tstartDayOfWeek");of.writeInt(i); of.writeAsciiString(",\n");
1888 of.writeAsciiString("\tminimalDaysInFirstWeek");of.writeInt(i); of.writeAsciiString(",\n");
1891 of.writeAsciiString("};\n\n");
1892 of.writeFunction("getAllCalendars_", "calendarsCount", "calendars");
1894 delete []nbOfDays;
1895 delete []nbOfMonths;
1896 delete []nbOfGenitiveMonths;
1897 delete []nbOfPartitiveMonths;
1898 delete []nbOfEras;
1901 bool isIso4217( const OUString& rStr )
1903 const sal_Unicode* p = rStr.getStr();
1904 return rStr.getLength() == 3
1905 && 'A' <= p[0] && p[0] <= 'Z'
1906 && 'A' <= p[1] && p[1] <= 'Z'
1907 && 'A' <= p[2] && p[2] <= 'Z'
1911 void LCCurrencyNode :: generateCode (const OFileWriter &of) const
1913 OUString useLocale = getAttr().getValueByName("ref");
1914 if (!useLocale.isEmpty()) {
1915 useLocale = useLocale.replace( '-', '_');
1916 of.writeRefFunction("getAllCurrencies_", useLocale);
1917 return;
1919 sal_Int16 nbOfCurrencies = 0;
1920 OUString str;
1921 sal_Int16 i;
1923 bool bTheDefault= false;
1924 bool bTheCompatible = false;
1925 for ( i = 0; i < getNumberOfChildren(); i++,nbOfCurrencies++) {
1926 LocaleNode * currencyNode = getChildAt (i);
1927 str = currencyNode->getAttr().getValueByName("default");
1928 bool bDefault = of.writeDefaultParameter("Currency", str, nbOfCurrencies);
1929 str = currencyNode->getAttr().getValueByName("usedInCompatibleFormatCodes");
1930 bool bCompatible = of.writeDefaultParameter("CurrencyUsedInCompatibleFormatCodes", str, nbOfCurrencies);
1931 str = currencyNode->getAttr().getValueByName("legacyOnly");
1932 bool bLegacy = of.writeDefaultParameter("CurrencyLegacyOnly", str, nbOfCurrencies);
1933 if (bLegacy && (bDefault || bCompatible))
1934 incError( "Currency: if legacyOnly==true, both 'default' and 'usedInCompatibleFormatCodes' must be false.");
1935 if (bDefault)
1937 if (bTheDefault)
1938 incError( "Currency: more than one default currency.");
1939 bTheDefault = true;
1941 if (bCompatible)
1943 if (bTheCompatible)
1944 incError( "Currency: more than one currency flagged as usedInCompatibleFormatCodes.");
1945 bTheCompatible = true;
1947 str = currencyNode -> findNode ("CurrencyID") -> getValue();
1948 of.writeParameter("currencyID", str, nbOfCurrencies);
1949 // CurrencyID MUST be ISO 4217.
1950 if (!bLegacy && !isIso4217(str))
1951 incError( "CurrencyID is not ISO 4217");
1952 str = currencyNode -> findNode ("CurrencySymbol") -> getValue();
1953 of.writeParameter("currencySymbol", str, nbOfCurrencies);
1954 // Check if this currency really is the one used in number format
1955 // codes. In case of ref=... mechanisms it may be that TheCurrency
1956 // couldn't had been determined from the current locale (i.e. is
1957 // empty), silently assume the referred locale has things right.
1958 if (bCompatible && !sTheCompatibleCurrency.isEmpty() && sTheCompatibleCurrency != str)
1959 incErrorStrStr( "Error: CurrencySymbol \"%s\" flagged as usedInCompatibleFormatCodes doesn't match \"%s\" determined from format codes.\n", str, sTheCompatibleCurrency);
1960 str = currencyNode -> findNode ("BankSymbol") -> getValue();
1961 of.writeParameter("bankSymbol", str, nbOfCurrencies);
1962 // BankSymbol currently must be ISO 4217. May change later if
1963 // application always uses CurrencyID instead of BankSymbol.
1964 if (!bLegacy && !isIso4217(str))
1965 incError( "BankSymbol is not ISO 4217");
1966 str = currencyNode -> findNode ("CurrencyName") -> getValue();
1967 of.writeParameter("currencyName", str, nbOfCurrencies);
1968 str = currencyNode -> findNode ("DecimalPlaces") -> getValue();
1969 sal_Int16 nDecimalPlaces = (sal_Int16)str.toInt32();
1970 of.writeIntParameter("currencyDecimalPlaces", nbOfCurrencies, nDecimalPlaces);
1971 of.writeAsciiString("\n");
1974 if (!bTheDefault)
1975 incError( "Currency: no default currency.");
1976 if (!bTheCompatible)
1977 incError( "Currency: no currency flagged as usedInCompatibleFormatCodes.");
1979 of.writeAsciiString("static const sal_Int16 currencyCount = ");
1980 of.writeInt(nbOfCurrencies);
1981 of.writeAsciiString(";\n\n");
1982 of.writeAsciiString("static const sal_Unicode* currencies[] = {\n");
1983 for(i = 0; i < nbOfCurrencies; i++) {
1984 of.writeAsciiString("\tcurrencyID");
1985 of.writeInt(i);
1986 of.writeAsciiString(",\n");
1987 of.writeAsciiString("\tcurrencySymbol");
1988 of.writeInt(i);
1989 of.writeAsciiString(",\n");
1990 of.writeAsciiString("\tbankSymbol");
1991 of.writeInt(i);
1992 of.writeAsciiString(",\n");
1993 of.writeAsciiString("\tcurrencyName");
1994 of.writeInt(i);
1995 of.writeAsciiString(",\n");
1996 of.writeAsciiString("\tdefaultCurrency");
1997 of.writeInt(i);
1998 of.writeAsciiString(",\n");
1999 of.writeAsciiString("\tdefaultCurrencyUsedInCompatibleFormatCodes");
2000 of.writeInt(i);
2001 of.writeAsciiString(",\n");
2002 of.writeAsciiString("\tcurrencyDecimalPlaces");
2003 of.writeInt(i);
2004 of.writeAsciiString(",\n");
2005 of.writeAsciiString("\tdefaultCurrencyLegacyOnly");
2006 of.writeInt(i);
2007 of.writeAsciiString(",\n");
2009 of.writeAsciiString("};\n\n");
2010 of.writeFunction("getAllCurrencies_", "currencyCount", "currencies");
2013 void LCTransliterationNode::generateCode (const OFileWriter &of) const
2015 OUString useLocale = getAttr().getValueByName("ref");
2016 if (!useLocale.isEmpty()) {
2017 useLocale = useLocale.replace( '-', '_');
2018 of.writeRefFunction("getTransliterations_", useLocale);
2019 return;
2021 sal_Int16 nbOfModules = 0;
2022 OUString str;
2023 sal_Int16 i;
2025 for ( i = 0; i < getNumberOfChildren(); i++,nbOfModules++) {
2026 LocaleNode * transNode = getChildAt (i);
2027 str = transNode->getAttr().getValueByIndex(0);
2028 of.writeParameter("Transliteration", str, nbOfModules);
2030 of.writeAsciiString("static const sal_Int16 nbOfTransliterations = ");
2031 of.writeInt(nbOfModules);
2032 of.writeAsciiString(";\n\n");
2034 of.writeAsciiString("\nstatic const sal_Unicode* LCTransliterationsArray[] = {\n");
2035 for( i = 0; i < nbOfModules; i++) {
2036 of.writeAsciiString("\tTransliteration");
2037 of.writeInt(i);
2038 of.writeAsciiString(",\n");
2040 of.writeAsciiString("};\n\n");
2041 of.writeFunction("getTransliterations_", "nbOfTransliterations", "LCTransliterationsArray");
2044 struct NameValuePair {
2045 const sal_Char *name;
2046 const sal_Char *value;
2048 static const NameValuePair ReserveWord[] = {
2049 { "trueWord", "true" },
2050 { "falseWord", "false" },
2051 { "quarter1Word", "1st quarter" },
2052 { "quarter2Word", "2nd quarter" },
2053 { "quarter3Word", "3rd quarter" },
2054 { "quarter4Word", "4th quarter" },
2055 { "aboveWord", "above" },
2056 { "belowWord", "below" },
2057 { "quarter1Abbreviation", "Q1" },
2058 { "quarter2Abbreviation", "Q2" },
2059 { "quarter3Abbreviation", "Q3" },
2060 { "quarter4Abbreviation", "Q4" }
2063 void LCMiscNode::generateCode (const OFileWriter &of) const
2065 OUString useLocale = getAttr().getValueByName("ref");
2066 if (!useLocale.isEmpty()) {
2067 useLocale = useLocale.replace( '-', '_');
2068 of.writeRefFunction("getForbiddenCharacters_", useLocale);
2069 of.writeRefFunction("getBreakIteratorRules_", useLocale);
2070 of.writeRefFunction("getReservedWords_", useLocale);
2071 return;
2073 const LocaleNode * reserveNode = findNode("ReservedWords");
2074 if (!reserveNode)
2075 incError( "No ReservedWords element."); // should not happen if validated..
2076 const LocaleNode * forbidNode = findNode("ForbiddenCharacters");
2077 const LocaleNode * breakNode = findNode("BreakIteratorRules");
2079 bool bEnglishLocale = (strncmp( of.getLocale(), "en_", 3) == 0);
2081 sal_Int16 nbOfWords = 0;
2082 OUString str;
2083 sal_Int16 i;
2085 for ( i = 0; i < sal_Int16(SAL_N_ELEMENTS(ReserveWord)); i++,nbOfWords++) {
2086 const LocaleNode * curNode = (reserveNode ? reserveNode->findNode(
2087 ReserveWord[i].name) : 0);
2088 if (!curNode)
2089 fprintf( stderr,
2090 "Warning: No %s in ReservedWords, using en_US default: \"%s\".\n",
2091 ReserveWord[i].name, ReserveWord[i].value);
2092 str = curNode ? curNode -> getValue() : OUString::createFromAscii(ReserveWord[i].value);
2093 if (str.isEmpty())
2095 ++nError;
2096 fprintf( stderr, "Error: No content for ReservedWords %s.\n", ReserveWord[i].name);
2098 of.writeParameter("ReservedWord", str, nbOfWords);
2099 // "true", ..., "below" trigger untranslated warning.
2100 if (!bEnglishLocale && curNode && (0 <= i && i <= 7) &&
2101 str.equalsIgnoreAsciiCaseAscii( ReserveWord[i].value))
2103 fprintf( stderr,
2104 "Warning: ReservedWord %s seems to be untranslated \"%s\".\n",
2105 ReserveWord[i].name, ReserveWord[i].value);
2108 of.writeAsciiString("static const sal_Int16 nbOfReservedWords = ");
2109 of.writeInt(nbOfWords);
2110 of.writeAsciiString(";\n\n");
2111 of.writeAsciiString("\nstatic const sal_Unicode* LCReservedWordsArray[] = {\n");
2112 for( i = 0; i < nbOfWords; i++) {
2113 of.writeAsciiString("\tReservedWord");
2114 of.writeInt(i);
2115 of.writeAsciiString(",\n");
2117 of.writeAsciiString("};\n\n");
2118 of.writeFunction("getReservedWords_", "nbOfReservedWords", "LCReservedWordsArray");
2120 if (forbidNode) {
2121 of.writeParameter( "forbiddenBegin", forbidNode -> getChildAt(0)->getValue());
2122 of.writeParameter( "forbiddenEnd", forbidNode -> getChildAt(1)->getValue());
2123 of.writeParameter( "hangingChars", forbidNode -> getChildAt(2)->getValue());
2124 } else {
2125 of.writeParameter( "forbiddenBegin", OUString());
2126 of.writeParameter( "forbiddenEnd", OUString());
2127 of.writeParameter( "hangingChars", OUString());
2129 of.writeAsciiString("\nstatic const sal_Unicode* LCForbiddenCharactersArray[] = {\n");
2130 of.writeAsciiString("\tforbiddenBegin,\n");
2131 of.writeAsciiString("\tforbiddenEnd,\n");
2132 of.writeAsciiString("\thangingChars\n");
2133 of.writeAsciiString("};\n\n");
2134 of.writeFunction("getForbiddenCharacters_", "3", "LCForbiddenCharactersArray");
2136 if (breakNode) {
2137 of.writeParameter( "EditMode", breakNode -> getChildAt(0)->getValue());
2138 of.writeParameter( "DictionaryMode", breakNode -> getChildAt(1)->getValue());
2139 of.writeParameter( "WordCountMode", breakNode -> getChildAt(2)->getValue());
2140 of.writeParameter( "CharacterMode", breakNode -> getChildAt(3)->getValue());
2141 of.writeParameter( "LineMode", breakNode -> getChildAt(4)->getValue());
2142 } else {
2143 of.writeParameter( "EditMode", OUString());
2144 of.writeParameter( "DictionaryMode", OUString());
2145 of.writeParameter( "WordCountMode", OUString());
2146 of.writeParameter( "CharacterMode", OUString());
2147 of.writeParameter( "LineMode", OUString());
2149 of.writeAsciiString("\nstatic const sal_Unicode* LCBreakIteratorRulesArray[] = {\n");
2150 of.writeAsciiString("\tEditMode,\n");
2151 of.writeAsciiString("\tDictionaryMode,\n");
2152 of.writeAsciiString("\tWordCountMode,\n");
2153 of.writeAsciiString("\tCharacterMode,\n");
2154 of.writeAsciiString("\tLineMode\n");
2155 of.writeAsciiString("};\n\n");
2156 of.writeFunction("getBreakIteratorRules_", "5", "LCBreakIteratorRulesArray");
2160 void LCNumberingLevelNode::generateCode (const OFileWriter &of) const
2162 of.writeAsciiString("// ---> ContinuousNumbering\n");
2163 OUString useLocale = getAttr().getValueByName("ref");
2164 if (!useLocale.isEmpty()) {
2165 useLocale = useLocale.replace( '-', '_');
2166 of.writeRefFunction2("getContinuousNumberingLevels_", useLocale);
2167 return;
2170 // hard code number of attributes per style.
2171 const int nAttributes = 5;
2172 const char* attr[ nAttributes ] = { "Prefix", "NumType", "Suffix", "Transliteration", "NatNum" };
2174 // record each attribute of each style in a static C++ variable.
2175 // determine number of styles on the fly.
2176 sal_Int32 nStyles = getNumberOfChildren();
2177 sal_Int32 i;
2179 for( i = 0; i < nStyles; ++i )
2181 const Attr &q = getChildAt( i )->getAttr();
2182 for( sal_Int32 j=0; j<nAttributes; ++j )
2184 const char* name = attr[j];
2185 OUString value = q.getValueByName( name );
2186 of.writeParameter("continuous", name, value, sal::static_int_cast<sal_Int16>(i) );
2190 // record number of styles and attributes.
2191 of.writeAsciiString("static const sal_Int16 continuousNbOfStyles = ");
2192 of.writeInt( sal::static_int_cast<sal_Int16>( nStyles ) );
2193 of.writeAsciiString(";\n\n");
2194 of.writeAsciiString("static const sal_Int16 continuousNbOfAttributesPerStyle = ");
2195 of.writeInt( nAttributes );
2196 of.writeAsciiString(";\n\n");
2198 // generate code. (intermediate arrays)
2199 for( i=0; i<nStyles; i++ )
2201 of.writeAsciiString("\nstatic const sal_Unicode* continuousStyle" );
2202 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
2203 of.writeAsciiString("[] = {\n");
2204 for( sal_Int32 j=0; j<nAttributes; j++)
2206 of.writeAsciiString("\t");
2207 of.writeAsciiString( "continuous" );
2208 of.writeAsciiString( attr[j] );
2209 of.writeInt(sal::static_int_cast<sal_Int16>(i));
2210 of.writeAsciiString(",\n");
2212 of.writeAsciiString("\t0\n};\n\n");
2215 // generate code. (top-level array)
2216 of.writeAsciiString("\n");
2217 of.writeAsciiString("static const sal_Unicode** LCContinuousNumberingLevelsArray[] = {\n" );
2218 for( i=0; i<nStyles; i++ )
2220 of.writeAsciiString( "\t" );
2221 of.writeAsciiString( "continuousStyle" );
2222 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
2223 of.writeAsciiString( ",\n");
2225 of.writeAsciiString("\t0\n};\n\n");
2226 of.writeFunction2("getContinuousNumberingLevels_", "continuousNbOfStyles",
2227 "continuousNbOfAttributesPerStyle", "LCContinuousNumberingLevelsArray");
2231 void LCOutlineNumberingLevelNode::generateCode (const OFileWriter &of) const
2233 of.writeAsciiString("// ---> OutlineNumbering\n");
2234 OUString useLocale = getAttr().getValueByName("ref");
2235 if (!useLocale.isEmpty()) {
2236 useLocale = useLocale.replace( '-', '_');
2237 of.writeRefFunction3("getOutlineNumberingLevels_", useLocale);
2238 return;
2241 // hardcode number of attributes per level
2242 const int nAttributes = 11;
2243 const char* attr[ nAttributes ] =
2245 "Prefix",
2246 "NumType",
2247 "Suffix",
2248 "BulletChar",
2249 "BulletFontName",
2250 "ParentNumbering",
2251 "LeftMargin",
2252 "SymbolTextDistance",
2253 "FirstLineOffset",
2254 "Transliteration",
2255 "NatNum",
2258 // record each attribute of each level of each style in a static C++ variable.
2259 // determine number of styles and number of levels per style on the fly.
2260 sal_Int32 nStyles = getNumberOfChildren();
2261 vector<sal_Int32> nLevels; // may be different for each style?
2262 for( sal_Int32 i = 0; i < nStyles; i++ )
2264 LocaleNode* p = getChildAt( i );
2265 nLevels.push_back( p->getNumberOfChildren() );
2266 for( sal_Int32 j=0; j<nLevels.back(); j++ )
2268 const Attr& q = p->getChildAt( j )->getAttr();
2269 for( sal_Int32 k=0; k<nAttributes; ++k )
2271 const char* name = attr[k];
2272 OUString value = q.getValueByName( name );
2273 of.writeParameter("outline", name, value,
2274 sal::static_int_cast<sal_Int16>(i),
2275 sal::static_int_cast<sal_Int16>(j) );
2280 // verify that each style has the same number of levels.
2281 for( size_t i=0; i<nLevels.size(); i++ )
2283 if( nLevels[0] != nLevels[i] )
2285 incError( "Numbering levels don't match.");
2289 // record number of attributes, levels, and styles.
2290 of.writeAsciiString("static const sal_Int16 outlineNbOfStyles = ");
2291 of.writeInt( sal::static_int_cast<sal_Int16>( nStyles ) );
2292 of.writeAsciiString(";\n\n");
2293 of.writeAsciiString("static const sal_Int16 outlineNbOfLevelsPerStyle = ");
2294 of.writeInt( sal::static_int_cast<sal_Int16>( nLevels.back() ) );
2295 of.writeAsciiString(";\n\n");
2296 of.writeAsciiString("static const sal_Int16 outlineNbOfAttributesPerLevel = ");
2297 of.writeInt( nAttributes );
2298 of.writeAsciiString(";\n\n");
2300 // too complicated for now...
2301 // of.writeAsciiString("static const sal_Int16 nbOfOutlineNumberingLevels[] = { ");
2302 // for( sal_Int32 j=0; j<nStyles; j++ )
2303 // {
2304 // of.writeInt( nLevels[j] );
2305 // of.writeAsciiString(", ");
2306 // }
2307 // of.writeAsciiString("};\n\n");
2310 for( sal_Int32 i=0; i<nStyles; i++ )
2312 for( sal_Int32 j=0; j<nLevels.back(); j++ )
2314 of.writeAsciiString("static const sal_Unicode* outline");
2315 of.writeAsciiString("Style");
2316 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
2317 of.writeAsciiString("Level");
2318 of.writeInt( sal::static_int_cast<sal_Int16>(j) );
2319 of.writeAsciiString("[] = { ");
2321 for( sal_Int32 k=0; k<nAttributes; k++ )
2323 of.writeAsciiString( "outline" );
2324 of.writeAsciiString( attr[k] );
2325 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
2326 of.writeInt( sal::static_int_cast<sal_Int16>(j) );
2327 of.writeAsciiString(", ");
2329 of.writeAsciiString("NULL };\n");
2333 of.writeAsciiString("\n");
2336 for( sal_Int32 i=0; i<nStyles; i++ )
2338 of.writeAsciiString("static const sal_Unicode** outline");
2339 of.writeAsciiString( "Style" );
2340 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
2341 of.writeAsciiString("[] = { ");
2343 for( sal_Int32 j=0; j<nLevels.back(); j++ )
2345 of.writeAsciiString("outlineStyle");
2346 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
2347 of.writeAsciiString("Level");
2348 of.writeInt( sal::static_int_cast<sal_Int16>(j) );
2349 of.writeAsciiString(", ");
2351 of.writeAsciiString("NULL };\n");
2353 of.writeAsciiString("\n");
2355 of.writeAsciiString("static const sal_Unicode*** LCOutlineNumberingLevelsArray[] = {\n" );
2356 for( sal_Int32 i=0; i<nStyles; i++ )
2358 of.writeAsciiString( "\t" );
2359 of.writeAsciiString( "outlineStyle" );
2360 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
2361 of.writeAsciiString(",\n");
2363 of.writeAsciiString("\tNULL\n};\n\n");
2364 of.writeFunction3("getOutlineNumberingLevels_", "outlineNbOfStyles", "outlineNbOfLevelsPerStyle",
2365 "outlineNbOfAttributesPerLevel", "LCOutlineNumberingLevelsArray");
2368 Attr::Attr (const Reference< XAttributeList > & attr) {
2369 sal_Int16 len = attr->getLength();
2370 name.realloc (len);
2371 value.realloc (len);
2372 for (sal_Int16 i =0; i< len;i++) {
2373 name[i] = attr->getNameByIndex(i);
2374 value[i] = attr -> getValueByIndex(i);
2378 const OUString& Attr::getValueByName (const sal_Char *str) const {
2379 static OUString empty;
2380 sal_Int32 len = name.getLength();
2381 for (sal_Int32 i = 0;i<len;i++)
2382 if (name[i].equalsAscii(str))
2383 return value[i];
2384 return empty;
2387 sal_Int32 Attr::getLength() const{
2388 return name.getLength();
2391 const OUString& Attr::getTypeByIndex (sal_Int32 idx) const {
2392 return name[idx];
2395 const OUString& Attr::getValueByIndex (sal_Int32 idx) const
2397 return value[idx];
2400 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */