1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
27 #include <rtl/ustrbuf.hxx>
28 #include <sal/macros.h>
30 #include "LocaleNode.hxx"
31 #include <com/sun/star/i18n/NumberFormatIndex.hpp>
33 // NOTE: MUST match the Locale versionDTD attribute defined in data/locale.dtd
34 #define LOCALE_VERSION_DTD "2.0.3"
36 typedef ::std::set
< ::rtl::OUString
> NameSet
;
37 typedef ::std::set
< sal_Int16
> ValueSet
;
39 namespace cssi
= ::com::sun::star::i18n
;
41 LocaleNode::LocaleNode (const OUString
& name
, const Reference
< XAttributeList
> & attr
)
52 int LocaleNode::getError() const
55 for (sal_Int32 i
=0;i
<nChildren
;i
++)
56 err
+= children
[i
]->getError();
60 void LocaleNode::print () const {
62 ::rtl::OUString
str (aName
);
63 for(sal_Int32 i
= 0; i
< str
.getLength(); i
++)
64 printf( "%c", str
[i
]);
68 void LocaleNode::printR () const {
70 for (sal_Int32 i
=0;i
<nChildren
;i
++)
71 children
[i
]->printR();
76 void LocaleNode::addChild ( LocaleNode
* node
) {
77 if (childArrSize
<= nChildren
) {
78 LocaleNode
** arrN
= new LocaleNode
*[childArrSize
+10];
79 for (sal_Int32 i
= 0; i
<childArrSize
; ++i
)
80 arrN
[i
] = children
[i
];
85 children
[nChildren
++] = node
;
86 node
->setParent (this);
89 void LocaleNode::setParent ( LocaleNode
* node
) {
93 const LocaleNode
* LocaleNode::getRoot() const
95 const LocaleNode
* pRoot
= 0;
96 const LocaleNode
* pParent
= this;
97 while ( (pParent
= pParent
->getParent()) != 0 )
102 const LocaleNode
* LocaleNode::findNode ( const sal_Char
*name
) const {
103 if (aName
.equalsAscii(name
))
105 for (sal_Int32 i
= 0; i
< nChildren
; i
++) {
106 const LocaleNode
*n
=children
[i
]->findNode(name
);
113 LocaleNode::~LocaleNode()
115 for (sal_Int32 i
=0; i
< nChildren
; ++i
)
120 LocaleNode
* LocaleNode::createNode (const OUString
& name
, const Reference
< XAttributeList
> & attr
)
122 if ( name
== "LC_INFO" )
123 return new LCInfoNode (name
,attr
);
124 if ( name
== "LC_CTYPE" )
125 return new LCCTYPENode (name
,attr
);
126 if ( name
== "LC_FORMAT" )
127 return new LCFormatNode (name
,attr
);
128 if ( name
== "LC_FORMAT_1" )
129 return new LCFormatNode (name
,attr
);
130 if ( name
== "LC_CALENDAR" )
131 return new LCCalendarNode (name
,attr
);
132 if ( name
== "LC_CURRENCY" )
133 return new LCCurrencyNode (name
,attr
);
134 if ( name
== "LC_TRANSLITERATION" )
135 return new LCTransliterationNode (name
,attr
);
136 if ( name
== "LC_COLLATION" )
137 return new LCCollationNode (name
,attr
);
138 if ( name
== "LC_INDEX" )
139 return new LCIndexNode (name
,attr
);
140 if ( name
== "LC_SEARCH" )
141 return new LCSearchNode (name
,attr
);
142 if ( name
== "LC_MISC" )
143 return new LCMiscNode (name
,attr
);
144 if ( name
== "LC_NumberingLevel" )
145 return new LCNumberingLevelNode (name
, attr
);
146 if ( name
== "LC_OutLineNumberingLevel" )
147 return new LCOutlineNumberingLevelNode (name
, attr
);
149 return new LocaleNode(name
,attr
);
153 // printf(" name: '%s'\n", p->getName().pData->buffer );
154 // printf("value: '%s'\n", p->getValue().pData->buffer );
156 #define OSTR(s) (OUStringToOString( (s), RTL_TEXTENCODING_UTF8).getStr())
158 void print_OUString( const OUString
& s
)
160 printf( "%s", OSTR(s
));
163 bool is_empty_string( const OUString
& s
)
165 return s
.isEmpty() || (s
.getLength()==1 && s
[0]=='\n');
168 void print_indent( int depth
)
170 for( int i
=0; i
<depth
; i
++ ) printf(" ");
173 void print_color( int color
)
175 printf("\033[%dm", color
);
178 void print_node( const LocaleNode
* p
, int depth
=0 )
182 print_indent( depth
);
185 print_OUString( p
->getName() );
187 const Attr
& q
= p
->getAttr();
188 for( sal_Int32 j
= 0; j
< q
.getLength(); ++j
)
192 print_OUString( q
.getTypeByIndex(j
) );
197 print_OUString( q
.getValueByIndex(j
) );
203 if( !is_empty_string( p
->getValue() ) )
205 print_indent( depth
+1 );
209 print_OUString( p
->getValue() );
214 for( sal_Int32 i
=0; i
<p
->getNumberOfChildren(); i
++ )
216 print_node( p
->getChildAt(i
), depth
+1 );
218 print_indent( depth
);
220 print_OUString( p
->getName() );
225 void LocaleNode :: generateCode (const OFileWriter
&of
) const
227 ::rtl::OUString aDTD
= getAttr().getValueByName("versionDTD");
228 if ( aDTD
!= LOCALE_VERSION_DTD
)
231 fprintf( stderr
, "Error: Locale versionDTD is not %s, see comment in locale.dtd\n", LOCALE_VERSION_DTD
);
233 for (sal_Int32 i
=0; i
<nChildren
;i
++)
234 children
[i
]->generateCode (of
);
235 // print_node( this );
239 ::rtl::OUString
LocaleNode::writeParameterCheckLen( const OFileWriter
&of
,
240 const char* pParameterName
, const LocaleNode
* pNode
,
241 sal_Int32 nMinLen
, sal_Int32 nMaxLen
) const
245 aVal
= pNode
->getValue();
249 fprintf( stderr
, "Error: node NULL pointer for parameter %s.\n",
252 // write empty data if error
253 of
.writeParameter( pParameterName
, aVal
);
254 sal_Int32 nLen
= aVal
.getLength();
258 fprintf( stderr
, "Error: less than %ld character%s (%ld) in %s '%s'.\n",
259 sal::static_int_cast
< long >(nMinLen
), (nMinLen
> 1 ? "s" : ""),
260 sal::static_int_cast
< long >(nLen
),
261 (pNode
? OSTR( pNode
->getName()) : ""),
264 else if (nLen
> nMaxLen
&& nMaxLen
>= 0)
266 "Warning: more than %ld character%s (%ld) in %s %s not supported by application.\n",
267 sal::static_int_cast
< long >(nMaxLen
), (nMaxLen
> 1 ? "s" : ""),
268 sal::static_int_cast
< long >(nLen
),
269 (pNode
? OSTR( pNode
->getName()) : ""),
275 ::rtl::OUString
LocaleNode::writeParameterCheckLen( const OFileWriter
&of
,
276 const char* pNodeName
, const char* pParameterName
,
277 sal_Int32 nMinLen
, sal_Int32 nMaxLen
) const
280 const LocaleNode
* pNode
= findNode( pNodeName
);
282 aVal
= writeParameterCheckLen( of
, pParameterName
, pNode
, nMinLen
, nMaxLen
);
286 fprintf( stderr
, "Error: node %s not found.\n", pNodeName
);
287 // write empty data if error
288 of
.writeParameter( pParameterName
, aVal
);
293 void LocaleNode::incError( const char* pStr
) const
296 fprintf( stderr
, "Error: %s\n", pStr
);
299 void LocaleNode::incError( const ::rtl::OUString
& rStr
) const
301 incError( OSTR( rStr
));
304 char* LocaleNode::prepareErrorFormat( const char* pFormat
, const char* pDefaultConversion
) const
306 static char buf
[2048];
307 strcpy( buf
, "Error: ");
308 strncat( buf
, pFormat
, 2000);
310 while (((p
= strchr( p
, '%')) != 0) && p
[1] == '%')
313 strcat( buf
, pDefaultConversion
);
318 void LocaleNode::incErrorInt( const char* pStr
, int nVal
) const
321 fprintf( stderr
, prepareErrorFormat( pStr
, ": %d"), nVal
);
324 void LocaleNode::incErrorStr( const char* pStr
, const ::rtl::OUString
& rVal
) const
327 fprintf( stderr
, prepareErrorFormat( pStr
, ": %s"), OSTR( rVal
));
330 void LocaleNode::incErrorStrStr( const char* pStr
, const ::rtl::OUString
& rVal1
, const ::rtl::OUString
& rVal2
) const
333 fprintf( stderr
, prepareErrorFormat( pStr
, ": %s %s"), OSTR( rVal1
), OSTR( rVal2
));
336 void LCInfoNode::generateCode (const OFileWriter
&of
) const
339 const LocaleNode
* languageNode
= findNode("Language");
340 const LocaleNode
* countryNode
= findNode("Country");
341 const LocaleNode
* variantNode
= findNode("Variant");
345 writeParameterCheckLen( of
, "langID", languageNode
->getChildAt(0), 2, -1);
346 of
.writeParameter("langDefaultName", languageNode
->getChildAt(1)->getValue());
349 incError( "No Language node.");
352 of
.writeParameter("countryID", countryNode
->getChildAt(0)->getValue());
353 of
.writeParameter("countryDefaultName", countryNode
->getChildAt(1)->getValue());
356 incError( "No Country node.");
359 of
.writeParameter("Variant", variantNode
->getValue());
360 fprintf( stderr
, "Warning: %s\n",
361 "Variants are not supported by application.");
364 of
.writeParameter("Variant", ::rtl::OUString());
365 of
.writeAsciiString("\nstatic const sal_Unicode* LCInfoArray[] = {\n");
366 of
.writeAsciiString("\tlangID,\n");
367 of
.writeAsciiString("\tlangDefaultName,\n");
368 of
.writeAsciiString("\tcountryID,\n");
369 of
.writeAsciiString("\tcountryDefaultName,\n");
370 of
.writeAsciiString("\tVariant\n");
371 of
.writeAsciiString("};\n\n");
372 of
.writeFunction("getLCInfo_", "0", "LCInfoArray");
376 static OUString aDateSep
;
377 static OUString aDecSep
;
379 void LCCTYPENode::generateCode (const OFileWriter
&of
) const
381 const LocaleNode
* sepNode
= 0;
382 ::rtl::OUString useLocale
= getAttr().getValueByName("ref");
383 if (!useLocale
.isEmpty()) {
384 of
.writeRefFunction("getLocaleItem_", useLocale
);
387 ::rtl::OUString str
= getAttr().getValueByName("unoid");
388 of
.writeAsciiString("\n\n");
389 of
.writeParameter("LC_CTYPE_Unoid", str
);;
392 writeParameterCheckLen( of
, "DateSeparator", "dateSeparator", 1, 1);
394 writeParameterCheckLen( of
, "ThousandSeparator", "thousandSeparator", 1, 1);
396 writeParameterCheckLen( of
, "DecimalSeparator", "decimalSeparator", 1, 1);
398 writeParameterCheckLen( of
, "TimeSeparator", "timeSeparator", 1, 1);
399 OUString aTime100Sep
=
400 writeParameterCheckLen( of
, "Time100SecSeparator", "time100SecSeparator", 1, 1);
402 writeParameterCheckLen( of
, "ListSeparator", "listSeparator", 1, 1);
406 sepNode
= findNode("LongDateDayOfWeekSeparator");
407 aLDS
= sepNode
->getValue();
408 of
.writeParameter("LongDateDayOfWeekSeparator", aLDS
);
409 if (aLDS
.getLength() == 1 && aLDS
.getStr()[0] == ',')
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
.getLength() == 1 && (aLDS
.getStr()[0] == ',' || aLDS
.getStr()[0] == '.'))
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
);
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
);
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
;
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
.getStr()[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);
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.
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)
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)
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)
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)
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
603 incError("more than 2 LC_FORMAT sections");
605 ::std::vector
< OUString
> theDateAcceptancePatterns
;
608 OUString
strFrom( getAttr().getValueByName("replaceFrom"));
609 of
.writeParameter("replaceFrom", strFrom
, mnSection
);
610 str
= getAttr().getValueByName("replaceTo");
611 if (!strFrom
.isEmpty() && str
.isEmpty())
612 incErrorStr("replaceFrom=\"%s\" replaceTo=\"\" is empty replacement.", strFrom
);
613 // Locale data generator inserts FFFF for LangID, we need to adapt that.
614 if (str
.endsWithIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "-FFFF]")))
615 incErrorStr("replaceTo=\"%s\" needs FFFF to be adapted to the real LangID value.", str
);
616 of
.writeParameter("replaceTo", str
, mnSection
);
617 // Remember the replaceTo value for "[CURRENCY]" to check format codes.
618 if ( strFrom
== "[CURRENCY]" )
619 sTheCurrencyReplaceTo
= str
;
620 // Remember the currency symbol if present.
621 if (str
.indexOfAsciiL( "[$", 2) == 0)
623 sal_Int32 nHyphen
= str
.indexOf( '-');
626 sTheCompatibleCurrency
= str
.copy( 2, nHyphen
- 2);
630 ::rtl::OUString useLocale
= getAttr().getValueByName("ref");
631 if (!useLocale
.isEmpty())
636 of
.writeRefFunction("getAllFormats0_", useLocale
, "replaceTo0");
639 of
.writeRefFunction("getAllFormats1_", useLocale
, "replaceTo1");
642 of
.writeRefFunction("getDateAcceptancePatterns_", useLocale
);
646 sal_Int16 formatCount
= mnFormats
;
648 ValueSet aFormatIndexSet
;
649 NameSet aDefaultsSet
;
650 bool bCtypeIsRef
= false;
652 for (sal_Int16 i
= 0; i
< getNumberOfChildren() ; i
++, formatCount
++)
654 LocaleNode
* currNode
= getChildAt (i
);
655 if ( currNode
->getName() == "DateAcceptancePattern" )
658 incError( "DateAcceptancePattern only handled in LC_FORMAT, not LC_FORMAT_1");
660 theDateAcceptancePatterns
.push_back( currNode
->getValue());
664 if ( currNode
->getName() != "FormatElement" )
666 incErrorStr( "Undefined element in LC_FORMAT", currNode
->getName());
673 OUString aFormatIndex
;
674 // currNode -> print();
675 const Attr
&currNodeAttr
= currNode
->getAttr();
676 //printf ("getLen() = %d\n", currNode->getAttr().getLength());
678 str
= currNodeAttr
.getValueByName("msgid");
679 if (!aMsgIdSet
.insert( str
).second
)
680 incErrorStr( "Duplicated msgid=\"%s\" in FormatElement.", str
);
681 of
.writeParameter("FormatKey", str
, formatCount
);
683 str
= currNodeAttr
.getValueByName("default");
684 bool bDefault
= str
== "true";
685 of
.writeDefaultParameter("FormatElement", str
, formatCount
);
687 aType
= currNodeAttr
.getValueByName("type");
688 of
.writeParameter("FormatType", aType
, formatCount
);
690 aUsage
= currNodeAttr
.getValueByName("usage");
691 of
.writeParameter("FormatUsage", aUsage
, formatCount
);
693 aFormatIndex
= currNodeAttr
.getValueByName("formatindex");
694 sal_Int16 formatindex
= (sal_Int16
)aFormatIndex
.toInt32();
695 if (!aFormatIndexSet
.insert( formatindex
).second
)
696 incErrorInt( "Duplicated formatindex=\"%d\" in FormatElement.", formatindex
);
697 of
.writeIntParameter("Formatindex", formatCount
, formatindex
);
699 // Ensure only one default per usage and type.
702 OUString
aKey( aUsage
+ OUString( sal_Unicode(',')) + aType
);
703 if (!aDefaultsSet
.insert( aKey
).second
)
705 OUString
aStr( "Duplicated default for usage=\"");
707 aStr
+= OUString( "\" type=\"");
709 aStr
+= OUString( "\": formatindex=\"");
710 aStr
+= aFormatIndex
;
711 aStr
+= OUString( "\".");
716 const LocaleNode
* n
= currNode
-> findNode("FormatCode");
719 of
.writeParameter("FormatCode", n
->getValue(), formatCount
);
720 // Check separator usage for some FormatCode elements.
721 const LocaleNode
* pCtype
= 0;
724 case cssi::NumberFormatIndex::DATE_SYS_DDMMYYYY
:
725 sTheDateEditFormat
= n
->getValue();
727 case cssi::NumberFormatIndex::NUMBER_1000DEC2
: // #,##0.00
728 case cssi::NumberFormatIndex::TIME_MMSS00
: // MM:SS.00
729 case cssi::NumberFormatIndex::TIME_HH_MMSS00
: // [HH]:MM:SS.00
731 const LocaleNode
* pRoot
= getRoot();
733 incError( "No root for FormatCode.");
736 pCtype
= pRoot
->findNode( "LC_CTYPE");
738 incError( "No LC_CTYPE found for FormatCode.");
741 OUString
aRef( pCtype
->getAttr().getValueByName("ref"));
746 "Warning: Can't check separators used in FormatCode due to LC_CTYPE ref=\"%s\".\n"
747 "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",
756 case cssi::NumberFormatIndex::CURRENCY_1000DEC2
:
757 // Remember the currency symbol if present.
760 if (sTheCompatibleCurrency
.isEmpty() &&
761 ((nStart
= n
->getValue().indexOfAsciiL( "[$", 2)) >= 0))
763 OUString
aCode( n
->getValue());
764 sal_Int32 nHyphen
= aCode
.indexOf( '-', nStart
);
765 if (nHyphen
>= nStart
+ 3)
766 sTheCompatibleCurrency
= aCode
.copy( nStart
+ 2, nHyphen
- nStart
- 2);
770 case cssi::NumberFormatIndex::CURRENCY_1000INT
:
771 case cssi::NumberFormatIndex::CURRENCY_1000INT_RED
:
772 case cssi::NumberFormatIndex::CURRENCY_1000DEC2_RED
:
773 case cssi::NumberFormatIndex::CURRENCY_1000DEC2_CCC
:
774 case cssi::NumberFormatIndex::CURRENCY_1000DEC2_DASHED
:
775 // Currency formats should be something like [C]###0;-[C]###0
776 // and not parenthesized [C]###0;([C]###0) if not en_US.
777 if (strcmp( of
.getLocale(), "en_US") != 0)
779 OUString
aCode( n
->getValue());
780 OUString
aPar1( "0)");
781 OUString
aPar2( "-)" );
782 OUString
aPar3( " )" );
783 OUString
aPar4( "])" );
784 if (aCode
.indexOf( aPar1
) > 0 || aCode
.indexOf( aPar2
) > 0 ||
785 aCode
.indexOf( aPar3
) > 0 || aCode
.indexOf( aPar4
) > 0)
786 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
);
788 // Check if we have replaceTo for "[CURRENCY]" placeholder.
789 if (sTheCurrencyReplaceTo
.isEmpty())
791 OUString
aCode( n
->getValue());
792 if (aCode
.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "[CURRENCY]")) >= 0)
793 incErrorInt( "[CURRENCY] replaceTo not found for formatindex=\"%d\".", formatindex
);
799 int nSavErr
= nError
;
800 OUString
aCode( n
->getValue());
801 if (formatindex
== cssi::NumberFormatIndex::NUMBER_1000DEC2
)
805 const LocaleNode
* pSep
= pCtype
->findNode( "DecimalSeparator");
807 incError( "No DecimalSeparator found for FormatCode.");
810 nDec
= aCode
.indexOf( pSep
->getValue());
812 incErrorInt( "DecimalSeparator not present in FormatCode formatindex=\"%d\".",
815 pSep
= pCtype
->findNode( "ThousandSeparator");
817 incError( "No ThousandSeparator found for FormatCode.");
820 nGrp
= aCode
.indexOf( pSep
->getValue());
822 incErrorInt( "ThousandSeparator not present in FormatCode formatindex=\"%d\".",
825 if (nDec
>= 0 && nGrp
>= 0 && nDec
<= nGrp
)
826 incErrorInt( "Ordering of ThousandSeparator and DecimalSeparator not correct in formatindex=\"%d\".",
829 if (formatindex
== cssi::NumberFormatIndex::TIME_MMSS00
||
830 formatindex
== cssi::NumberFormatIndex::TIME_HH_MMSS00
)
832 sal_Int32 nTime
= -1;
833 sal_Int32 n100s
= -1;
834 const LocaleNode
* pSep
= pCtype
->findNode( "TimeSeparator");
836 incError( "No TimeSeparator found for FormatCode.");
839 nTime
= aCode
.indexOf( pSep
->getValue());
841 incErrorInt( "TimeSeparator not present in FormatCode formatindex=\"%d\".",
844 pSep
= pCtype
->findNode( "Time100SecSeparator");
846 incError( "No Time100SecSeparator found for FormatCode.");
849 n100s
= aCode
.indexOf( pSep
->getValue());
851 incErrorInt( "Time100SecSeparator not present in FormatCode formatindex=\"%d\".",
853 OUStringBuffer
a100s( pSep
->getValue());
854 a100s
.appendAscii( "00");
855 n100s
= aCode
.indexOf( a100s
.makeStringAndClear());
857 incErrorInt( "Time100SecSeparator+00 not present in FormatCode formatindex=\"%d\".",
860 if (n100s
>= 0 && nTime
>= 0 && n100s
<= nTime
)
861 incErrorInt( "Ordering of Time100SecSeparator and TimeSeparator not correct in formatindex=\"%d\".",
864 if (nSavErr
!= nError
)
866 "Warning: formatindex=\"%d\",\"%d\",\"%d\" are the only FormatCode elements checked for separator usage, there may be others that have errors.\n",
867 int(cssi::NumberFormatIndex::NUMBER_1000DEC2
),
868 int(cssi::NumberFormatIndex::TIME_MMSS00
),
869 int(cssi::NumberFormatIndex::TIME_HH_MMSS00
));
874 incError( "No FormatCode in FormatElement.");
875 n
= currNode
-> findNode("DefaultName");
877 of
.writeParameter("FormatDefaultName", n
->getValue(), formatCount
);
879 of
.writeParameter("FormatDefaultName", ::rtl::OUString(), formatCount
);
883 // Check presence of all required format codes only in first section
884 // LC_FORMAT, not in optional LC_FORMAT_1
887 // 0..47 MUST be present, 48,49 MUST NOT be present
888 ValueSet::const_iterator
aIter( aFormatIndexSet
.begin());
889 for (sal_Int16 nNext
= cssi::NumberFormatIndex::NUMBER_START
;
890 nNext
< cssi::NumberFormatIndex::INDEX_TABLE_ENTRIES
; ++nNext
)
892 sal_Int16 nHere
= ::std::min( ((aIter
!= aFormatIndexSet
.end() ? *aIter
:
893 cssi::NumberFormatIndex::INDEX_TABLE_ENTRIES
)),
894 cssi::NumberFormatIndex::INDEX_TABLE_ENTRIES
);
895 if (aIter
!= aFormatIndexSet
.end()) ++aIter
;
896 for ( ; nNext
< nHere
; ++nNext
)
900 case cssi::NumberFormatIndex::FRACTION_1
:
901 case cssi::NumberFormatIndex::FRACTION_2
:
902 case cssi::NumberFormatIndex::BOOLEAN
:
903 case cssi::NumberFormatIndex::TEXT
:
904 // generated internally
907 incErrorInt( "FormatElement formatindex=\"%d\" not present.", nNext
);
912 case cssi::NumberFormatIndex::BOOLEAN
:
913 incErrorInt( "FormatElement formatindex=\"%d\" reserved for internal ``BOOLEAN''.", nNext
);
915 case cssi::NumberFormatIndex::TEXT
:
916 incErrorInt( "FormatElement formatindex=\"%d\" reserved for internal ``@'' (TEXT).", nNext
);
924 of
.writeAsciiString("\nstatic const sal_Int16 ");
925 of
.writeAsciiString("FormatElementsCount");
926 of
.writeInt(mnSection
);
927 of
.writeAsciiString(" = ");
928 of
.writeInt( formatCount
- mnFormats
);
929 of
.writeAsciiString(";\n");
930 of
.writeAsciiString("static const sal_Unicode* ");
931 of
.writeAsciiString("FormatElementsArray");
932 of
.writeInt(mnSection
);
933 of
.writeAsciiString("[] = {\n");
934 for(sal_Int16 i
= mnFormats
; i
< formatCount
; i
++) {
936 of
.writeAsciiString("\t");
937 of
.writeAsciiString("FormatCode");
939 of
.writeAsciiString(",\n");
941 of
.writeAsciiString("\t");
942 of
.writeAsciiString("FormatDefaultName");
944 of
.writeAsciiString(",\n");
946 of
.writeAsciiString("\t");
947 of
.writeAsciiString("FormatKey");
949 of
.writeAsciiString(",\n");
951 of
.writeAsciiString("\t");
952 of
.writeAsciiString("FormatType");
954 of
.writeAsciiString(",\n");
956 of
.writeAsciiString("\t");
957 of
.writeAsciiString("FormatUsage");
959 of
.writeAsciiString(",\n");
961 of
.writeAsciiString("\t");
962 of
.writeAsciiString("Formatindex");
964 of
.writeAsciiString(",\n");
967 of
.writeAsciiString("\tdefaultFormatElement");
969 of
.writeAsciiString(",\n");
971 of
.writeAsciiString("};\n\n");
976 of
.writeFunction("getAllFormats0_", "FormatElementsCount0", "FormatElementsArray0", "replaceFrom0", "replaceTo0");
979 of
.writeFunction("getAllFormats1_", "FormatElementsCount1", "FormatElementsArray1", "replaceFrom1", "replaceTo1");
983 mnFormats
= mnFormats
+ formatCount
;
987 // Extract and add date acceptance pattern for full date, so we provide
988 // at least one valid pattern, even if the number parser doesn't need
990 /* XXX NOTE: only simple [...] modifier and "..." quotes detected and
991 * ignored, not nested, no fancy stuff. */
992 sal_Int32 nIndex
= 0;
993 // aDateSep can be empty if LC_CTYPE was a ref=..., determine from
995 sal_uInt32 cDateSep
= (aDateSep
.isEmpty() ? 0 : aDateSep
.iterateCodePoints( &nIndex
));
996 sal_uInt32 cDateSep2
= cDateSep
;
998 OUStringBuffer
aPatternBuf(5);
999 OUStringBuffer
aPatternBuf2(5);
1000 sal_uInt8 nDetected
= 0; // bits Y,M,D
1001 bool bInModifier
= false;
1002 bool bQuoted
= false;
1003 while (nIndex
< sTheDateEditFormat
.getLength() && nDetected
< 7)
1005 sal_uInt32 cChar
= sTheDateEditFormat
.iterateCodePoints( &nIndex
);
1009 bInModifier
= false;
1022 if (!(nDetected
& 4))
1024 aPatternBuf
.append( 'Y');
1025 if (aPatternBuf2
.getLength() > 0)
1026 aPatternBuf2
.append( 'Y');
1032 if (!(nDetected
& 2))
1034 aPatternBuf
.append( 'M');
1035 if (aPatternBuf2
.getLength() > 0)
1036 aPatternBuf2
.append( 'M');
1042 if (!(nDetected
& 1))
1044 aPatternBuf
.append( 'D');
1045 if (aPatternBuf2
.getLength() > 0)
1046 aPatternBuf2
.append( 'D');
1057 cChar
= sTheDateEditFormat
.iterateCodePoints( &nIndex
);
1062 // There are locales that use an ISO 8601 edit format
1063 // regardless of what the date separator or other formats
1064 // say, for example hu-HU. Generalize this for all cases
1065 // where the used separator differs and is one of the known
1066 // separators and generate a second pattern with the
1067 // format's separator at the current position.
1075 if (cDateSep
!= cDateSep2
&& aPatternBuf2
.getLength() == 0)
1076 aPatternBuf2
= aPatternBuf
;
1077 if (cChar
== cDateSep
|| cChar
== cDateSep2
)
1078 aPatternBuf
.append( OUString( &cDateSep
, 1)); // always the defined separator
1079 if (cChar
== cDateSep2
&& aPatternBuf2
.getLength() > 0)
1080 aPatternBuf2
.append( OUString( &cDateSep2
, 1)); // always the format's separator
1082 // The localized legacy:
1084 if (((nDetected
& 7) == 3) || ((nDetected
& 7) == 0))
1090 aPatternBuf
.append( 'Y');
1091 if (aPatternBuf2
.getLength() > 0)
1092 aPatternBuf2
.append( 'Y');
1097 if (((nDetected
& 7) == 0) || ((nDetected
& 7) == 6))
1101 aPatternBuf
.append( 'D');
1102 if (aPatternBuf2
.getLength() > 0)
1103 aPatternBuf2
.append( 'D');
1106 else if ((nDetected
& 7) == 3)
1110 aPatternBuf
.append( 'Y');
1111 if (aPatternBuf2
.getLength() > 0)
1112 aPatternBuf2
.append( 'Y');
1117 if ((nDetected
& 7) == 0)
1120 aPatternBuf
.append( 'D');
1121 if (aPatternBuf2
.getLength() > 0)
1122 aPatternBuf2
.append( 'D');
1127 if ((nDetected
& 7) == 0)
1130 aPatternBuf
.append( 'D');
1131 if (aPatternBuf2
.getLength() > 0)
1132 aPatternBuf2
.append( 'D');
1137 if ((nDetected
& 7) == 0)
1140 aPatternBuf
.append( 'D');
1141 if (aPatternBuf2
.getLength() > 0)
1142 aPatternBuf2
.append( 'D');
1147 if ((nDetected
& 7) == 1)
1150 aPatternBuf
.append( 'M');
1151 if (aPatternBuf2
.getLength() > 0)
1152 aPatternBuf2
.append( 'M');
1157 if ((nDetected
& 7) == 3)
1160 aPatternBuf
.append( 'Y');
1161 if (aPatternBuf2
.getLength() > 0)
1162 aPatternBuf2
.append( 'Y');
1168 OUString
aPattern( aPatternBuf
.makeStringAndClear());
1169 if (((nDetected
& 7) != 7) || aPattern
.getLength() < 5)
1171 incErrorStr( "failed to extract full date acceptance pattern", aPattern
);
1172 fprintf( stderr
, " with DateSeparator '%s' from FormatCode '%s' (formatindex=\"%d\")\n",
1173 OSTR( OUString( cDateSep
)), OSTR( sTheDateEditFormat
),
1174 (int)cssi::NumberFormatIndex::DATE_SYS_DDMMYYYY
);
1178 fprintf( stderr
, "Generated date acceptance pattern: '%s' from '%s' (formatindex=\"%d\" and defined DateSeparator '%s')\n",
1179 OSTR( aPattern
), OSTR( sTheDateEditFormat
),
1180 (int)cssi::NumberFormatIndex::DATE_SYS_DDMMYYYY
,
1181 OSTR( OUString( cDateSep
)));
1182 // Insert at front so full date pattern is first in checks.
1183 theDateAcceptancePatterns
.insert( theDateAcceptancePatterns
.begin(), aPattern
);
1185 if (aPatternBuf2
.getLength() > 0)
1187 OUString
aPattern2( aPatternBuf2
.makeStringAndClear());
1188 if (aPattern2
.getLength() < 5)
1190 incErrorStr( "failed to extract 2nd date acceptance pattern", aPattern2
);
1191 fprintf( stderr
, " with DateSeparator '%s' from FormatCode '%s' (formatindex=\"%d\")\n",
1192 OSTR( OUString( cDateSep2
)), OSTR( sTheDateEditFormat
),
1193 (int)cssi::NumberFormatIndex::DATE_SYS_DDMMYYYY
);
1197 fprintf( stderr
, "Generated 2nd acceptance pattern: '%s' from '%s' (formatindex=\"%d\")\n",
1198 OSTR( aPattern2
), OSTR( sTheDateEditFormat
),
1199 (int)cssi::NumberFormatIndex::DATE_SYS_DDMMYYYY
);
1200 theDateAcceptancePatterns
.insert( theDateAcceptancePatterns
.begin(), aPattern2
);
1204 // Rudimentary check if a pattern interferes with decimal number.
1206 sal_uInt32 cDecSep
= aDecSep
.iterateCodePoints( &nIndex
);
1207 for (vector
<OUString
>::const_iterator aIt
= theDateAcceptancePatterns
.begin();
1208 aIt
!= theDateAcceptancePatterns
.end(); ++aIt
)
1210 if ((*aIt
).getLength() == (cDecSep
<= 0xffff ? 3 : 4))
1213 if ((*aIt
).iterateCodePoints( &nIndex
) == cDecSep
)
1216 fprintf( stderr
, "Error: Date acceptance pattern '%s' matches decimal number '#%s#'\n",
1217 OSTR( *aIt
), OSTR( aDecSep
));
1222 // Check for duplicates.
1223 for (vector
<OUString
>::const_iterator aIt
= theDateAcceptancePatterns
.begin();
1224 aIt
!= theDateAcceptancePatterns
.end(); ++aIt
)
1226 for (vector
<OUString
>::iterator aComp
= theDateAcceptancePatterns
.begin();
1227 aComp
!= theDateAcceptancePatterns
.end(); /*nop*/)
1229 if (aIt
!= aComp
&& *aIt
== *aComp
)
1231 incErrorStr( "Duplicated DateAcceptancePattern", *aComp
);
1232 aComp
= theDateAcceptancePatterns
.erase( aComp
);
1239 sal_Int16 nbOfDateAcceptancePatterns
= static_cast<sal_Int16
>(theDateAcceptancePatterns
.size());
1241 for (sal_Int16 i
= 0; i
< nbOfDateAcceptancePatterns
; ++i
)
1243 of
.writeParameter("DateAcceptancePattern", theDateAcceptancePatterns
[i
], i
);
1246 of
.writeAsciiString("static const sal_Int16 DateAcceptancePatternsCount = ");
1247 of
.writeInt( nbOfDateAcceptancePatterns
);
1248 of
.writeAsciiString(";\n");
1250 of
.writeAsciiString("static const sal_Unicode* DateAcceptancePatternsArray[] = {\n");
1251 for (sal_Int16 i
= 0; i
< nbOfDateAcceptancePatterns
; ++i
)
1253 of
.writeAsciiString("\t");
1254 of
.writeAsciiString("DateAcceptancePattern");
1256 of
.writeAsciiString(",\n");
1258 of
.writeAsciiString("};\n\n");
1260 of
.writeFunction("getDateAcceptancePatterns_", "DateAcceptancePatternsCount", "DateAcceptancePatternsArray");
1266 void LCCollationNode::generateCode (const OFileWriter
&of
) const
1268 ::rtl::OUString useLocale
= getAttr().getValueByName("ref");
1269 if (!useLocale
.isEmpty()) {
1270 of
.writeRefFunction("getCollatorImplementation_", useLocale
);
1271 of
.writeRefFunction("getCollationOptions_", useLocale
);
1274 sal_Int16 nbOfCollations
= 0;
1275 sal_Int16 nbOfCollationOptions
= 0;
1278 for ( j
= 0; j
< getNumberOfChildren(); j
++ ) {
1279 LocaleNode
* currNode
= getChildAt (j
);
1280 if( currNode
->getName().compareToAscii("Collator") == 0 )
1282 ::rtl::OUString str
;
1283 str
= currNode
->getAttr().getValueByName("unoid");
1284 of
.writeParameter("CollatorID", str
, j
);
1285 str
= currNode
->getValue();
1286 of
.writeParameter("CollatorRule", str
, j
);
1287 str
= currNode
-> getAttr().getValueByName("default");
1288 of
.writeDefaultParameter("Collator", str
, j
);
1289 of
.writeAsciiString("\n");
1293 if( currNode
->getName().compareToAscii("CollationOptions") == 0 )
1295 LocaleNode
* pCollationOptions
= currNode
;
1296 nbOfCollationOptions
= sal::static_int_cast
<sal_Int16
>( pCollationOptions
->getNumberOfChildren() );
1297 for( sal_Int16 i
=0; i
<nbOfCollationOptions
; i
++ )
1299 of
.writeParameter("collationOption", pCollationOptions
->getChildAt( i
)->getValue(), i
);
1302 of
.writeAsciiString("static const sal_Int16 nbOfCollationOptions = ");
1303 of
.writeInt( nbOfCollationOptions
);
1304 of
.writeAsciiString(";\n\n");
1307 of
.writeAsciiString("static const sal_Int16 nbOfCollations = ");
1308 of
.writeInt(nbOfCollations
);
1309 of
.writeAsciiString(";\n\n");
1311 of
.writeAsciiString("\nstatic const sal_Unicode* LCCollatorArray[] = {\n");
1312 for(j
= 0; j
< nbOfCollations
; j
++) {
1313 of
.writeAsciiString("\tCollatorID");
1315 of
.writeAsciiString(",\n");
1317 of
.writeAsciiString("\tdefaultCollator");
1319 of
.writeAsciiString(",\n");
1321 of
.writeAsciiString("\tCollatorRule");
1323 of
.writeAsciiString(",\n");
1325 of
.writeAsciiString("};\n\n");
1327 of
.writeAsciiString("static const sal_Unicode* collationOptions[] = {");
1328 for( j
=0; j
<nbOfCollationOptions
; j
++ )
1330 of
.writeAsciiString( "collationOption" );
1332 of
.writeAsciiString( ", " );
1334 of
.writeAsciiString("NULL };\n");
1335 of
.writeFunction("getCollatorImplementation_", "nbOfCollations", "LCCollatorArray");
1336 of
.writeFunction("getCollationOptions_", "nbOfCollationOptions", "collationOptions");
1339 void LCSearchNode::generateCode (const OFileWriter
&of
) const
1341 ::rtl::OUString useLocale
= getAttr().getValueByName("ref");
1342 if (!useLocale
.isEmpty()) {
1343 of
.writeRefFunction("getSearchOptions_", useLocale
);
1347 if( getNumberOfChildren() != 1 )
1351 stderr
, "Error: LC_SEARCH: more than 1 child: %ld\n",
1352 sal::static_int_cast
< long >(getNumberOfChildren()));
1355 LocaleNode
* pSearchOptions
= getChildAt( 0 );
1356 sal_Int32 nSearchOptions
= pSearchOptions
->getNumberOfChildren();
1357 for( i
=0; i
<nSearchOptions
; i
++ )
1359 of
.writeParameter("searchOption", pSearchOptions
->getChildAt( i
)->getValue(), sal::static_int_cast
<sal_Int16
>(i
) );
1362 of
.writeAsciiString("static const sal_Int16 nbOfSearchOptions = ");
1363 of
.writeInt( sal::static_int_cast
<sal_Int16
>( nSearchOptions
) );
1364 of
.writeAsciiString(";\n\n");
1366 of
.writeAsciiString("static const sal_Unicode* searchOptions[] = {");
1367 for( i
=0; i
<nSearchOptions
; i
++ )
1369 of
.writeAsciiString( "searchOption" );
1370 of
.writeInt( sal::static_int_cast
<sal_Int16
>(i
) );
1371 of
.writeAsciiString( ", " );
1373 of
.writeAsciiString("NULL };\n");
1374 of
.writeFunction("getSearchOptions_", "nbOfSearchOptions", "searchOptions");
1377 void LCIndexNode::generateCode (const OFileWriter
&of
) const
1379 ::rtl::OUString useLocale
= getAttr().getValueByName("ref");
1380 if (!useLocale
.isEmpty()) {
1381 of
.writeRefFunction("getIndexAlgorithm_", useLocale
);
1382 of
.writeRefFunction("getUnicodeScripts_", useLocale
);
1383 of
.writeRefFunction("getFollowPageWords_", useLocale
);
1386 sal_Int16 nbOfIndexs
= 0;
1387 sal_Int16 nbOfUnicodeScripts
= 0;
1388 sal_Int16 nbOfPageWords
= 0;
1390 for (i
= 0; i
< getNumberOfChildren();i
++) {
1391 LocaleNode
* currNode
= getChildAt (i
);
1392 if( currNode
->getName().compareToAscii("IndexKey") == 0 )
1394 ::rtl::OUString str
;
1395 str
= currNode
->getAttr().getValueByName("unoid");
1396 of
.writeParameter("IndexID", str
, nbOfIndexs
);
1397 str
= currNode
->getAttr().getValueByName("module");
1398 of
.writeParameter("IndexModule", str
, nbOfIndexs
);
1399 str
= currNode
->getValue();
1400 of
.writeParameter("IndexKey", str
, nbOfIndexs
);
1401 str
= currNode
-> getAttr().getValueByName("default");
1402 of
.writeDefaultParameter("Index", str
, nbOfIndexs
);
1403 str
= currNode
-> getAttr().getValueByName("phonetic");
1404 of
.writeDefaultParameter("Phonetic", str
, nbOfIndexs
);
1405 of
.writeAsciiString("\n");
1409 if( currNode
->getName().compareToAscii("UnicodeScript") == 0 )
1411 of
.writeParameter("unicodeScript", currNode
->getValue(), nbOfUnicodeScripts
);
1412 nbOfUnicodeScripts
++;
1415 if( currNode
->getName().compareToAscii("FollowPageWord") == 0 )
1417 of
.writeParameter("followPageWord", currNode
->getValue(), nbOfPageWords
);
1421 of
.writeAsciiString("static const sal_Int16 nbOfIndexs = ");
1422 of
.writeInt(nbOfIndexs
);
1423 of
.writeAsciiString(";\n\n");
1425 of
.writeAsciiString("\nstatic const sal_Unicode* IndexArray[] = {\n");
1426 for(i
= 0; i
< nbOfIndexs
; i
++) {
1427 of
.writeAsciiString("\tIndexID");
1429 of
.writeAsciiString(",\n");
1431 of
.writeAsciiString("\tIndexModule");
1433 of
.writeAsciiString(",\n");
1435 of
.writeAsciiString("\tIndexKey");
1437 of
.writeAsciiString(",\n");
1439 of
.writeAsciiString("\tdefaultIndex");
1441 of
.writeAsciiString(",\n");
1443 of
.writeAsciiString("\tdefaultPhonetic");
1445 of
.writeAsciiString(",\n");
1447 of
.writeAsciiString("};\n\n");
1449 of
.writeAsciiString("static const sal_Int16 nbOfUnicodeScripts = ");
1450 of
.writeInt( nbOfUnicodeScripts
);
1451 of
.writeAsciiString(";\n\n");
1453 of
.writeAsciiString("static const sal_Unicode* UnicodeScriptArray[] = {");
1454 for( i
=0; i
<nbOfUnicodeScripts
; i
++ )
1456 of
.writeAsciiString( "unicodeScript" );
1458 of
.writeAsciiString( ", " );
1460 of
.writeAsciiString("NULL };\n\n");
1462 of
.writeAsciiString("static const sal_Int16 nbOfPageWords = ");
1463 of
.writeInt(nbOfPageWords
);
1464 of
.writeAsciiString(";\n\n");
1466 of
.writeAsciiString("static const sal_Unicode* FollowPageWordArray[] = {\n");
1467 for(i
= 0; i
< nbOfPageWords
; i
++) {
1468 of
.writeAsciiString("\tfollowPageWord");
1470 of
.writeAsciiString(",\n");
1472 of
.writeAsciiString("\tNULL\n};\n\n");
1474 of
.writeFunction("getIndexAlgorithm_", "nbOfIndexs", "IndexArray");
1475 of
.writeFunction("getUnicodeScripts_", "nbOfUnicodeScripts", "UnicodeScriptArray");
1476 of
.writeFunction("getFollowPageWords_", "nbOfPageWords", "FollowPageWordArray");
1480 static void lcl_writeAbbrFullNarrNames( const OFileWriter
& of
, const LocaleNode
* currNode
,
1481 const sal_Char
* elementTag
, sal_Int16 i
, sal_Int16 j
)
1483 OUString aAbbrName
= currNode
->getChildAt(1)->getValue();
1484 OUString aFullName
= currNode
->getChildAt(2)->getValue();
1486 LocaleNode
* p
= (currNode
->getNumberOfChildren() > 3 ? currNode
->getChildAt(3) : 0);
1487 if ( p
&& p
->getName() == "DefaultNarrowName" )
1488 aNarrName
= p
->getValue();
1491 sal_Int32 nIndex
= 0;
1492 sal_uInt32 nChar
= aFullName
.iterateCodePoints( &nIndex
);
1493 aNarrName
= OUString( &nChar
, 1);
1495 of
.writeParameter( elementTag
, "DefaultAbbrvName", aAbbrName
, i
, j
);
1496 of
.writeParameter( elementTag
, "DefaultFullName", aFullName
, i
, j
);
1497 of
.writeParameter( elementTag
, "DefaultNarrowName", aNarrName
, i
, j
);
1500 static void lcl_writeTabTagString( const OFileWriter
& of
, const sal_Char
* pTag
, const sal_Char
* pStr
)
1502 of
.writeAsciiString("\t");
1503 of
.writeAsciiString( pTag
);
1504 of
.writeAsciiString( pStr
);
1507 static void lcl_writeTabTagStringNums( const OFileWriter
& of
,
1508 const sal_Char
* pTag
, const sal_Char
* pStr
, sal_Int16 i
, sal_Int16 j
)
1510 lcl_writeTabTagString( of
, pTag
, pStr
);
1511 of
.writeInt(i
); of
.writeInt(j
); of
.writeAsciiString(",\n");
1514 static void lcl_writeAbbrFullNarrArrays( const OFileWriter
& of
, sal_Int16 nCount
,
1515 const sal_Char
* elementTag
, sal_Int16 i
, bool bNarrow
)
1519 lcl_writeTabTagString( of
, elementTag
, "Ref");
1520 of
.writeInt(i
); of
.writeAsciiString(",\n");
1521 lcl_writeTabTagString( of
, elementTag
, "RefName");
1522 of
.writeInt(i
); of
.writeAsciiString(",\n");
1526 for (sal_Int16 j
= 0; j
< nCount
; j
++)
1528 lcl_writeTabTagStringNums( of
, elementTag
, "ID", i
, j
);
1529 lcl_writeTabTagStringNums( of
, elementTag
, "DefaultAbbrvName", i
, j
);
1530 lcl_writeTabTagStringNums( of
, elementTag
, "DefaultFullName", i
, j
);
1532 lcl_writeTabTagStringNums( of
, elementTag
, "DefaultNarrowName", i
, j
);
1537 void LCCalendarNode::generateCode (const OFileWriter
&of
) const
1539 ::rtl::OUString useLocale
= getAttr().getValueByName("ref");
1540 if (!useLocale
.isEmpty()) {
1541 of
.writeRefFunction("getAllCalendars_", useLocale
);
1544 sal_Int16 nbOfCalendars
= sal::static_int_cast
<sal_Int16
>( getNumberOfChildren() );
1545 ::rtl::OUString str
;
1546 sal_Int16
* nbOfDays
= new sal_Int16
[nbOfCalendars
];
1547 sal_Int16
* nbOfMonths
= new sal_Int16
[nbOfCalendars
];
1548 sal_Int16
* nbOfGenitiveMonths
= new sal_Int16
[nbOfCalendars
];
1549 sal_Int16
* nbOfPartitiveMonths
= new sal_Int16
[nbOfCalendars
];
1550 sal_Int16
* nbOfEras
= new sal_Int16
[nbOfCalendars
];
1553 bool bHasGregorian
= false;
1556 for ( i
= 0; i
< nbOfCalendars
; i
++) {
1557 LocaleNode
* calNode
= getChildAt (i
);
1558 OUString calendarID
= calNode
-> getAttr().getValueByName("unoid");
1559 of
.writeParameter( "calendarID", calendarID
, i
);
1560 bool bGregorian
= calendarID
== "gregorian";
1562 bHasGregorian
= bGregorian
;
1563 str
= calNode
-> getAttr().getValueByName("default");
1564 of
.writeDefaultParameter("Calendar", str
, i
);
1566 sal_Int16 nChild
= 0;
1568 // Generate Days of Week
1569 const sal_Char
*elementTag
;
1570 LocaleNode
* daysNode
= NULL
;
1571 ::rtl::OUString ref_name
= calNode
->getChildAt(nChild
)->getAttr().getValueByName("ref");
1572 if (!ref_name
.isEmpty() && i
> 0) {
1573 for (j
= 0; j
< i
; j
++) {
1574 str
= getChildAt(j
)->getAttr().getValueByName("unoid");
1575 if (str
.equals(ref_name
))
1576 daysNode
= getChildAt(j
)->getChildAt(0);
1579 if (!ref_name
.isEmpty() && daysNode
== NULL
) {
1580 of
.writeParameter("dayRef", OUString("ref"), i
);
1581 of
.writeParameter("dayRefName", ref_name
, i
);
1584 if (daysNode
== NULL
)
1585 daysNode
= calNode
-> getChildAt(nChild
);
1586 nbOfDays
[i
] = sal::static_int_cast
<sal_Int16
>( daysNode
->getNumberOfChildren() );
1587 if (bGregorian
&& nbOfDays
[i
] != 7)
1588 incErrorInt( "A Gregorian calendar must have 7 days per week, this one has %d", nbOfDays
[i
]);
1590 for (j
= 0; j
< nbOfDays
[i
]; j
++) {
1591 LocaleNode
*currNode
= daysNode
-> getChildAt(j
);
1592 OUString
dayID( currNode
->getChildAt(0)->getValue());
1593 of
.writeParameter("dayID", dayID
, i
, j
);
1594 if ( j
== 0 && bGregorian
&& dayID
!= "sun" )
1595 incError( "First day of a week of a Gregorian calendar must be <DayID>sun</DayID>");
1596 lcl_writeAbbrFullNarrNames( of
, currNode
, elementTag
, i
, j
);
1601 // Generate Months of Year
1602 LocaleNode
* monthsNode
= NULL
;
1603 ref_name
= calNode
->getChildAt(nChild
)->getAttr().getValueByName("ref");
1604 if (!ref_name
.isEmpty() && i
> 0) {
1605 for (j
= 0; j
< i
; j
++) {
1606 str
= getChildAt(j
)->getAttr().getValueByName("unoid");
1607 if (str
.equals(ref_name
))
1608 monthsNode
= getChildAt(j
)->getChildAt(1);
1611 if (!ref_name
.isEmpty() && monthsNode
== NULL
) {
1612 of
.writeParameter("monthRef", OUString("ref"), i
);
1613 of
.writeParameter("monthRefName", ref_name
, i
);
1616 if (monthsNode
== NULL
)
1617 monthsNode
= calNode
-> getChildAt(nChild
);
1618 nbOfMonths
[i
] = sal::static_int_cast
<sal_Int16
>( monthsNode
->getNumberOfChildren() );
1619 if (bGregorian
&& nbOfMonths
[i
] != 12)
1620 incErrorInt( "A Gregorian calendar must have 12 months, this one has %d", nbOfMonths
[i
]);
1621 elementTag
= "month";
1622 for (j
= 0; j
< nbOfMonths
[i
]; j
++) {
1623 LocaleNode
*currNode
= monthsNode
-> getChildAt(j
);
1624 OUString
monthID( currNode
->getChildAt(0)->getValue());
1625 of
.writeParameter("monthID", monthID
, i
, j
);
1626 if ( j
== 0 && bGregorian
&& monthID
!= "jan" )
1627 incError( "First month of a year of a Gregorian calendar must be <MonthID>jan</MonthID>");
1628 lcl_writeAbbrFullNarrNames( of
, currNode
, elementTag
, i
, j
);
1633 // Generate genitive Months of Year
1634 // Optional, if not present fall back to month nouns.
1635 if ( calNode
->getChildAt(nChild
)->getName() != "GenitiveMonths" )
1637 LocaleNode
* genitiveMonthsNode
= NULL
;
1638 ref_name
= calNode
->getChildAt(nChild
)->getAttr().getValueByName("ref");
1639 if (!ref_name
.isEmpty() && i
> 0) {
1640 for (j
= 0; j
< i
; j
++) {
1641 str
= getChildAt(j
)->getAttr().getValueByName("unoid");
1642 if (str
.equals(ref_name
))
1643 genitiveMonthsNode
= getChildAt(j
)->getChildAt(1);
1646 if (!ref_name
.isEmpty() && genitiveMonthsNode
== NULL
) {
1647 of
.writeParameter("genitiveMonthRef", OUString("ref"), i
);
1648 of
.writeParameter("genitiveMonthRefName", ref_name
, i
);
1649 nbOfGenitiveMonths
[i
] = 0;
1651 if (genitiveMonthsNode
== NULL
)
1652 genitiveMonthsNode
= calNode
-> getChildAt(nChild
);
1653 nbOfGenitiveMonths
[i
] = sal::static_int_cast
<sal_Int16
>( genitiveMonthsNode
->getNumberOfChildren() );
1654 if (bGregorian
&& nbOfGenitiveMonths
[i
] != 12)
1655 incErrorInt( "A Gregorian calendar must have 12 genitive months, this one has %d", nbOfGenitiveMonths
[i
]);
1656 elementTag
= "genitiveMonth";
1657 for (j
= 0; j
< nbOfGenitiveMonths
[i
]; j
++) {
1658 LocaleNode
*currNode
= genitiveMonthsNode
-> getChildAt(j
);
1659 OUString
genitiveMonthID( currNode
->getChildAt(0)->getValue());
1660 of
.writeParameter("genitiveMonthID", genitiveMonthID
, i
, j
);
1661 if ( j
== 0 && bGregorian
&& genitiveMonthID
!= "jan" )
1662 incError( "First genitive month of a year of a Gregorian calendar must be <MonthID>jan</MonthID>");
1663 lcl_writeAbbrFullNarrNames( of
, currNode
, elementTag
, i
, j
);
1668 // Generate partitive Months of Year
1669 // Optional, if not present fall back to genitive months, or nominative
1670 // months (nouns) if that isn't present either.
1671 if ( calNode
->getChildAt(nChild
)->getName() != "PartitiveMonths" )
1673 LocaleNode
* partitiveMonthsNode
= NULL
;
1674 ref_name
= calNode
->getChildAt(nChild
)->getAttr().getValueByName("ref");
1675 if (!ref_name
.isEmpty() && i
> 0) {
1676 for (j
= 0; j
< i
; j
++) {
1677 str
= getChildAt(j
)->getAttr().getValueByName("unoid");
1678 if (str
.equals(ref_name
))
1679 partitiveMonthsNode
= getChildAt(j
)->getChildAt(1);
1682 if (!ref_name
.isEmpty() && partitiveMonthsNode
== NULL
) {
1683 of
.writeParameter("partitiveMonthRef", OUString("ref"), i
);
1684 of
.writeParameter("partitiveMonthRefName", ref_name
, i
);
1685 nbOfPartitiveMonths
[i
] = 0;
1687 if (partitiveMonthsNode
== NULL
)
1688 partitiveMonthsNode
= calNode
-> getChildAt(nChild
);
1689 nbOfPartitiveMonths
[i
] = sal::static_int_cast
<sal_Int16
>( partitiveMonthsNode
->getNumberOfChildren() );
1690 if (bGregorian
&& nbOfPartitiveMonths
[i
] != 12)
1691 incErrorInt( "A Gregorian calendar must have 12 partitive months, this one has %d", nbOfPartitiveMonths
[i
]);
1692 elementTag
= "partitiveMonth";
1693 for (j
= 0; j
< nbOfPartitiveMonths
[i
]; j
++) {
1694 LocaleNode
*currNode
= partitiveMonthsNode
-> getChildAt(j
);
1695 OUString
partitiveMonthID( currNode
->getChildAt(0)->getValue());
1696 of
.writeParameter("partitiveMonthID", partitiveMonthID
, i
, j
);
1697 if ( j
== 0 && bGregorian
&& partitiveMonthID
!= "jan" )
1698 incError( "First partitive month of a year of a Gregorian calendar must be <MonthID>jan</MonthID>");
1699 lcl_writeAbbrFullNarrNames( of
, currNode
, elementTag
, i
, j
);
1704 // Generate Era name
1705 LocaleNode
* erasNode
= NULL
;
1706 ref_name
= calNode
-> getChildAt(nChild
) ->getAttr().getValueByName("ref");
1707 if (!ref_name
.isEmpty() && i
> 0) {
1708 for (j
= 0; j
< i
; j
++) {
1709 str
= getChildAt(j
)->getAttr().getValueByName("unoid");
1710 if (str
.equals(ref_name
))
1711 erasNode
= getChildAt(j
)->getChildAt(2);
1714 if (!ref_name
.isEmpty() && erasNode
== NULL
) {
1715 of
.writeParameter("eraRef", OUString("ref"), i
);
1716 of
.writeParameter("eraRefName", ref_name
, i
);
1719 if (erasNode
== NULL
)
1720 erasNode
= calNode
-> getChildAt(nChild
);
1721 nbOfEras
[i
] = sal::static_int_cast
<sal_Int16
>( erasNode
->getNumberOfChildren() );
1722 if (bGregorian
&& nbOfEras
[i
] != 2)
1723 incErrorInt( "A Gregorian calendar must have 2 eras, this one has %d", nbOfEras
[i
]);
1725 for (j
= 0; j
< nbOfEras
[i
]; j
++) {
1726 LocaleNode
*currNode
= erasNode
-> getChildAt(j
);
1727 OUString
eraID( currNode
->getChildAt(0)->getValue());
1728 of
.writeParameter("eraID", eraID
, i
, j
);
1729 if ( j
== 0 && bGregorian
&& eraID
!= "bc" )
1730 incError( "First era of a Gregorian calendar must be <EraID>bc</EraID>");
1731 if ( j
== 1 && bGregorian
&& eraID
!= "ad" )
1732 incError( "Second era of a Gregorian calendar must be <EraID>ad</EraID>");
1733 of
.writeAsciiString("\n");
1734 of
.writeParameter(elementTag
, "DefaultAbbrvName",currNode
->getChildAt(1)->getValue() ,i
, j
);
1735 of
.writeParameter(elementTag
, "DefaultFullName",currNode
->getChildAt(2)->getValue() , i
, j
);
1740 str
= calNode
->getChildAt(nChild
)->getChildAt(0)->getValue();
1743 for (j
= 0; j
< nbOfDays
[i
]; j
++)
1745 LocaleNode
*currNode
= daysNode
->getChildAt(j
);
1746 OUString
dayID( currNode
->getChildAt(0)->getValue());
1750 if (j
>= nbOfDays
[i
])
1751 incErrorStr( "<StartDayOfWeek> <DayID> must be one of the <DaysOfWeek>, but is", str
);
1753 of
.writeParameter("startDayOfWeek", str
, i
);
1756 str
= calNode
->getChildAt(nChild
)-> getValue();
1757 sal_Int16 nDays
= sal::static_int_cast
<sal_Int16
>( str
.toInt32() );
1758 if (nDays
< 1 || (0 < nbOfDays
[i
] && nbOfDays
[i
] < nDays
))
1759 incErrorInt( "Bad value of MinimalDaysInFirstWeek: %d, must be 1 <= value <= days_in_week", nDays
);
1760 of
.writeIntParameter("minimalDaysInFirstWeek", i
, nDays
);
1763 fprintf( stderr
, "Warning: %s\n", "No Gregorian calendar defined, are you sure?");
1765 of
.writeAsciiString("static const sal_Int16 calendarsCount = ");
1766 of
.writeInt(nbOfCalendars
);
1767 of
.writeAsciiString(";\n\n");
1769 of
.writeAsciiString("static const sal_Unicode nbOfDays[] = {");
1770 for(i
= 0; i
< nbOfCalendars
- 1; i
++) {
1771 of
.writeInt(nbOfDays
[i
]);
1772 of
.writeAsciiString(", ");
1774 of
.writeInt(nbOfDays
[i
]);
1775 of
.writeAsciiString("};\n");
1777 of
.writeAsciiString("static const sal_Unicode nbOfMonths[] = {");
1778 for(i
= 0; i
< nbOfCalendars
- 1; i
++) {
1779 of
.writeInt(nbOfMonths
[i
]);
1780 of
.writeAsciiString(", ");
1782 of
.writeInt(nbOfMonths
[i
]);
1783 of
.writeAsciiString("};\n");
1785 of
.writeAsciiString("static const sal_Unicode nbOfGenitiveMonths[] = {");
1786 for(i
= 0; i
< nbOfCalendars
- 1; i
++) {
1787 of
.writeInt(nbOfGenitiveMonths
[i
]);
1788 of
.writeAsciiString(", ");
1790 of
.writeInt(nbOfGenitiveMonths
[i
]);
1791 of
.writeAsciiString("};\n");
1793 of
.writeAsciiString("static const sal_Unicode nbOfPartitiveMonths[] = {");
1794 for(i
= 0; i
< nbOfCalendars
- 1; i
++) {
1795 of
.writeInt(nbOfPartitiveMonths
[i
]);
1796 of
.writeAsciiString(", ");
1798 of
.writeInt(nbOfPartitiveMonths
[i
]);
1799 of
.writeAsciiString("};\n");
1801 of
.writeAsciiString("static const sal_Unicode nbOfEras[] = {");
1802 for(i
= 0; i
< nbOfCalendars
- 1; i
++) {
1803 of
.writeInt(nbOfEras
[i
]);
1804 of
.writeAsciiString(", ");
1806 of
.writeInt(nbOfEras
[i
]);
1807 of
.writeAsciiString("};\n");
1810 of
.writeAsciiString("static const sal_Unicode* calendars[] = {\n");
1811 of
.writeAsciiString("\tnbOfDays,\n");
1812 of
.writeAsciiString("\tnbOfMonths,\n");
1813 of
.writeAsciiString("\tnbOfGenitiveMonths,\n");
1814 of
.writeAsciiString("\tnbOfPartitiveMonths,\n");
1815 of
.writeAsciiString("\tnbOfEras,\n");
1816 for(i
= 0; i
< nbOfCalendars
; i
++) {
1817 of
.writeAsciiString("\tcalendarID");
1819 of
.writeAsciiString(",\n");
1820 of
.writeAsciiString("\tdefaultCalendar");
1822 of
.writeAsciiString(",\n");
1823 lcl_writeAbbrFullNarrArrays( of
, nbOfDays
[i
], "day", i
, true);
1824 lcl_writeAbbrFullNarrArrays( of
, nbOfMonths
[i
], "month", i
, true);
1825 lcl_writeAbbrFullNarrArrays( of
, nbOfGenitiveMonths
[i
], "genitiveMonth", i
, true);
1826 lcl_writeAbbrFullNarrArrays( of
, nbOfPartitiveMonths
[i
], "partitiveMonth", i
, true);
1827 lcl_writeAbbrFullNarrArrays( of
, nbOfEras
[i
], "era", i
, false /*noNarrow*/);
1828 of
.writeAsciiString("\tstartDayOfWeek");of
.writeInt(i
); of
.writeAsciiString(",\n");
1829 of
.writeAsciiString("\tminimalDaysInFirstWeek");of
.writeInt(i
); of
.writeAsciiString(",\n");
1832 of
.writeAsciiString("};\n\n");
1833 of
.writeFunction("getAllCalendars_", "calendarsCount", "calendars");
1836 delete []nbOfMonths
;
1837 delete []nbOfGenitiveMonths
;
1838 delete []nbOfPartitiveMonths
;
1842 bool isIso4217( const OUString
& rStr
)
1844 const sal_Unicode
* p
= rStr
.getStr();
1845 return rStr
.getLength() == 3
1846 && 'A' <= p
[0] && p
[0] <= 'Z'
1847 && 'A' <= p
[1] && p
[1] <= 'Z'
1848 && 'A' <= p
[2] && p
[2] <= 'Z'
1852 void LCCurrencyNode :: generateCode (const OFileWriter
&of
) const
1854 ::rtl::OUString useLocale
= getAttr().getValueByName("ref");
1855 if (!useLocale
.isEmpty()) {
1856 of
.writeRefFunction("getAllCurrencies_", useLocale
);
1859 sal_Int16 nbOfCurrencies
= 0;
1860 ::rtl::OUString str
;
1863 bool bTheDefault
= false;
1864 bool bTheCompatible
= false;
1865 for ( i
= 0; i
< getNumberOfChildren(); i
++,nbOfCurrencies
++) {
1866 LocaleNode
* currencyNode
= getChildAt (i
);
1867 str
= currencyNode
->getAttr().getValueByName("default");
1868 bool bDefault
= of
.writeDefaultParameter("Currency", str
, nbOfCurrencies
);
1869 str
= currencyNode
->getAttr().getValueByName("usedInCompatibleFormatCodes");
1870 bool bCompatible
= of
.writeDefaultParameter("CurrencyUsedInCompatibleFormatCodes", str
, nbOfCurrencies
);
1871 str
= currencyNode
->getAttr().getValueByName("legacyOnly");
1872 bool bLegacy
= of
.writeDefaultParameter("CurrencyLegacyOnly", str
, nbOfCurrencies
);
1873 if (bLegacy
&& (bDefault
|| bCompatible
))
1874 incError( "Currency: if legacyOnly==true, both 'default' and 'usedInCompatibleFormatCodes' must be false.");
1878 incError( "Currency: more than one default currency.");
1884 incError( "Currency: more than one currency flagged as usedInCompatibleFormatCodes.");
1885 bTheCompatible
= true;
1887 str
= currencyNode
-> findNode ("CurrencyID") -> getValue();
1888 of
.writeParameter("currencyID", str
, nbOfCurrencies
);
1889 // CurrencyID MUST be ISO 4217.
1890 if (!bLegacy
&& !isIso4217(str
))
1891 incError( "CurrencyID is not ISO 4217");
1892 str
= currencyNode
-> findNode ("CurrencySymbol") -> getValue();
1893 of
.writeParameter("currencySymbol", str
, nbOfCurrencies
);
1894 // Check if this currency really is the one used in number format
1895 // codes. In case of ref=... mechanisms it may be that TheCurrency
1896 // couldn't had been determined from the current locale (i.e. is
1897 // empty), silently assume the referred locale has things right.
1898 if (bCompatible
&& !sTheCompatibleCurrency
.isEmpty() && sTheCompatibleCurrency
!= str
)
1899 incErrorStrStr( "CurrencySymbol \"%s\" flagged as usedInCompatibleFormatCodes doesn't match \"%s\" determined from format codes.", str
, sTheCompatibleCurrency
);
1900 str
= currencyNode
-> findNode ("BankSymbol") -> getValue();
1901 of
.writeParameter("bankSymbol", str
, nbOfCurrencies
);
1902 // BankSymbol currently must be ISO 4217. May change later if
1903 // application always uses CurrencyID instead of BankSymbol.
1904 if (!bLegacy
&& !isIso4217(str
))
1905 incError( "BankSymbol is not ISO 4217");
1906 str
= currencyNode
-> findNode ("CurrencyName") -> getValue();
1907 of
.writeParameter("currencyName", str
, nbOfCurrencies
);
1908 str
= currencyNode
-> findNode ("DecimalPlaces") -> getValue();
1909 sal_Int16 nDecimalPlaces
= (sal_Int16
)str
.toInt32();
1910 of
.writeIntParameter("currencyDecimalPlaces", nbOfCurrencies
, nDecimalPlaces
);
1911 of
.writeAsciiString("\n");
1915 incError( "Currency: no default currency.");
1916 if (!bTheCompatible
)
1917 incError( "Currency: no currency flagged as usedInCompatibleFormatCodes.");
1919 of
.writeAsciiString("static const sal_Int16 currencyCount = ");
1920 of
.writeInt(nbOfCurrencies
);
1921 of
.writeAsciiString(";\n\n");
1922 of
.writeAsciiString("static const sal_Unicode* currencies[] = {\n");
1923 for(i
= 0; i
< nbOfCurrencies
; i
++) {
1924 of
.writeAsciiString("\tcurrencyID");
1926 of
.writeAsciiString(",\n");
1927 of
.writeAsciiString("\tcurrencySymbol");
1929 of
.writeAsciiString(",\n");
1930 of
.writeAsciiString("\tbankSymbol");
1932 of
.writeAsciiString(",\n");
1933 of
.writeAsciiString("\tcurrencyName");
1935 of
.writeAsciiString(",\n");
1936 of
.writeAsciiString("\tdefaultCurrency");
1938 of
.writeAsciiString(",\n");
1939 of
.writeAsciiString("\tdefaultCurrencyUsedInCompatibleFormatCodes");
1941 of
.writeAsciiString(",\n");
1942 of
.writeAsciiString("\tcurrencyDecimalPlaces");
1944 of
.writeAsciiString(",\n");
1945 of
.writeAsciiString("\tdefaultCurrencyLegacyOnly");
1947 of
.writeAsciiString(",\n");
1949 of
.writeAsciiString("};\n\n");
1950 of
.writeFunction("getAllCurrencies_", "currencyCount", "currencies");
1953 void LCTransliterationNode::generateCode (const OFileWriter
&of
) const
1955 ::rtl::OUString useLocale
= getAttr().getValueByName("ref");
1956 if (!useLocale
.isEmpty()) {
1957 of
.writeRefFunction("getTransliterations_", useLocale
);
1960 sal_Int16 nbOfModules
= 0;
1961 ::rtl::OUString str
;
1964 for ( i
= 0; i
< getNumberOfChildren(); i
++,nbOfModules
++) {
1965 LocaleNode
* transNode
= getChildAt (i
);
1966 str
= transNode
->getAttr().getValueByIndex(0);
1967 of
.writeParameter("Transliteration", str
, nbOfModules
);
1969 of
.writeAsciiString("static const sal_Int16 nbOfTransliterations = ");
1970 of
.writeInt(nbOfModules
);
1971 of
.writeAsciiString(";\n\n");
1973 of
.writeAsciiString("\nstatic const sal_Unicode* LCTransliterationsArray[] = {\n");
1974 for( i
= 0; i
< nbOfModules
; i
++) {
1975 of
.writeAsciiString("\tTransliteration");
1977 of
.writeAsciiString(",\n");
1979 of
.writeAsciiString("};\n\n");
1980 of
.writeFunction("getTransliterations_", "nbOfTransliterations", "LCTransliterationsArray");
1983 struct NameValuePair
{
1984 const sal_Char
*name
;
1985 const sal_Char
*value
;
1987 static NameValuePair ReserveWord
[] = {
1988 { "trueWord", "true" },
1989 { "falseWord", "false" },
1990 { "quarter1Word", "1st quarter" },
1991 { "quarter2Word", "2nd quarter" },
1992 { "quarter3Word", "3rd quarter" },
1993 { "quarter4Word", "4th quarter" },
1994 { "aboveWord", "above" },
1995 { "belowWord", "below" },
1996 { "quarter1Abbreviation", "Q1" },
1997 { "quarter2Abbreviation", "Q2" },
1998 { "quarter3Abbreviation", "Q3" },
1999 { "quarter4Abbreviation", "Q4" }
2002 void LCMiscNode::generateCode (const OFileWriter
&of
) const
2004 ::rtl::OUString useLocale
= getAttr().getValueByName("ref");
2005 if (!useLocale
.isEmpty()) {
2006 of
.writeRefFunction("getForbiddenCharacters_", useLocale
);
2007 of
.writeRefFunction("getBreakIteratorRules_", useLocale
);
2008 of
.writeRefFunction("getReservedWords_", useLocale
);
2011 const LocaleNode
* reserveNode
= findNode("ReservedWords");
2013 incError( "No ReservedWords element."); // should not happen if validated..
2014 const LocaleNode
* forbidNode
= findNode("ForbiddenCharacters");
2015 const LocaleNode
* breakNode
= findNode("BreakIteratorRules");
2017 bool bEnglishLocale
= (strncmp( of
.getLocale(), "en_", 3) == 0);
2019 sal_Int16 nbOfWords
= 0;
2020 ::rtl::OUString str
;
2023 for ( i
= 0; i
< sal_Int16(SAL_N_ELEMENTS(ReserveWord
)); i
++,nbOfWords
++) {
2024 const LocaleNode
* curNode
= (reserveNode
? reserveNode
->findNode(
2025 ReserveWord
[i
].name
) : 0);
2028 "Warning: No %s in ReservedWords, using en_US default: \"%s\".\n",
2029 ReserveWord
[i
].name
, ReserveWord
[i
].value
);
2030 str
= curNode
? curNode
-> getValue() : OUString::createFromAscii(ReserveWord
[i
].value
);
2034 fprintf( stderr
, "Error: No content for ReservedWords %s.\n", ReserveWord
[i
].name
);
2036 of
.writeParameter("ReservedWord", str
, nbOfWords
);
2037 // "true", ..., "below" trigger untranslated warning.
2038 if (!bEnglishLocale
&& curNode
&& (0 <= i
&& i
<= 7) &&
2039 str
.equalsIgnoreAsciiCaseAscii( ReserveWord
[i
].value
))
2042 "Warning: ReservedWord %s seems to be untranslated \"%s\".\n",
2043 ReserveWord
[i
].name
, ReserveWord
[i
].value
);
2046 of
.writeAsciiString("static const sal_Int16 nbOfReservedWords = ");
2047 of
.writeInt(nbOfWords
);
2048 of
.writeAsciiString(";\n\n");
2049 of
.writeAsciiString("\nstatic const sal_Unicode* LCReservedWordsArray[] = {\n");
2050 for( i
= 0; i
< nbOfWords
; i
++) {
2051 of
.writeAsciiString("\tReservedWord");
2053 of
.writeAsciiString(",\n");
2055 of
.writeAsciiString("};\n\n");
2056 of
.writeFunction("getReservedWords_", "nbOfReservedWords", "LCReservedWordsArray");
2059 of
.writeParameter( "forbiddenBegin", forbidNode
-> getChildAt(0)->getValue());
2060 of
.writeParameter( "forbiddenEnd", forbidNode
-> getChildAt(1)->getValue());
2061 of
.writeParameter( "hangingChars", forbidNode
-> getChildAt(2)->getValue());
2063 of
.writeParameter( "forbiddenBegin", ::rtl::OUString());
2064 of
.writeParameter( "forbiddenEnd", ::rtl::OUString());
2065 of
.writeParameter( "hangingChars", ::rtl::OUString());
2067 of
.writeAsciiString("\nstatic const sal_Unicode* LCForbiddenCharactersArray[] = {\n");
2068 of
.writeAsciiString("\tforbiddenBegin,\n");
2069 of
.writeAsciiString("\tforbiddenEnd,\n");
2070 of
.writeAsciiString("\thangingChars\n");
2071 of
.writeAsciiString("};\n\n");
2072 of
.writeFunction("getForbiddenCharacters_", "3", "LCForbiddenCharactersArray");
2075 of
.writeParameter( "EditMode", breakNode
-> getChildAt(0)->getValue());
2076 of
.writeParameter( "DictionaryMode", breakNode
-> getChildAt(1)->getValue());
2077 of
.writeParameter( "WordCountMode", breakNode
-> getChildAt(2)->getValue());
2078 of
.writeParameter( "CharacterMode", breakNode
-> getChildAt(3)->getValue());
2079 of
.writeParameter( "LineMode", breakNode
-> getChildAt(4)->getValue());
2081 of
.writeParameter( "EditMode", ::rtl::OUString());
2082 of
.writeParameter( "DictionaryMode", ::rtl::OUString());
2083 of
.writeParameter( "WordCountMode", ::rtl::OUString());
2084 of
.writeParameter( "CharacterMode", ::rtl::OUString());
2085 of
.writeParameter( "LineMode", ::rtl::OUString());
2087 of
.writeAsciiString("\nstatic const sal_Unicode* LCBreakIteratorRulesArray[] = {\n");
2088 of
.writeAsciiString("\tEditMode,\n");
2089 of
.writeAsciiString("\tDictionaryMode,\n");
2090 of
.writeAsciiString("\tWordCountMode,\n");
2091 of
.writeAsciiString("\tCharacterMode,\n");
2092 of
.writeAsciiString("\tLineMode\n");
2093 of
.writeAsciiString("};\n\n");
2094 of
.writeFunction("getBreakIteratorRules_", "5", "LCBreakIteratorRulesArray");
2098 void LCNumberingLevelNode::generateCode (const OFileWriter
&of
) const
2100 of
.writeAsciiString("// ---> ContinuousNumbering\n");
2101 ::rtl::OUString useLocale
= getAttr().getValueByName("ref");
2102 if (!useLocale
.isEmpty()) {
2103 of
.writeRefFunction2("getContinuousNumberingLevels_", useLocale
);
2107 // hard code number of attributes per style.
2108 const int nAttributes
= 5;
2109 const char* attr
[ nAttributes
] = { "Prefix", "NumType", "Suffix", "Transliteration", "NatNum" };
2111 // record each attribute of each style in a static C++ variable.
2112 // determine number of styles on the fly.
2113 sal_Int32 nStyles
= getNumberOfChildren();
2116 for( i
= 0; i
< nStyles
; ++i
)
2118 const Attr
&q
= getChildAt( i
)->getAttr();
2119 for( sal_Int32 j
=0; j
<nAttributes
; ++j
)
2121 const char* name
= attr
[j
];
2122 OUString value
= q
.getValueByName( name
);
2123 of
.writeParameter("continuous", name
, value
, sal::static_int_cast
<sal_Int16
>(i
) );
2127 // record number of styles and attributes.
2128 of
.writeAsciiString("static const sal_Int16 continuousNbOfStyles = ");
2129 of
.writeInt( sal::static_int_cast
<sal_Int16
>( nStyles
) );
2130 of
.writeAsciiString(";\n\n");
2131 of
.writeAsciiString("static const sal_Int16 continuousNbOfAttributesPerStyle = ");
2132 of
.writeInt( nAttributes
);
2133 of
.writeAsciiString(";\n\n");
2135 // generate code. (intermediate arrays)
2136 for( i
=0; i
<nStyles
; i
++ )
2138 of
.writeAsciiString("\nstatic const sal_Unicode* continuousStyle" );
2139 of
.writeInt( sal::static_int_cast
<sal_Int16
>(i
) );
2140 of
.writeAsciiString("[] = {\n");
2141 for( sal_Int32 j
=0; j
<nAttributes
; j
++)
2143 of
.writeAsciiString("\t");
2144 of
.writeAsciiString( "continuous" );
2145 of
.writeAsciiString( attr
[j
] );
2146 of
.writeInt(sal::static_int_cast
<sal_Int16
>(i
));
2147 of
.writeAsciiString(",\n");
2149 of
.writeAsciiString("\t0\n};\n\n");
2152 // generate code. (top-level array)
2153 of
.writeAsciiString("\n");
2154 of
.writeAsciiString("static const sal_Unicode** LCContinuousNumberingLevelsArray[] = {\n" );
2155 for( i
=0; i
<nStyles
; i
++ )
2157 of
.writeAsciiString( "\t" );
2158 of
.writeAsciiString( "continuousStyle" );
2159 of
.writeInt( sal::static_int_cast
<sal_Int16
>(i
) );
2160 of
.writeAsciiString( ",\n");
2162 of
.writeAsciiString("\t0\n};\n\n");
2163 of
.writeFunction2("getContinuousNumberingLevels_", "continuousNbOfStyles",
2164 "continuousNbOfAttributesPerStyle", "LCContinuousNumberingLevelsArray");
2168 void LCOutlineNumberingLevelNode::generateCode (const OFileWriter
&of
) const
2170 of
.writeAsciiString("// ---> OutlineNumbering\n");
2171 ::rtl::OUString useLocale
= getAttr().getValueByName("ref");
2172 if (!useLocale
.isEmpty()) {
2173 of
.writeRefFunction3("getOutlineNumberingLevels_", useLocale
);
2177 // hardcode number of attributes per level
2178 const int nAttributes
= 11;
2179 const char* attr
[ nAttributes
] =
2188 "SymbolTextDistance",
2194 // record each attribute of each level of each style in a static C++ variable.
2195 // determine number of styles and number of levels per style on the fly.
2196 sal_Int32 nStyles
= getNumberOfChildren();
2197 vector
<sal_Int32
> nLevels
; // may be different for each style?
2198 for( sal_Int32 i
= 0; i
< nStyles
; i
++ )
2200 LocaleNode
* p
= getChildAt( i
);
2201 nLevels
.push_back( p
->getNumberOfChildren() );
2202 for( sal_Int32 j
=0; j
<nLevels
.back(); j
++ )
2204 const Attr
& q
= p
->getChildAt( j
)->getAttr();
2205 for( sal_Int32 k
=0; k
<nAttributes
; ++k
)
2207 const char* name
= attr
[k
];
2208 OUString value
= q
.getValueByName( name
);
2209 of
.writeParameter("outline", name
, value
,
2210 sal::static_int_cast
<sal_Int16
>(i
),
2211 sal::static_int_cast
<sal_Int16
>(j
) );
2216 // verify that each style has the same number of levels.
2217 for( size_t i
=0; i
<nLevels
.size(); i
++ )
2219 if( nLevels
[0] != nLevels
[i
] )
2221 incError( "Numbering levels don't match.");
2225 // record number of attributes, levels, and styles.
2226 of
.writeAsciiString("static const sal_Int16 outlineNbOfStyles = ");
2227 of
.writeInt( sal::static_int_cast
<sal_Int16
>( nStyles
) );
2228 of
.writeAsciiString(";\n\n");
2229 of
.writeAsciiString("static const sal_Int16 outlineNbOfLevelsPerStyle = ");
2230 of
.writeInt( sal::static_int_cast
<sal_Int16
>( nLevels
.back() ) );
2231 of
.writeAsciiString(";\n\n");
2232 of
.writeAsciiString("static const sal_Int16 outlineNbOfAttributesPerLevel = ");
2233 of
.writeInt( nAttributes
);
2234 of
.writeAsciiString(";\n\n");
2236 // too complicated for now...
2237 // of.writeAsciiString("static const sal_Int16 nbOfOutlineNumberingLevels[] = { ");
2238 // for( sal_Int32 j=0; j<nStyles; j++ )
2240 // of.writeInt( nLevels[j] );
2241 // of.writeAsciiString(", ");
2243 // of.writeAsciiString("};\n\n");
2246 for( sal_Int32 i
=0; i
<nStyles
; i
++ )
2248 for( sal_Int32 j
=0; j
<nLevels
.back(); j
++ )
2250 of
.writeAsciiString("static const sal_Unicode* outline");
2251 of
.writeAsciiString("Style");
2252 of
.writeInt( sal::static_int_cast
<sal_Int16
>(i
) );
2253 of
.writeAsciiString("Level");
2254 of
.writeInt( sal::static_int_cast
<sal_Int16
>(j
) );
2255 of
.writeAsciiString("[] = { ");
2257 for( sal_Int32 k
=0; k
<nAttributes
; k
++ )
2259 of
.writeAsciiString( "outline" );
2260 of
.writeAsciiString( attr
[k
] );
2261 of
.writeInt( sal::static_int_cast
<sal_Int16
>(i
) );
2262 of
.writeInt( sal::static_int_cast
<sal_Int16
>(j
) );
2263 of
.writeAsciiString(", ");
2265 of
.writeAsciiString("NULL };\n");
2269 of
.writeAsciiString("\n");
2272 for( sal_Int32 i
=0; i
<nStyles
; i
++ )
2274 of
.writeAsciiString("static const sal_Unicode** outline");
2275 of
.writeAsciiString( "Style" );
2276 of
.writeInt( sal::static_int_cast
<sal_Int16
>(i
) );
2277 of
.writeAsciiString("[] = { ");
2279 for( sal_Int32 j
=0; j
<nLevels
.back(); j
++ )
2281 of
.writeAsciiString("outlineStyle");
2282 of
.writeInt( sal::static_int_cast
<sal_Int16
>(i
) );
2283 of
.writeAsciiString("Level");
2284 of
.writeInt( sal::static_int_cast
<sal_Int16
>(j
) );
2285 of
.writeAsciiString(", ");
2287 of
.writeAsciiString("NULL };\n");
2289 of
.writeAsciiString("\n");
2291 of
.writeAsciiString("static const sal_Unicode*** LCOutlineNumberingLevelsArray[] = {\n" );
2292 for( sal_Int32 i
=0; i
<nStyles
; i
++ )
2294 of
.writeAsciiString( "\t" );
2295 of
.writeAsciiString( "outlineStyle" );
2296 of
.writeInt( sal::static_int_cast
<sal_Int16
>(i
) );
2297 of
.writeAsciiString(",\n");
2299 of
.writeAsciiString("\tNULL\n};\n\n");
2300 of
.writeFunction3("getOutlineNumberingLevels_", "outlineNbOfStyles", "outlineNbOfLevelsPerStyle",
2301 "outlineNbOfAttributesPerLevel", "LCOutlineNumberingLevelsArray");
2304 Attr::Attr (const Reference
< XAttributeList
> & attr
) {
2305 sal_Int16 len
= attr
->getLength();
2307 value
.realloc (len
);
2308 for (sal_Int16 i
=0; i
< len
;i
++) {
2309 name
[i
] = attr
->getNameByIndex(i
);
2310 value
[i
] = attr
-> getValueByIndex(i
);
2314 const OUString
& Attr::getValueByName (const sal_Char
*str
) const {
2315 static OUString empty
;
2316 sal_Int32 len
= name
.getLength();
2317 for (sal_Int32 i
= 0;i
<len
;i
++)
2318 if (name
[i
].equalsAscii(str
))
2323 sal_Int32
Attr::getLength() const{
2324 return name
.getLength();
2327 const OUString
& Attr::getTypeByIndex (sal_Int32 idx
) const {
2331 const OUString
& Attr::getValueByIndex (sal_Int32 idx
) const
2336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */