bump product version to 6.3.0.0.beta1
[LibreOffice.git] / i18npool / source / localedata / LocaleNode.cxx
blobc79c2dae88bfd4db0825fda82250130cfa5e4514
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 <string.h>
22 #include <algorithm>
23 #include <memory>
24 #include <set>
25 #include <vector>
27 #include <rtl/ustrbuf.hxx>
28 #include <sal/macros.h>
30 #include "LocaleNode.hxx"
31 #include <com/sun/star/i18n/NumberFormatIndex.hpp>
32 #include <com/sun/star/xml/sax/XAttributeList.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(nullptr)
46 , nError(0)
50 int LocaleNode::getError() const
52 int err = nError;
53 for (size_t i=0;i<children.size();i++)
54 err += children[i]->getError();
55 return err;
58 void LocaleNode::addChild ( LocaleNode * node) {
59 children.emplace_back(node);
60 node->parent = this;
63 const LocaleNode* LocaleNode::getRoot() const
65 const LocaleNode* pRoot = nullptr;
66 const LocaleNode* pParent = this;
67 while ( (pParent = pParent->parent) != nullptr )
68 pRoot = pParent;
69 return pRoot;
72 const LocaleNode * LocaleNode::findNode ( const sal_Char *name) const {
73 if (aName.equalsAscii(name))
74 return this;
75 for (size_t i = 0; i< children.size(); i++) {
76 const LocaleNode *n=children[i]->findNode(name);
77 if (n)
78 return n;
80 return nullptr;
83 LocaleNode::~LocaleNode()
87 LocaleNode* LocaleNode::createNode (const OUString& name, const Reference< XAttributeList > & attr)
89 if ( name == "LC_INFO" )
90 return new LCInfoNode (name,attr);
91 if ( name == "LC_CTYPE" )
92 return new LCCTYPENode (name,attr);
93 if ( name == "LC_FORMAT" )
94 return new LCFormatNode (name,attr);
95 if ( name == "LC_FORMAT_1" )
96 return new LCFormatNode (name,attr);
97 if ( name == "LC_CALENDAR" )
98 return new LCCalendarNode (name,attr);
99 if ( name == "LC_CURRENCY" )
100 return new LCCurrencyNode (name,attr);
101 if ( name == "LC_TRANSLITERATION" )
102 return new LCTransliterationNode (name,attr);
103 if ( name == "LC_COLLATION" )
104 return new LCCollationNode (name,attr);
105 if ( name == "LC_INDEX" )
106 return new LCIndexNode (name,attr);
107 if ( name == "LC_SEARCH" )
108 return new LCSearchNode (name,attr);
109 if ( name == "LC_MISC" )
110 return new LCMiscNode (name,attr);
111 if ( name == "LC_NumberingLevel" )
112 return new LCNumberingLevelNode (name, attr);
113 if ( name == "LC_OutLineNumberingLevel" )
114 return new LCOutlineNumberingLevelNode (name, attr);
116 return new LocaleNode(name,attr);
120 // printf(" name: '%s'\n", p->getName().pData->buffer );
121 // printf("value: '%s'\n", p->getValue().pData->buffer );
123 #define OSTR(s) (OUStringToOString( (s), RTL_TEXTENCODING_UTF8).getStr())
125 void LocaleNode::generateCode (const OFileWriter &of) const
127 OUString aDTD = getAttr().getValueByName("versionDTD");
128 if ( aDTD != LOCALE_VERSION_DTD )
130 ++nError;
131 fprintf( stderr, "Error: Locale versionDTD is not %s, see comment in locale.dtd\n", LOCALE_VERSION_DTD);
133 for (size_t i=0; i<children.size(); i++)
134 children[i]->generateCode (of);
135 // print_node( this );
139 OUString LocaleNode::writeParameterCheckLen( const OFileWriter &of,
140 const char* pParameterName, const LocaleNode* pNode,
141 sal_Int32 nMinLen, sal_Int32 nMaxLen ) const
143 OUString aVal;
144 if (pNode)
145 aVal = pNode->getValue();
146 else if (nMinLen >= 0) // -1: optional => empty, 0: must be present, empty
148 ++nError;
149 fprintf( stderr, "Error: node NULL pointer for parameter %s.\n",
150 pParameterName);
152 // write empty data if error
153 of.writeParameter( pParameterName, aVal);
154 sal_Int32 nLen = aVal.getLength();
155 if (nLen < nMinLen)
157 ++nError;
158 fprintf( stderr, "Error: less than %ld character%s (%ld) in %s '%s'.\n",
159 sal::static_int_cast< long >(nMinLen), (nMinLen > 1 ? "s" : ""),
160 sal::static_int_cast< long >(nLen),
161 (pNode ? OSTR( pNode->getName()) : ""),
162 OSTR( aVal));
164 else if (nLen > nMaxLen && nMaxLen >= 0)
166 ++nError;
167 fprintf( stderr,
168 "Error: more than %ld character%s (%ld) in %s '%s' not supported by application.\n",
169 sal::static_int_cast< long >(nMaxLen), (nMaxLen > 1 ? "s" : ""),
170 sal::static_int_cast< long >(nLen),
171 (pNode ? OSTR( pNode->getName()) : ""),
172 OSTR( aVal));
174 return aVal;
178 OUString LocaleNode::writeParameterCheckLen( const OFileWriter &of,
179 const char* pNodeName, const char* pParameterName,
180 sal_Int32 nMinLen, sal_Int32 nMaxLen ) const
182 OUString aVal;
183 const LocaleNode * pNode = findNode( pNodeName);
184 if (pNode || nMinLen < 0)
185 aVal = writeParameterCheckLen( of, pParameterName, pNode, nMinLen, nMaxLen);
186 else
188 ++nError;
189 fprintf( stderr, "Error: node %s not found.\n", pNodeName);
190 // write empty data if error
191 of.writeParameter( pParameterName, aVal);
193 return aVal;
196 void LocaleNode::incError( const char* pStr ) const
198 ++nError;
199 fprintf( stderr, "Error: %s\n", pStr);
202 void LocaleNode::incError( const OUString& rStr ) const
204 incError( OSTR( rStr));
207 void LocaleNode::incErrorInt( const char* pStr, int nVal ) const
209 ++nError;
210 fprintf( stderr, pStr, nVal);
213 void LocaleNode::incErrorStr( const char* pStr, const OUString& rVal ) const
215 ++nError;
216 fprintf( stderr, pStr, OSTR( rVal));
219 void LocaleNode::incErrorStrStr( const char* pStr, const OUString& rVal1, const OUString& rVal2 ) const
221 ++nError;
222 fprintf(stderr, pStr, OSTR(rVal1), OSTR(rVal2));
225 void LCInfoNode::generateCode (const OFileWriter &of) const
228 const LocaleNode * languageNode = findNode("Language");
229 const LocaleNode * countryNode = findNode("Country");
230 const LocaleNode * variantNode = findNode("Variant");
232 OUString aLanguage;
234 if (languageNode)
236 aLanguage = languageNode->getChildAt(0)->getValue();
237 if (!(aLanguage.getLength() == 2 || aLanguage.getLength() == 3))
238 incErrorStr( "Error: langID '%s' not 2-3 characters\n", aLanguage);
239 of.writeParameter("langID", aLanguage);
240 of.writeParameter("langDefaultName", languageNode->getChildAt(1)->getValue());
242 else
243 incError( "No Language node.");
244 if (countryNode)
246 OUString aCountry( countryNode->getChildAt(0)->getValue());
247 if (!(aCountry.isEmpty() || aCountry.getLength() == 2))
248 incErrorStr( "Error: countryID '%s' not empty or more than 2 characters\n", aCountry);
249 of.writeParameter("countryID", aCountry);
250 of.writeParameter("countryDefaultName", countryNode->getChildAt(1)->getValue());
252 else
253 incError( "No Country node.");
254 if (variantNode)
256 // If given Variant must be at least ll-Ssss and language must be 'qlt'
257 const OUString& aVariant( variantNode->getValue());
258 if (!(aVariant.isEmpty() || (aVariant.getLength() >= 7 && aVariant.indexOf('-') >= 2)))
259 incErrorStr( "Error: invalid Variant '%s'\n", aVariant);
260 if (!(aVariant.isEmpty() || aLanguage == "qlt"))
261 incErrorStrStr( "Error: Variant '%s' given but Language '%s' is not 'qlt'\n", aVariant, aLanguage);
262 of.writeParameter("Variant", aVariant);
264 else
265 of.writeParameter("Variant", OUString());
266 of.writeAsciiString("\nstatic const sal_Unicode* LCInfoArray[] = {\n");
267 of.writeAsciiString("\tlangID,\n");
268 of.writeAsciiString("\tlangDefaultName,\n");
269 of.writeAsciiString("\tcountryID,\n");
270 of.writeAsciiString("\tcountryDefaultName,\n");
271 of.writeAsciiString("\tVariant\n");
272 of.writeAsciiString("};\n\n");
273 of.writeFunction("getLCInfo_", "SAL_N_ELEMENTS(LCInfoArray)", "LCInfoArray");
277 static OUString aDateSep;
278 static OUString aDecSep;
280 void LCCTYPENode::generateCode (const OFileWriter &of) const
282 const LocaleNode * sepNode = nullptr;
283 OUString useLocale = getAttr().getValueByName("ref");
284 if (!useLocale.isEmpty()) {
285 useLocale = useLocale.replace( '-', '_');
286 of.writeRefFunction("getLocaleItem_", useLocale);
287 return;
289 OUString str = getAttr().getValueByName("unoid");
290 of.writeAsciiString("\n\n");
291 of.writeParameter("LC_CTYPE_Unoid", str);
293 aDateSep =
294 writeParameterCheckLen( of, "DateSeparator", "dateSeparator", 1, 1);
295 OUString aThoSep =
296 writeParameterCheckLen( of, "ThousandSeparator", "thousandSeparator", 1, 1);
297 aDecSep =
298 writeParameterCheckLen( of, "DecimalSeparator", "decimalSeparator", 1, 1);
299 OUString aDecSepAlt =
300 writeParameterCheckLen( of, "DecimalSeparatorAlternative", "decimalSeparatorAlternative", -1, 1);
301 OUString aTimeSep =
302 writeParameterCheckLen( of, "TimeSeparator", "timeSeparator", 1, 1);
303 OUString aTime100Sep =
304 writeParameterCheckLen( of, "Time100SecSeparator", "time100SecSeparator", 1, 1);
305 OUString aListSep =
306 writeParameterCheckLen( of, "ListSeparator", "listSeparator", 1, 1);
308 OUString aLDS;
310 sepNode = findNode("LongDateDayOfWeekSeparator");
311 aLDS = sepNode->getValue();
312 of.writeParameter("LongDateDayOfWeekSeparator", aLDS);
313 if (aLDS == ",")
314 fprintf( stderr, "Warning: %s\n",
315 "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\".");
317 sepNode = findNode("LongDateDaySeparator");
318 aLDS = sepNode->getValue();
319 of.writeParameter("LongDateDaySeparator", aLDS);
320 if (aLDS == "," || aLDS == ".")
321 fprintf( stderr, "Warning: %s\n",
322 "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\".");
324 sepNode = findNode("LongDateMonthSeparator");
325 aLDS = sepNode->getValue();
326 of.writeParameter("LongDateMonthSeparator", aLDS);
327 if (aLDS.isEmpty())
328 fprintf( stderr, "Warning: %s\n",
329 "LongDateMonthSeparator is empty. Usually this is not the case and may lead to concatenated display names like \"Wednesday, May9, 2007\".");
331 sepNode = findNode("LongDateYearSeparator");
332 aLDS = sepNode->getValue();
333 of.writeParameter("LongDateYearSeparator", aLDS);
334 if (aLDS.isEmpty())
335 fprintf( stderr, "Warning: %s\n",
336 "LongDateYearSeparator is empty. Usually this is not the case and may lead to concatenated display names like \"Wednesday, 2007May 9\".");
338 int nSavErr = nError;
339 int nWarn = 0;
340 if (aDateSep == aTimeSep)
341 incError( "DateSeparator equals TimeSeparator.");
342 if (aDecSep == aThoSep)
343 incError( "DecimalSeparator equals ThousandSeparator.");
344 if (aDecSepAlt == aThoSep)
345 incError( "DecimalSeparatorAlternative equals ThousandSeparator.");
346 if (aDecSepAlt == aDecSep)
347 incError( "DecimalSeparatorAlternative equals DecimalSeparator, it must not be specified then.");
348 if ( aThoSep == " " )
349 incError( "ThousandSeparator is an ' ' ordinary space, this should be a non-breaking space U+00A0 instead.");
350 if (aListSep == aDecSep)
351 fprintf( stderr, "Warning: %s\n",
352 "ListSeparator equals DecimalSeparator.");
353 if (aListSep == aThoSep)
354 fprintf( stderr, "Warning: %s\n",
355 "ListSeparator equals ThousandSeparator.");
356 if (aListSep.getLength() != 1 || aListSep[0] != ';')
358 incError( "ListSeparator not ';' semicolon. Strongly recommended. Currently required.");
359 ++nSavErr; // format codes not affected
361 if (aTimeSep == aTime100Sep)
363 ++nWarn;
364 fprintf( stderr, "Warning: %s\n",
365 "Time100SecSeparator equals TimeSeparator, this is probably an error.");
367 if (aDecSep != aTime100Sep)
369 ++nWarn;
370 fprintf( stderr, "Warning: %s\n",
371 "Time100SecSeparator is different from DecimalSeparator, this may be correct or not. Intended?");
373 if (nSavErr != nError || nWarn)
374 fprintf( stderr, "Warning: %s\n",
375 "Don't forget to adapt corresponding FormatCode elements when changing separators.");
377 OUString aQuoteStart =
378 writeParameterCheckLen( of, "QuotationStart", "quotationStart", 1, 1);
379 OUString aQuoteEnd =
380 writeParameterCheckLen( of, "QuotationEnd", "quotationEnd", 1, 1);
381 OUString aDoubleQuoteStart =
382 writeParameterCheckLen( of, "DoubleQuotationStart", "doubleQuotationStart", 1, 1);
383 OUString aDoubleQuoteEnd =
384 writeParameterCheckLen( of, "DoubleQuotationEnd", "doubleQuotationEnd", 1, 1);
386 if (aQuoteStart.toChar() <= 127 && aQuoteEnd.toChar() > 127)
387 fprintf( stderr, "Warning: %s\n",
388 "QuotationStart is an ASCII character but QuotationEnd is not.");
389 if (aQuoteEnd.toChar() <= 127 && aQuoteStart.toChar() > 127)
390 fprintf( stderr, "Warning: %s\n",
391 "QuotationEnd is an ASCII character but QuotationStart is not.");
392 if (aDoubleQuoteStart.toChar() <= 127 && aDoubleQuoteEnd.toChar() > 127)
393 fprintf( stderr, "Warning: %s\n",
394 "DoubleQuotationStart is an ASCII character but DoubleQuotationEnd is not.");
395 if (aDoubleQuoteEnd.toChar() <= 127 && aDoubleQuoteStart.toChar() > 127)
396 fprintf( stderr, "Warning: %s\n",
397 "DoubleQuotationEnd is an ASCII character but DoubleQuotationStart is not.");
398 if (aQuoteStart.toChar() <= 127 && aQuoteEnd.toChar() <= 127)
399 fprintf( stderr, "Warning: %s\n",
400 "QuotationStart and QuotationEnd are both ASCII characters. Not necessarily an issue, but unusual.");
401 if (aDoubleQuoteStart.toChar() <= 127 && aDoubleQuoteEnd.toChar() <= 127)
402 fprintf( stderr, "Warning: %s\n",
403 "DoubleQuotationStart and DoubleQuotationEnd are both ASCII characters. Not necessarily an issue, but unusual.");
404 if (aQuoteStart == aQuoteEnd)
405 fprintf( stderr, "Warning: %s\n",
406 "QuotationStart equals QuotationEnd. Not necessarily an issue, but unusual.");
407 if (aDoubleQuoteStart == aDoubleQuoteEnd)
408 fprintf( stderr, "Warning: %s\n",
409 "DoubleQuotationStart equals DoubleQuotationEnd. Not necessarily an issue, but unusual.");
410 /* TODO: should equalness of single and double quotes be an error? Would
411 * need to adapt quite some locales' data. */
412 if (aQuoteStart == aDoubleQuoteStart)
413 fprintf( stderr, "Warning: %s\n",
414 "QuotationStart equals DoubleQuotationStart. Not necessarily an issue, but unusual.");
415 if (aQuoteEnd == aDoubleQuoteEnd)
416 fprintf( stderr, "Warning: %s\n",
417 "QuotationEnd equals DoubleQuotationEnd. Not necessarily an issue, but unusual.");
418 // Known good values, exclude ASCII single (U+0027, ') and double (U+0022, ") quotes.
419 switch (int ic = aQuoteStart.toChar())
421 case 0x2018: // LEFT SINGLE QUOTATION MARK
422 case 0x201a: // SINGLE LOW-9 QUOTATION MARK
423 case 0x201b: // SINGLE HIGH-REVERSED-9 QUOTATION MARK
424 case 0x2039: // SINGLE LEFT-POINTING ANGLE QUOTATION MARK
425 case 0x203a: // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
426 case 0x300c: // LEFT CORNER BRACKET (Chinese)
428 break;
429 default:
430 fprintf( stderr, "Warning: %s U+%04X %s\n",
431 "QuotationStart may be wrong:", ic, OSTR( aQuoteStart));
433 switch (int ic = aQuoteEnd.toChar())
435 case 0x2019: // RIGHT SINGLE QUOTATION MARK
436 case 0x201a: // SINGLE LOW-9 QUOTATION MARK
437 case 0x201b: // SINGLE HIGH-REVERSED-9 QUOTATION MARK
438 case 0x2039: // SINGLE LEFT-POINTING ANGLE QUOTATION MARK
439 case 0x203a: // SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
440 case 0x300d: // RIGHT CORNER BRACKET (Chinese)
442 break;
443 default:
444 fprintf( stderr, "Warning: %s U+%04X %s\n",
445 "QuotationEnd may be wrong:", ic, OSTR( aQuoteEnd));
447 switch (int ic = aDoubleQuoteStart.toChar())
449 case 0x00ab: // LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
450 case 0x00bb: // RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
451 case 0x201c: // LEFT DOUBLE QUOTATION MARK
452 case 0x201e: // DOUBLE LOW-9 QUOTATION MARK
453 case 0x201f: // DOUBLE HIGH-REVERSED-9 QUOTATION MARK
454 case 0x300e: // LEFT WHITE CORNER BRACKET (Chinese)
456 break;
457 default:
458 fprintf( stderr, "Warning: %s U+%04X %s\n",
459 "DoubleQuotationStart may be wrong:", ic, OSTR( aDoubleQuoteStart));
461 switch (int ic = aDoubleQuoteEnd.toChar())
463 case 0x00ab: // LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
464 case 0x00bb: // RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
465 case 0x201d: // RIGHT DOUBLE QUOTATION MARK
466 case 0x201e: // DOUBLE LOW-9 QUOTATION MARK
467 case 0x201f: // DOUBLE HIGH-REVERSED-9 QUOTATION MARK
468 case 0x300f: // RIGHT WHITE CORNER BRACKET (Chinese)
470 break;
471 default:
472 fprintf( stderr, "Warning: %s U+%04X %s\n",
473 "DoubleQuotationEnd may be wrong:", ic, OSTR( aDoubleQuoteEnd));
476 writeParameterCheckLen( of, "TimeAM", "timeAM", 1, -1);
477 writeParameterCheckLen( of, "TimePM", "timePM", 1, -1);
478 sepNode = findNode("MeasurementSystem");
479 of.writeParameter("measurementSystem", sepNode->getValue());
481 of.writeAsciiString("\nstatic const sal_Unicode* LCType[] = {\n");
482 of.writeAsciiString("\tLC_CTYPE_Unoid,\n");
483 of.writeAsciiString("\tdateSeparator,\n");
484 of.writeAsciiString("\tthousandSeparator,\n");
485 of.writeAsciiString("\tdecimalSeparator,\n");
486 of.writeAsciiString("\ttimeSeparator,\n");
487 of.writeAsciiString("\ttime100SecSeparator,\n");
488 of.writeAsciiString("\tlistSeparator,\n");
489 of.writeAsciiString("\tquotationStart,\n");
490 of.writeAsciiString("\tquotationEnd,\n");
491 of.writeAsciiString("\tdoubleQuotationStart,\n");
492 of.writeAsciiString("\tdoubleQuotationEnd,\n");
493 of.writeAsciiString("\ttimeAM,\n");
494 of.writeAsciiString("\ttimePM,\n");
495 of.writeAsciiString("\tmeasurementSystem,\n");
496 of.writeAsciiString("\tLongDateDayOfWeekSeparator,\n");
497 of.writeAsciiString("\tLongDateDaySeparator,\n");
498 of.writeAsciiString("\tLongDateMonthSeparator,\n");
499 of.writeAsciiString("\tLongDateYearSeparator,\n");
500 of.writeAsciiString("\tdecimalSeparatorAlternative\n");
501 of.writeAsciiString("};\n\n");
502 of.writeFunction("getLocaleItem_", "SAL_N_ELEMENTS(LCType)", "LCType");
506 static OUString sTheCurrencyReplaceTo;
507 static OUString sTheCompatibleCurrency;
508 static OUString sTheDateEditFormat;
510 sal_Int16 LCFormatNode::mnSection = 0;
511 sal_Int16 LCFormatNode::mnFormats = 0;
513 void LCFormatNode::generateCode (const OFileWriter &of) const
515 if (mnSection >= 2)
516 incError("more than 2 LC_FORMAT sections");
518 ::std::vector< OUString > theDateAcceptancePatterns;
520 OUString useLocale(getAttr().getValueByName("ref"));
522 OUString str;
523 OUString strFrom( getAttr().getValueByName("replaceFrom"));
524 if (useLocale.isEmpty())
526 of.writeParameter("replaceFrom", strFrom, mnSection);
528 str = getAttr().getValueByName("replaceTo");
529 if (!strFrom.isEmpty() && str.isEmpty())
530 incErrorStr("replaceFrom=\"%s\" replaceTo=\"\" is empty replacement.\n", strFrom);
531 // Locale data generator inserts FFFF for LangID, we need to adapt that.
532 if (str.endsWithIgnoreAsciiCase( "-FFFF]"))
533 incErrorStr("replaceTo=\"%s\" needs FFFF to be adapted to the real LangID value.\n", str);
534 of.writeParameter("replaceTo", str, mnSection);
535 // Remember the replaceTo value for "[CURRENCY]" to check format codes.
536 if ( strFrom == "[CURRENCY]" )
537 sTheCurrencyReplaceTo = str;
538 // Remember the currency symbol if present.
539 if (str.startsWith( "[$" ))
541 sal_Int32 nHyphen = str.indexOf( '-');
542 if (nHyphen >= 3)
544 sTheCompatibleCurrency = str.copy( 2, nHyphen - 2);
548 if (!useLocale.isEmpty())
550 if (!strFrom.isEmpty() && strFrom != "[CURRENCY]") //???
552 incErrorStrStr(
553 "Error: non-empty replaceFrom=\"%s\" with non-empty ref=\"%s\".",
554 strFrom, useLocale);
556 useLocale = useLocale.replace( '-', '_');
557 switch (mnSection)
559 case 0:
560 of.writeRefFunction("getAllFormats0_", useLocale, "replaceTo0");
561 break;
562 case 1:
563 of.writeRefFunction("getAllFormats1_", useLocale, "replaceTo1");
564 break;
566 of.writeRefFunction("getDateAcceptancePatterns_", useLocale);
567 return;
570 sal_Int16 formatCount = mnFormats;
571 NameSet aMsgIdSet;
572 ValueSet aFormatIndexSet;
573 NameSet aDefaultsSet;
574 bool bCtypeIsRef = false;
575 bool bHaveEngineering = false;
576 bool bShowNextFreeFormatIndex = false;
577 const sal_Int16 nFirstFreeFormatIndex = 60;
579 for (sal_Int32 i = 0; i< getNumberOfChildren() ; i++, formatCount++)
581 LocaleNode * currNode = getChildAt (i);
582 if ( currNode->getName() == "DateAcceptancePattern" )
584 if (mnSection > 0)
585 incError( "DateAcceptancePattern only handled in LC_FORMAT, not LC_FORMAT_1");
586 else
587 theDateAcceptancePatterns.push_back( currNode->getValue());
588 --formatCount;
589 continue; // for
591 if ( currNode->getName() != "FormatElement" )
593 incErrorStr( "Error: Undefined element '%s' in LC_FORMAT\n", currNode->getName());
594 --formatCount;
595 continue; // for
598 OUString aUsage;
599 OUString aType;
600 OUString aFormatIndex;
601 // currNode -> print();
602 const Attr &currNodeAttr = currNode->getAttr();
603 //printf ("getLen() = %d\n", currNode->getAttr().getLength());
605 str = currNodeAttr.getValueByName("msgid");
606 if (!aMsgIdSet.insert( str).second)
607 incErrorStr( "Error: Duplicated msgid=\"%s\" in FormatElement.\n", str);
608 of.writeParameter("FormatKey", str, formatCount);
610 str = currNodeAttr.getValueByName("default");
611 bool bDefault = str == "true";
612 of.writeDefaultParameter("FormatElement", str, formatCount);
614 aType = currNodeAttr.getValueByName("type");
615 of.writeParameter("FormatType", aType, formatCount);
617 aUsage = currNodeAttr.getValueByName("usage");
618 of.writeParameter("FormatUsage", aUsage, formatCount);
620 aFormatIndex = currNodeAttr.getValueByName("formatindex");
621 sal_Int16 formatindex = static_cast<sal_Int16>(aFormatIndex.toInt32());
622 // Ensure the new reserved range is not used anymore, free usage start
623 // was up'ed from 50 to 60.
624 if (50 <= formatindex && formatindex < nFirstFreeFormatIndex)
626 incErrorInt( "Error: Reserved formatindex=\"%d\" in FormatElement.\n", formatindex);
627 bShowNextFreeFormatIndex = true;
629 if (!aFormatIndexSet.insert( formatindex).second)
631 incErrorInt( "Error: Duplicated formatindex=\"%d\" in FormatElement.\n", formatindex);
632 bShowNextFreeFormatIndex = true;
634 of.writeIntParameter("Formatindex", formatCount, formatindex);
636 // Ensure only one default per usage and type.
637 if (bDefault)
639 OUString aKey( aUsage + "," + aType);
640 if (!aDefaultsSet.insert( aKey).second)
642 OUString aStr = "Duplicated default for usage=\"" + aUsage + "\" type=\"" + aType + "\": formatindex=\"" + aFormatIndex + "\".";
643 incError( aStr);
647 const LocaleNode * n = currNode -> findNode("FormatCode");
648 if (n)
650 of.writeParameter("FormatCode", n->getValue(), formatCount);
651 // Check separator usage for some FormatCode elements.
652 const LocaleNode* pCtype = nullptr;
653 switch (formatindex)
655 case cssi::NumberFormatIndex::DATE_SYS_DDMMYYYY :
656 sTheDateEditFormat = n->getValue();
657 break;
658 case cssi::NumberFormatIndex::NUMBER_1000DEC2 : // #,##0.00
659 case cssi::NumberFormatIndex::TIME_MMSS00 : // MM:SS.00
660 case cssi::NumberFormatIndex::TIME_HH_MMSS00 : // [HH]:MM:SS.00
662 const LocaleNode* pRoot = getRoot();
663 if (!pRoot)
664 incError( "No root for FormatCode.");
665 else
667 pCtype = pRoot->findNode( "LC_CTYPE");
668 if (!pCtype)
669 incError( "No LC_CTYPE found for FormatCode.");
670 else
672 OUString aRef( pCtype->getAttr().getValueByName("ref"));
673 if (!aRef.isEmpty())
675 aRef = aRef.replace( '-', '_');
676 if (!bCtypeIsRef)
677 fprintf( stderr,
678 "Warning: Can't check separators used in FormatCode due to LC_CTYPE ref=\"%s\".\n"
679 "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",
680 OSTR( aRef));
681 bCtypeIsRef = true;
682 pCtype = nullptr;
687 break;
688 case cssi::NumberFormatIndex::CURRENCY_1000DEC2 :
689 // Remember the currency symbol if present.
691 sal_Int32 nStart;
692 if (sTheCompatibleCurrency.isEmpty() &&
693 ((nStart = n->getValue().indexOf("[$")) >= 0))
695 const OUString& aCode( n->getValue());
696 sal_Int32 nHyphen = aCode.indexOf( '-', nStart);
697 if (nHyphen >= nStart + 3)
698 sTheCompatibleCurrency = aCode.copy( nStart + 2, nHyphen - nStart - 2);
701 [[fallthrough]];
702 case cssi::NumberFormatIndex::CURRENCY_1000INT :
703 case cssi::NumberFormatIndex::CURRENCY_1000INT_RED :
704 case cssi::NumberFormatIndex::CURRENCY_1000DEC2_RED :
705 case cssi::NumberFormatIndex::CURRENCY_1000DEC2_CCC :
706 case cssi::NumberFormatIndex::CURRENCY_1000DEC2_DASHED :
707 // Currency formats should be something like [C]###0;-[C]###0
708 // and not parenthesized [C]###0;([C]###0) if not en_US.
709 if (strcmp( of.getLocale(), "en_US") != 0)
711 const OUString& aCode( n->getValue());
712 OUString const aPar1( "0)");
713 OUString const aPar2( "-)" );
714 OUString const aPar3( " )" );
715 OUString const aPar4( "])" );
716 if (aCode.indexOf( aPar1 ) > 0 || aCode.indexOf( aPar2 ) > 0 ||
717 aCode.indexOf( aPar3 ) > 0 || aCode.indexOf( aPar4 ) > 0)
718 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);
720 // Check if we have replaceTo for "[CURRENCY]" placeholder.
721 if (sTheCurrencyReplaceTo.isEmpty())
723 const OUString& aCode( n->getValue());
724 if (aCode.indexOf( "[CURRENCY]" ) >= 0)
725 incErrorInt( "Error: [CURRENCY] replaceTo not found for formatindex=\"%d\".\n", formatindex);
727 break;
728 default:
729 if (aUsage == "SCIENTIFIC_NUMBER")
731 // Check for presence of ##0.00E+00
732 const OUString& aCode( n->getValue());
733 // Simple check without decimal separator (assumed to
734 // be one UTF-16 character). May be prefixed with
735 // [NatNum1] or other tags.
736 sal_Int32 nInt = aCode.indexOf("##0");
737 sal_Int32 nDec = (nInt < 0 ? -1 : aCode.indexOf("00E+00", nInt));
738 if (nInt >= 0 && nDec == nInt+4)
739 bHaveEngineering = true;
741 break;
743 if (pCtype)
745 int nSavErr = nError;
746 const OUString& aCode( n->getValue());
747 if (formatindex == cssi::NumberFormatIndex::NUMBER_1000DEC2)
749 sal_Int32 nDec = -1;
750 sal_Int32 nGrp = -1;
751 const LocaleNode* pSep = pCtype->findNode( "DecimalSeparator");
752 if (!pSep)
753 incError( "No DecimalSeparator found for FormatCode.");
754 else
756 nDec = aCode.indexOf( pSep->getValue());
757 if (nDec < 0)
758 incErrorInt( "Error: DecimalSeparator not present in FormatCode formatindex=\"%d\".\n",
759 formatindex);
761 pSep = pCtype->findNode( "ThousandSeparator");
762 if (!pSep)
763 incError( "No ThousandSeparator found for FormatCode.");
764 else
766 nGrp = aCode.indexOf( pSep->getValue());
767 if (nGrp < 0)
768 incErrorInt( "Error: ThousandSeparator not present in FormatCode formatindex=\"%d\".\n",
769 formatindex);
771 if (nDec >= 0 && nGrp >= 0 && nDec <= nGrp)
772 incErrorInt( "Error: Ordering of ThousandSeparator and DecimalSeparator not correct in formatindex=\"%d\".\n",
773 formatindex);
775 if (formatindex == cssi::NumberFormatIndex::TIME_MMSS00 ||
776 formatindex == cssi::NumberFormatIndex::TIME_HH_MMSS00)
778 sal_Int32 nTime = -1;
779 sal_Int32 n100s = -1;
780 const LocaleNode* pSep = pCtype->findNode( "TimeSeparator");
781 if (!pSep)
782 incError( "No TimeSeparator found for FormatCode.");
783 else
785 nTime = aCode.indexOf( pSep->getValue());
786 if (nTime < 0)
787 incErrorInt( "Error: TimeSeparator not present in FormatCode formatindex=\"%d\".\n",
788 formatindex);
790 pSep = pCtype->findNode( "Time100SecSeparator");
791 if (!pSep)
792 incError( "No Time100SecSeparator found for FormatCode.");
793 else
795 n100s = aCode.indexOf( pSep->getValue());
796 if (n100s < 0)
797 incErrorInt( "Error: Time100SecSeparator not present in FormatCode formatindex=\"%d\".\n",
798 formatindex);
799 OUStringBuffer a100s( pSep->getValue());
800 a100s.append( "00");
801 n100s = aCode.indexOf( a100s.makeStringAndClear());
802 if (n100s < 0)
803 incErrorInt( "Error: Time100SecSeparator+00 not present in FormatCode formatindex=\"%d\".\n",
804 formatindex);
806 if (n100s >= 0 && nTime >= 0 && n100s <= nTime)
807 incErrorInt( "Error: Ordering of Time100SecSeparator and TimeSeparator not correct in formatindex=\"%d\".\n",
808 formatindex);
810 if (nSavErr != nError)
811 fprintf( stderr,
812 "Warning: formatindex=\"%d\",\"%d\",\"%d\" are the only FormatCode elements checked for separator usage, there may be others that have errors.\n",
813 int(cssi::NumberFormatIndex::NUMBER_1000DEC2),
814 int(cssi::NumberFormatIndex::TIME_MMSS00),
815 int(cssi::NumberFormatIndex::TIME_HH_MMSS00));
819 else
820 incError( "No FormatCode in FormatElement.");
821 n = currNode -> findNode("DefaultName");
822 if (n)
823 of.writeParameter("FormatDefaultName", n->getValue(), formatCount);
824 else
825 of.writeParameter("FormatDefaultName", OUString(), formatCount);
829 if (bShowNextFreeFormatIndex)
831 sal_Int16 nNext = nFirstFreeFormatIndex;
832 std::set<sal_Int16>::const_iterator it( aFormatIndexSet.find( nNext));
833 if (it != aFormatIndexSet.end())
835 // nFirstFreeFormatIndex already used, find next free including gaps.
838 ++nNext;
840 while (++it != aFormatIndexSet.end() && *it == nNext);
842 fprintf( stderr, "Hint: Next free formatindex is %d.\n", static_cast<int>(nNext));
845 // Check presence of all required format codes only in first section
846 // LC_FORMAT, not in optional LC_FORMAT_1
847 if (mnSection == 0)
849 // At least one abbreviated date acceptance pattern must be present.
850 if (theDateAcceptancePatterns.empty())
851 incError( "No DateAcceptancePattern present.\n");
852 else
854 bool bHaveAbbr = false;
855 for (auto const& elem : theDateAcceptancePatterns)
857 if (elem.indexOf('D') > -1 && elem.indexOf('M') > -1 && elem.indexOf('Y') <= -1)
859 bHaveAbbr = true;
860 break;
863 if (!bHaveAbbr)
864 incError( "No abbreviated DateAcceptancePattern present. For example M/D or D.M.\n");
867 // 0..47 MUST be present, 48,49 MUST NOT be present
868 ValueSet::const_iterator aIter( aFormatIndexSet.begin());
869 for (sal_Int16 nNext = cssi::NumberFormatIndex::NUMBER_START;
870 nNext < cssi::NumberFormatIndex::INDEX_TABLE_ENTRIES; ++nNext)
872 sal_Int16 nHere = ::std::min( (aIter != aFormatIndexSet.end() ? *aIter :
873 cssi::NumberFormatIndex::INDEX_TABLE_ENTRIES),
874 cssi::NumberFormatIndex::INDEX_TABLE_ENTRIES);
875 if (aIter != aFormatIndexSet.end()) ++aIter;
876 for ( ; nNext < nHere; ++nNext)
878 switch (nNext)
880 case cssi::NumberFormatIndex::FRACTION_1 :
881 case cssi::NumberFormatIndex::FRACTION_2 :
882 case cssi::NumberFormatIndex::BOOLEAN :
883 case cssi::NumberFormatIndex::TEXT :
884 // generated internally
885 break;
886 default:
887 incErrorInt( "Error: FormatElement formatindex=\"%d\" not present.\n", nNext);
890 switch (nHere)
892 case cssi::NumberFormatIndex::BOOLEAN :
893 incErrorInt( "Error: FormatElement formatindex=\"%d\" reserved for internal ``BOOLEAN''.\n", nNext);
894 break;
895 case cssi::NumberFormatIndex::TEXT :
896 incErrorInt( "Error: FormatElement formatindex=\"%d\" reserved for internal ``@'' (TEXT).\n", nNext);
897 break;
898 default:
899 ; // nothing
903 if (!bHaveEngineering)
904 incError("Engineering notation format not present, e.g. ##0.00E+00 or ##0,00E+00 for usage=\"SCIENTIFIC_NUMBER\"\n");
907 of.writeAsciiString("\nstatic const sal_Int16 ");
908 of.writeAsciiString("FormatElementsCount");
909 of.writeInt(mnSection);
910 of.writeAsciiString(" = ");
911 of.writeInt( formatCount - mnFormats);
912 of.writeAsciiString(";\n");
913 of.writeAsciiString("static const sal_Unicode* ");
914 of.writeAsciiString("FormatElementsArray");
915 of.writeInt(mnSection);
916 of.writeAsciiString("[] = {\n");
917 for(sal_Int16 i = mnFormats; i < formatCount; i++) {
919 of.writeAsciiString("\t");
920 of.writeAsciiString("FormatCode");
921 of.writeInt(i);
922 of.writeAsciiString(",\n");
924 of.writeAsciiString("\t");
925 of.writeAsciiString("FormatDefaultName");
926 of.writeInt(i);
927 of.writeAsciiString(",\n");
929 of.writeAsciiString("\t");
930 of.writeAsciiString("FormatKey");
931 of.writeInt(i);
932 of.writeAsciiString(",\n");
934 of.writeAsciiString("\t");
935 of.writeAsciiString("FormatType");
936 of.writeInt(i);
937 of.writeAsciiString(",\n");
939 of.writeAsciiString("\t");
940 of.writeAsciiString("FormatUsage");
941 of.writeInt(i);
942 of.writeAsciiString(",\n");
944 of.writeAsciiString("\t");
945 of.writeAsciiString("Formatindex");
946 of.writeInt(i);
947 of.writeAsciiString(",\n");
950 of.writeAsciiString("\tdefaultFormatElement");
951 of.writeInt(i);
952 of.writeAsciiString(",\n");
954 of.writeAsciiString("};\n\n");
956 switch (mnSection)
958 case 0:
959 of.writeFunction("getAllFormats0_", "FormatElementsCount0", "FormatElementsArray0", "replaceFrom0", "replaceTo0");
960 break;
961 case 1:
962 of.writeFunction("getAllFormats1_", "FormatElementsCount1", "FormatElementsArray1", "replaceFrom1", "replaceTo1");
963 break;
966 mnFormats = mnFormats + formatCount;
968 if (mnSection == 0)
970 // Extract and add date acceptance pattern for full date, so we provide
971 // at least one valid pattern, even if the number parser doesn't need
972 // that one.
973 /* XXX NOTE: only simple [...] modifier and "..." quotes detected and
974 * ignored, not nested, no fancy stuff. */
975 sal_Int32 nIndex = 0;
976 // aDateSep can be empty if LC_CTYPE was a ref=..., determine from
977 // FormatCode then.
978 sal_uInt32 cDateSep = (aDateSep.isEmpty() ? 0 : aDateSep.iterateCodePoints( &nIndex));
979 sal_uInt32 cDateSep2 = cDateSep;
980 nIndex = 0;
981 OUStringBuffer aPatternBuf(5);
982 OUStringBuffer aPatternBuf2(5);
983 sal_uInt8 nDetected = 0; // bits Y,M,D
984 bool bInModifier = false;
985 bool bQuoted = false;
986 while (nIndex < sTheDateEditFormat.getLength() && nDetected < 7)
988 sal_uInt32 cChar = sTheDateEditFormat.iterateCodePoints( &nIndex);
989 if (bInModifier)
991 if (cChar == ']')
992 bInModifier = false;
993 continue; // while
995 if (bQuoted)
997 if (cChar == '"')
998 bQuoted = false;
999 continue; // while
1001 switch (cChar)
1003 case 'Y':
1004 case 'y':
1005 if (!(nDetected & 4))
1007 aPatternBuf.append( 'Y');
1008 if (!aPatternBuf2.isEmpty())
1009 aPatternBuf2.append( 'Y');
1010 nDetected |= 4;
1012 break;
1013 case 'M':
1014 case 'm':
1015 if (!(nDetected & 2))
1017 aPatternBuf.append( 'M');
1018 if (!aPatternBuf2.isEmpty())
1019 aPatternBuf2.append( 'M');
1020 nDetected |= 2;
1022 break;
1023 case 'D':
1024 case 'd':
1025 if (!(nDetected & 1))
1027 aPatternBuf.append( 'D');
1028 if (!aPatternBuf2.isEmpty())
1029 aPatternBuf2.append( 'D');
1030 nDetected |= 1;
1032 break;
1033 case '[':
1034 bInModifier = true;
1035 break;
1036 case '"':
1037 bQuoted = true;
1038 break;
1039 case '\\':
1040 cChar = sTheDateEditFormat.iterateCodePoints( &nIndex);
1041 goto handleDefault;
1042 case '-':
1043 case '.':
1044 case '/':
1045 // There are locales that use an ISO 8601 edit format
1046 // regardless of what the date separator or other formats
1047 // say, for example hu-HU. Generalize this for all cases
1048 // where the used separator differs and is one of the known
1049 // separators and generate a second pattern with the
1050 // format's separator at the current position.
1051 cDateSep2 = cChar;
1052 [[fallthrough]];
1053 default:
1054 handleDefault:
1055 if (!cDateSep)
1056 cDateSep = cChar;
1057 if (!cDateSep2)
1058 cDateSep2 = cChar;
1059 if (cDateSep != cDateSep2 && aPatternBuf2.isEmpty())
1060 aPatternBuf2 = aPatternBuf;
1061 if (cChar == cDateSep || cChar == cDateSep2)
1062 aPatternBuf.append( OUString( &cDateSep, 1)); // always the defined separator
1063 if (cChar == cDateSep2 && !aPatternBuf2.isEmpty())
1064 aPatternBuf2.append( OUString( &cDateSep2, 1)); // always the format's separator
1065 break;
1066 // The localized legacy:
1067 case 'A':
1068 if (((nDetected & 7) == 3) || ((nDetected & 7) == 0))
1070 // es DD/MM/AAAA
1071 // fr JJ.MM.AAAA
1072 // it GG/MM/AAAA
1073 // fr_CA AAAA-MM-JJ
1074 aPatternBuf.append( 'Y');
1075 if (!aPatternBuf2.isEmpty())
1076 aPatternBuf2.append( 'Y');
1077 nDetected |= 4;
1079 break;
1080 case 'J':
1081 if (((nDetected & 7) == 0) || ((nDetected & 7) == 6))
1083 // fr JJ.MM.AAAA
1084 // fr_CA AAAA-MM-JJ
1085 aPatternBuf.append( 'D');
1086 if (!aPatternBuf2.isEmpty())
1087 aPatternBuf2.append( 'D');
1088 nDetected |= 1;
1090 else if ((nDetected & 7) == 3)
1092 // nl DD-MM-JJJJ
1093 // de TT.MM.JJJJ
1094 aPatternBuf.append( 'Y');
1095 if (!aPatternBuf2.isEmpty())
1096 aPatternBuf2.append( 'Y');
1097 nDetected |= 4;
1099 break;
1100 case 'T':
1101 if ((nDetected & 7) == 0)
1103 // de TT.MM.JJJJ
1104 aPatternBuf.append( 'D');
1105 if (!aPatternBuf2.isEmpty())
1106 aPatternBuf2.append( 'D');
1107 nDetected |= 1;
1109 break;
1110 case 'G':
1111 if ((nDetected & 7) == 0)
1113 // it GG/MM/AAAA
1114 aPatternBuf.append( 'D');
1115 if (!aPatternBuf2.isEmpty())
1116 aPatternBuf2.append( 'D');
1117 nDetected |= 1;
1119 break;
1120 case 'P':
1121 if ((nDetected & 7) == 0)
1123 // fi PP.KK.VVVV
1124 aPatternBuf.append( 'D');
1125 if (!aPatternBuf2.isEmpty())
1126 aPatternBuf2.append( 'D');
1127 nDetected |= 1;
1129 break;
1130 case 'K':
1131 if ((nDetected & 7) == 1)
1133 // fi PP.KK.VVVV
1134 aPatternBuf.append( 'M');
1135 if (!aPatternBuf2.isEmpty())
1136 aPatternBuf2.append( 'M');
1137 nDetected |= 2;
1139 break;
1140 case 'V':
1141 if ((nDetected & 7) == 3)
1143 // fi PP.KK.VVVV
1144 aPatternBuf.append( 'Y');
1145 if (!aPatternBuf2.isEmpty())
1146 aPatternBuf2.append( 'Y');
1147 nDetected |= 4;
1149 break;
1152 OUString aPattern( aPatternBuf.makeStringAndClear());
1153 if (((nDetected & 7) != 7) || aPattern.getLength() < 5)
1155 incErrorStr( "Error: failed to extract full date acceptance pattern: %s\n", aPattern);
1156 fprintf( stderr, " with DateSeparator '%s' from FormatCode '%s' (formatindex=\"%d\")\n",
1157 OSTR( OUString(&cDateSep, 1)), OSTR( sTheDateEditFormat),
1158 int(cssi::NumberFormatIndex::DATE_SYS_DDMMYYYY));
1160 else
1162 fprintf( stderr, "Generated date acceptance pattern: '%s' from '%s' (formatindex=\"%d\" and defined DateSeparator '%s')\n",
1163 OSTR( aPattern), OSTR( sTheDateEditFormat),
1164 int(cssi::NumberFormatIndex::DATE_SYS_DDMMYYYY),
1165 OSTR( OUString(&cDateSep, 1)));
1166 // Insert at front so full date pattern is first in checks.
1167 theDateAcceptancePatterns.insert( theDateAcceptancePatterns.begin(), aPattern);
1169 if (!aPatternBuf2.isEmpty())
1171 OUString aPattern2( aPatternBuf2.makeStringAndClear());
1172 if (aPattern2.getLength() < 5)
1174 incErrorStr( "Error: failed to extract 2nd date acceptance pattern: %s\n", aPattern2);
1175 fprintf( stderr, " with DateSeparator '%s' from FormatCode '%s' (formatindex=\"%d\")\n",
1176 OSTR( OUString(&cDateSep2, 1)), OSTR( sTheDateEditFormat),
1177 int(cssi::NumberFormatIndex::DATE_SYS_DDMMYYYY));
1179 else
1181 fprintf( stderr, "Generated 2nd acceptance pattern: '%s' from '%s' (formatindex=\"%d\")\n",
1182 OSTR( aPattern2), OSTR( sTheDateEditFormat),
1183 int(cssi::NumberFormatIndex::DATE_SYS_DDMMYYYY));
1184 theDateAcceptancePatterns.insert( theDateAcceptancePatterns.begin(), aPattern2);
1188 // Rudimentary check if a pattern interferes with decimal number.
1189 // But only if not inherited in which case we don't have aDecSep here.
1190 if (!aDecSep.isEmpty())
1192 nIndex = 0;
1193 sal_uInt32 cDecSep = aDecSep.iterateCodePoints( &nIndex);
1194 for (auto const& elem : theDateAcceptancePatterns)
1196 if (elem.getLength() == (cDecSep <= 0xffff ? 3 : 4))
1198 nIndex = 1;
1199 if (elem.iterateCodePoints( &nIndex) == cDecSep)
1201 ++nError;
1202 fprintf( stderr, "Error: Date acceptance pattern '%s' matches decimal number '#%s#'\n",
1203 OSTR(elem), OSTR( aDecSep));
1209 // Check for duplicates.
1210 for (vector<OUString>::const_iterator aIt = theDateAcceptancePatterns.begin();
1211 aIt != theDateAcceptancePatterns.end(); ++aIt)
1213 for (vector<OUString>::iterator aComp = theDateAcceptancePatterns.begin();
1214 aComp != theDateAcceptancePatterns.end(); /*nop*/)
1216 if (aIt != aComp && *aIt == *aComp)
1218 incErrorStr( "Error: Duplicated DateAcceptancePattern: %s\n", *aComp);
1219 aComp = theDateAcceptancePatterns.erase( aComp);
1221 else
1222 ++aComp;
1226 sal_Int16 nbOfDateAcceptancePatterns = static_cast<sal_Int16>(theDateAcceptancePatterns.size());
1228 for (sal_Int16 i = 0; i < nbOfDateAcceptancePatterns; ++i)
1230 of.writeParameter("DateAcceptancePattern", theDateAcceptancePatterns[i], i);
1233 of.writeAsciiString("static const sal_Int16 DateAcceptancePatternsCount = ");
1234 of.writeInt( nbOfDateAcceptancePatterns);
1235 of.writeAsciiString(";\n");
1237 of.writeAsciiString("static const sal_Unicode* DateAcceptancePatternsArray[] = {\n");
1238 for (sal_Int16 i = 0; i < nbOfDateAcceptancePatterns; ++i)
1240 of.writeAsciiString("\t");
1241 of.writeAsciiString("DateAcceptancePattern");
1242 of.writeInt(i);
1243 of.writeAsciiString(",\n");
1245 of.writeAsciiString("};\n\n");
1247 of.writeFunction("getDateAcceptancePatterns_", "DateAcceptancePatternsCount", "DateAcceptancePatternsArray");
1250 ++mnSection;
1253 void LCCollationNode::generateCode (const OFileWriter &of) const
1255 OUString useLocale = getAttr().getValueByName("ref");
1256 if (!useLocale.isEmpty()) {
1257 useLocale = useLocale.replace( '-', '_');
1258 of.writeRefFunction("getCollatorImplementation_", useLocale);
1259 of.writeRefFunction("getCollationOptions_", useLocale);
1260 return;
1262 sal_Int16 nbOfCollations = 0;
1263 sal_Int16 nbOfCollationOptions = 0;
1265 for ( sal_Int32 j = 0; j < getNumberOfChildren(); j++ ) {
1266 LocaleNode * currNode = getChildAt (j);
1267 if( currNode->getName() == "Collator" )
1269 OUString str;
1270 str = currNode->getAttr().getValueByName("unoid");
1271 of.writeParameter("CollatorID", str, j);
1272 str = currNode->getValue();
1273 of.writeParameter("CollatorRule", str, j);
1274 str = currNode -> getAttr().getValueByName("default");
1275 of.writeDefaultParameter("Collator", str, j);
1276 of.writeAsciiString("\n");
1278 nbOfCollations++;
1280 if( currNode->getName() == "CollationOptions" )
1282 LocaleNode* pCollationOptions = currNode;
1283 nbOfCollationOptions = sal::static_int_cast<sal_Int16>( pCollationOptions->getNumberOfChildren() );
1284 for( sal_Int16 i=0; i<nbOfCollationOptions; i++ )
1286 of.writeParameter("collationOption", pCollationOptions->getChildAt( i )->getValue(), i );
1289 of.writeAsciiString("static const sal_Int16 nbOfCollationOptions = ");
1290 of.writeInt( nbOfCollationOptions );
1291 of.writeAsciiString(";\n\n");
1294 of.writeAsciiString("static const sal_Int16 nbOfCollations = ");
1295 of.writeInt(nbOfCollations);
1296 of.writeAsciiString(";\n\n");
1298 of.writeAsciiString("\nstatic const sal_Unicode* LCCollatorArray[] = {\n");
1299 for(sal_Int16 j = 0; j < nbOfCollations; j++) {
1300 of.writeAsciiString("\tCollatorID");
1301 of.writeInt(j);
1302 of.writeAsciiString(",\n");
1304 of.writeAsciiString("\tdefaultCollator");
1305 of.writeInt(j);
1306 of.writeAsciiString(",\n");
1308 of.writeAsciiString("\tCollatorRule");
1309 of.writeInt(j);
1310 of.writeAsciiString(",\n");
1312 of.writeAsciiString("};\n\n");
1314 of.writeAsciiString("static const sal_Unicode* collationOptions[] = {");
1315 for( sal_Int16 j=0; j<nbOfCollationOptions; j++ )
1317 of.writeAsciiString( "collationOption" );
1318 of.writeInt( j );
1319 of.writeAsciiString( ", " );
1321 of.writeAsciiString("NULL };\n");
1322 of.writeFunction("getCollatorImplementation_", "nbOfCollations", "LCCollatorArray");
1323 of.writeFunction("getCollationOptions_", "nbOfCollationOptions", "collationOptions");
1326 void LCSearchNode::generateCode (const OFileWriter &of) const
1328 OUString useLocale = getAttr().getValueByName("ref");
1329 if (!useLocale.isEmpty()) {
1330 useLocale = useLocale.replace( '-', '_');
1331 of.writeRefFunction("getSearchOptions_", useLocale);
1332 return;
1335 if( getNumberOfChildren() != 1 )
1337 ++nError;
1338 fprintf(
1339 stderr, "Error: LC_SEARCH: more than 1 child: %ld\n",
1340 sal::static_int_cast< long >(getNumberOfChildren()));
1342 sal_Int32 i;
1343 LocaleNode* pSearchOptions = getChildAt( 0 );
1344 sal_Int32 nSearchOptions = pSearchOptions->getNumberOfChildren();
1345 for( i=0; i<nSearchOptions; i++ )
1347 of.writeParameter("searchOption", pSearchOptions->getChildAt( i )->getValue(), sal::static_int_cast<sal_Int16>(i) );
1350 of.writeAsciiString("static const sal_Int16 nbOfSearchOptions = ");
1351 of.writeInt( sal::static_int_cast<sal_Int16>( nSearchOptions ) );
1352 of.writeAsciiString(";\n\n");
1354 of.writeAsciiString("static const sal_Unicode* searchOptions[] = {");
1355 for( i=0; i<nSearchOptions; i++ )
1357 of.writeAsciiString( "searchOption" );
1358 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
1359 of.writeAsciiString( ", " );
1361 of.writeAsciiString("NULL };\n");
1362 of.writeFunction("getSearchOptions_", "nbOfSearchOptions", "searchOptions");
1365 void LCIndexNode::generateCode (const OFileWriter &of) const
1367 OUString useLocale = getAttr().getValueByName("ref");
1368 if (!useLocale.isEmpty()) {
1369 useLocale = useLocale.replace( '-', '_');
1370 of.writeRefFunction("getIndexAlgorithm_", useLocale);
1371 of.writeRefFunction("getUnicodeScripts_", useLocale);
1372 of.writeRefFunction("getFollowPageWords_", useLocale);
1373 return;
1375 sal_Int16 nbOfIndexs = 0;
1376 sal_Int16 nbOfUnicodeScripts = 0;
1377 sal_Int16 nbOfPageWords = 0;
1378 for (sal_Int32 i = 0; i< getNumberOfChildren();i++) {
1379 LocaleNode * currNode = getChildAt (i);
1380 if( currNode->getName() == "IndexKey" )
1382 OUString str;
1383 str = currNode->getAttr().getValueByName("unoid");
1384 of.writeParameter("IndexID", str, nbOfIndexs);
1385 str = currNode->getAttr().getValueByName("module");
1386 of.writeParameter("IndexModule", str, nbOfIndexs);
1387 str = currNode->getValue();
1388 of.writeParameter("IndexKey", str, nbOfIndexs);
1389 str = currNode -> getAttr().getValueByName("default");
1390 of.writeDefaultParameter("Index", str, nbOfIndexs);
1391 str = currNode -> getAttr().getValueByName("phonetic");
1392 of.writeDefaultParameter("Phonetic", str, nbOfIndexs);
1393 of.writeAsciiString("\n");
1395 nbOfIndexs++;
1397 if( currNode->getName() == "UnicodeScript" )
1399 of.writeParameter("unicodeScript", currNode->getValue(), nbOfUnicodeScripts );
1400 nbOfUnicodeScripts++;
1403 if( currNode->getName() == "FollowPageWord" )
1405 of.writeParameter("followPageWord", currNode->getValue(), nbOfPageWords);
1406 nbOfPageWords++;
1409 of.writeAsciiString("static const sal_Int16 nbOfIndexs = ");
1410 of.writeInt(nbOfIndexs);
1411 of.writeAsciiString(";\n\n");
1413 of.writeAsciiString("\nstatic const sal_Unicode* IndexArray[] = {\n");
1414 for(sal_Int16 i = 0; i < nbOfIndexs; i++) {
1415 of.writeAsciiString("\tIndexID");
1416 of.writeInt(i);
1417 of.writeAsciiString(",\n");
1419 of.writeAsciiString("\tIndexModule");
1420 of.writeInt(i);
1421 of.writeAsciiString(",\n");
1423 of.writeAsciiString("\tIndexKey");
1424 of.writeInt(i);
1425 of.writeAsciiString(",\n");
1427 of.writeAsciiString("\tdefaultIndex");
1428 of.writeInt(i);
1429 of.writeAsciiString(",\n");
1431 of.writeAsciiString("\tdefaultPhonetic");
1432 of.writeInt(i);
1433 of.writeAsciiString(",\n");
1435 of.writeAsciiString("};\n\n");
1437 of.writeAsciiString("static const sal_Int16 nbOfUnicodeScripts = ");
1438 of.writeInt( nbOfUnicodeScripts );
1439 of.writeAsciiString(";\n\n");
1441 of.writeAsciiString("static const sal_Unicode* UnicodeScriptArray[] = {");
1442 for( sal_Int16 i=0; i<nbOfUnicodeScripts; i++ )
1444 of.writeAsciiString( "unicodeScript" );
1445 of.writeInt( i );
1446 of.writeAsciiString( ", " );
1448 of.writeAsciiString("NULL };\n\n");
1450 of.writeAsciiString("static const sal_Int16 nbOfPageWords = ");
1451 of.writeInt(nbOfPageWords);
1452 of.writeAsciiString(";\n\n");
1454 of.writeAsciiString("static const sal_Unicode* FollowPageWordArray[] = {\n");
1455 for(sal_Int16 i = 0; i < nbOfPageWords; i++) {
1456 of.writeAsciiString("\tfollowPageWord");
1457 of.writeInt(i);
1458 of.writeAsciiString(",\n");
1460 of.writeAsciiString("\tNULL\n};\n\n");
1462 of.writeFunction("getIndexAlgorithm_", "nbOfIndexs", "IndexArray");
1463 of.writeFunction("getUnicodeScripts_", "nbOfUnicodeScripts", "UnicodeScriptArray");
1464 of.writeFunction("getFollowPageWords_", "nbOfPageWords", "FollowPageWordArray");
1468 static void lcl_writeAbbrFullNarrNames( const OFileWriter & of, const LocaleNode* currNode,
1469 const sal_Char* elementTag, sal_Int16 i, sal_Int16 j )
1471 OUString aAbbrName = currNode->getChildAt(1)->getValue();
1472 OUString aFullName = currNode->getChildAt(2)->getValue();
1473 OUString aNarrName;
1474 LocaleNode* p = (currNode->getNumberOfChildren() > 3 ? currNode->getChildAt(3) : nullptr);
1475 if ( p && p->getName() == "DefaultNarrowName" )
1476 aNarrName = p->getValue();
1477 else
1479 sal_Int32 nIndex = 0;
1480 sal_uInt32 nChar = aFullName.iterateCodePoints( &nIndex);
1481 aNarrName = OUString( &nChar, 1);
1483 of.writeParameter( elementTag, "DefaultAbbrvName", aAbbrName, i, j);
1484 of.writeParameter( elementTag, "DefaultFullName", aFullName, i, j);
1485 of.writeParameter( elementTag, "DefaultNarrowName", aNarrName, i, j);
1488 static void lcl_writeTabTagString( const OFileWriter & of, const sal_Char* pTag, const sal_Char* pStr )
1490 of.writeAsciiString("\t");
1491 of.writeAsciiString( pTag);
1492 of.writeAsciiString( pStr);
1495 static void lcl_writeTabTagStringNums( const OFileWriter & of,
1496 const sal_Char* pTag, const sal_Char* pStr, sal_Int16 i, sal_Int16 j )
1498 lcl_writeTabTagString( of, pTag, pStr);
1499 of.writeInt(i); of.writeInt(j); of.writeAsciiString(",\n");
1502 static void lcl_writeAbbrFullNarrArrays( const OFileWriter & of, sal_Int16 nCount,
1503 const sal_Char* elementTag, sal_Int16 i, bool bNarrow )
1505 if (nCount == 0)
1507 lcl_writeTabTagString( of, elementTag, "Ref");
1508 of.writeInt(i); of.writeAsciiString(",\n");
1509 lcl_writeTabTagString( of, elementTag, "RefName");
1510 of.writeInt(i); of.writeAsciiString(",\n");
1512 else
1514 for (sal_Int16 j = 0; j < nCount; j++)
1516 lcl_writeTabTagStringNums( of, elementTag, "ID", i, j);
1517 lcl_writeTabTagStringNums( of, elementTag, "DefaultAbbrvName", i, j);
1518 lcl_writeTabTagStringNums( of, elementTag, "DefaultFullName", i, j);
1519 if (bNarrow)
1520 lcl_writeTabTagStringNums( of, elementTag, "DefaultNarrowName", i, j);
1525 void LCCalendarNode::generateCode (const OFileWriter &of) const
1527 OUString useLocale = getAttr().getValueByName("ref");
1528 if (!useLocale.isEmpty()) {
1529 useLocale = useLocale.replace( '-', '_');
1530 of.writeRefFunction("getAllCalendars_", useLocale);
1531 return;
1533 sal_Int16 nbOfCalendars = sal::static_int_cast<sal_Int16>( getNumberOfChildren() );
1534 OUString str;
1535 std::unique_ptr<sal_Int16[]> nbOfDays( new sal_Int16[nbOfCalendars] );
1536 std::unique_ptr<sal_Int16[]> nbOfMonths( new sal_Int16[nbOfCalendars] );
1537 std::unique_ptr<sal_Int16[]> nbOfGenitiveMonths( new sal_Int16[nbOfCalendars] );
1538 std::unique_ptr<sal_Int16[]> nbOfPartitiveMonths( new sal_Int16[nbOfCalendars] );
1539 std::unique_ptr<sal_Int16[]> nbOfEras( new sal_Int16[nbOfCalendars] );
1540 sal_Int16 j;
1541 sal_Int16 i;
1542 bool bHasGregorian = false;
1545 for ( i = 0; i < nbOfCalendars; i++) {
1546 LocaleNode * calNode = getChildAt (i);
1547 OUString calendarID = calNode -> getAttr().getValueByName("unoid");
1548 of.writeParameter( "calendarID", calendarID, i);
1549 bool bGregorian = calendarID == "gregorian";
1550 if (!bHasGregorian)
1551 bHasGregorian = bGregorian;
1552 str = calNode -> getAttr().getValueByName("default");
1553 of.writeDefaultParameter("Calendar", str, i);
1555 sal_Int16 nChild = 0;
1557 // Generate Days of Week
1558 const sal_Char *elementTag;
1559 LocaleNode * daysNode = nullptr;
1560 OUString ref_name = calNode->getChildAt(nChild)->getAttr().getValueByName("ref");
1561 ref_name = ref_name.replace( '-', '_');
1562 if (!ref_name.isEmpty() && i > 0) {
1563 for (j = 0; j < i; j++) {
1564 str = getChildAt(j)->getAttr().getValueByName("unoid");
1565 if (str == ref_name)
1566 daysNode = getChildAt(j)->getChildAt(0);
1569 if (!ref_name.isEmpty() && daysNode == nullptr) {
1570 of.writeParameter("dayRef", "ref", i);
1571 of.writeParameter("dayRefName", ref_name, i);
1572 nbOfDays[i] = 0;
1573 } else {
1574 if (daysNode == nullptr)
1575 daysNode = calNode -> getChildAt(nChild);
1576 nbOfDays[i] = sal::static_int_cast<sal_Int16>( daysNode->getNumberOfChildren() );
1577 if (bGregorian && nbOfDays[i] != 7)
1578 incErrorInt( "Error: A Gregorian calendar must have 7 days per week, this one has %d\n", nbOfDays[i]);
1579 elementTag = "day";
1580 for (j = 0; j < nbOfDays[i]; j++) {
1581 LocaleNode *currNode = daysNode -> getChildAt(j);
1582 OUString dayID( currNode->getChildAt(0)->getValue());
1583 of.writeParameter("dayID", dayID, i, j);
1584 if ( j == 0 && bGregorian && dayID != "sun" )
1585 incError( "First day of a week of a Gregorian calendar must be <DayID>sun</DayID>");
1586 lcl_writeAbbrFullNarrNames( of, currNode, elementTag, i, j);
1589 ++nChild;
1591 // Generate Months of Year
1592 LocaleNode * monthsNode = nullptr;
1593 ref_name = calNode->getChildAt(nChild)->getAttr().getValueByName("ref");
1594 ref_name = ref_name.replace( '-', '_');
1595 if (!ref_name.isEmpty() && i > 0) {
1596 for (j = 0; j < i; j++) {
1597 str = getChildAt(j)->getAttr().getValueByName("unoid");
1598 if (str == ref_name)
1599 monthsNode = getChildAt(j)->getChildAt(1);
1602 if (!ref_name.isEmpty() && monthsNode == nullptr) {
1603 of.writeParameter("monthRef", "ref", i);
1604 of.writeParameter("monthRefName", ref_name, i);
1605 nbOfMonths[i] = 0;
1606 } else {
1607 if (monthsNode == nullptr)
1608 monthsNode = calNode -> getChildAt(nChild);
1609 nbOfMonths[i] = sal::static_int_cast<sal_Int16>( monthsNode->getNumberOfChildren() );
1610 if (bGregorian && nbOfMonths[i] != 12)
1611 incErrorInt( "Error: A Gregorian calendar must have 12 months, this one has %d\n", nbOfMonths[i]);
1612 elementTag = "month";
1613 for (j = 0; j < nbOfMonths[i]; j++) {
1614 LocaleNode *currNode = monthsNode -> getChildAt(j);
1615 OUString monthID( currNode->getChildAt(0)->getValue());
1616 of.writeParameter("monthID", monthID, i, j);
1617 if ( j == 0 && bGregorian && monthID != "jan" )
1618 incError( "First month of a year of a Gregorian calendar must be <MonthID>jan</MonthID>");
1619 lcl_writeAbbrFullNarrNames( of, currNode, elementTag, i, j);
1622 ++nChild;
1624 // Generate genitive Months of Year
1625 // Optional, if not present fall back to month nouns.
1626 if ( calNode->getChildAt(nChild)->getName() != "GenitiveMonths" )
1627 --nChild;
1628 LocaleNode * genitiveMonthsNode = nullptr;
1629 ref_name = calNode->getChildAt(nChild)->getAttr().getValueByName("ref");
1630 ref_name = ref_name.replace( '-', '_');
1631 if (!ref_name.isEmpty() && i > 0) {
1632 for (j = 0; j < i; j++) {
1633 str = getChildAt(j)->getAttr().getValueByName("unoid");
1634 if (str == ref_name)
1635 genitiveMonthsNode = getChildAt(j)->getChildAt(1);
1638 if (!ref_name.isEmpty() && genitiveMonthsNode == nullptr) {
1639 of.writeParameter("genitiveMonthRef", "ref", i);
1640 of.writeParameter("genitiveMonthRefName", ref_name, i);
1641 nbOfGenitiveMonths[i] = 0;
1642 } else {
1643 if (genitiveMonthsNode == nullptr)
1644 genitiveMonthsNode = calNode -> getChildAt(nChild);
1645 nbOfGenitiveMonths[i] = sal::static_int_cast<sal_Int16>( genitiveMonthsNode->getNumberOfChildren() );
1646 if (bGregorian && nbOfGenitiveMonths[i] != 12)
1647 incErrorInt( "Error: A Gregorian calendar must have 12 genitive months, this one has %d\n", nbOfGenitiveMonths[i]);
1648 elementTag = "genitiveMonth";
1649 for (j = 0; j < nbOfGenitiveMonths[i]; j++) {
1650 LocaleNode *currNode = genitiveMonthsNode -> getChildAt(j);
1651 OUString genitiveMonthID( currNode->getChildAt(0)->getValue());
1652 of.writeParameter("genitiveMonthID", genitiveMonthID, i, j);
1653 if ( j == 0 && bGregorian && genitiveMonthID != "jan" )
1654 incError( "First genitive month of a year of a Gregorian calendar must be <MonthID>jan</MonthID>");
1655 lcl_writeAbbrFullNarrNames( of, currNode, elementTag, i, j);
1658 ++nChild;
1660 // Generate partitive Months of Year
1661 // Optional, if not present fall back to genitive months, or nominative
1662 // months (nouns) if that isn't present either.
1663 if ( calNode->getChildAt(nChild)->getName() != "PartitiveMonths" )
1664 --nChild;
1665 LocaleNode * partitiveMonthsNode = nullptr;
1666 ref_name = calNode->getChildAt(nChild)->getAttr().getValueByName("ref");
1667 ref_name = ref_name.replace( '-', '_');
1668 if (!ref_name.isEmpty() && i > 0) {
1669 for (j = 0; j < i; j++) {
1670 str = getChildAt(j)->getAttr().getValueByName("unoid");
1671 if (str == ref_name)
1672 partitiveMonthsNode = getChildAt(j)->getChildAt(1);
1675 if (!ref_name.isEmpty() && partitiveMonthsNode == nullptr) {
1676 of.writeParameter("partitiveMonthRef", "ref", i);
1677 of.writeParameter("partitiveMonthRefName", ref_name, i);
1678 nbOfPartitiveMonths[i] = 0;
1679 } else {
1680 if (partitiveMonthsNode == nullptr)
1681 partitiveMonthsNode = calNode -> getChildAt(nChild);
1682 nbOfPartitiveMonths[i] = sal::static_int_cast<sal_Int16>( partitiveMonthsNode->getNumberOfChildren() );
1683 if (bGregorian && nbOfPartitiveMonths[i] != 12)
1684 incErrorInt( "Error: A Gregorian calendar must have 12 partitive months, this one has %d\n", nbOfPartitiveMonths[i]);
1685 elementTag = "partitiveMonth";
1686 for (j = 0; j < nbOfPartitiveMonths[i]; j++) {
1687 LocaleNode *currNode = partitiveMonthsNode -> getChildAt(j);
1688 OUString partitiveMonthID( currNode->getChildAt(0)->getValue());
1689 of.writeParameter("partitiveMonthID", partitiveMonthID, i, j);
1690 if ( j == 0 && bGregorian && partitiveMonthID != "jan" )
1691 incError( "First partitive month of a year of a Gregorian calendar must be <MonthID>jan</MonthID>");
1692 lcl_writeAbbrFullNarrNames( of, currNode, elementTag, i, j);
1695 ++nChild;
1697 // Generate Era name
1698 LocaleNode * erasNode = nullptr;
1699 ref_name = calNode -> getChildAt(nChild) ->getAttr().getValueByName("ref");
1700 ref_name = ref_name.replace( '-', '_');
1701 if (!ref_name.isEmpty() && i > 0) {
1702 for (j = 0; j < i; j++) {
1703 str = getChildAt(j)->getAttr().getValueByName("unoid");
1704 if (str == ref_name)
1705 erasNode = getChildAt(j)->getChildAt(2);
1708 if (!ref_name.isEmpty() && erasNode == nullptr) {
1709 of.writeParameter("eraRef", "ref", i);
1710 of.writeParameter("eraRefName", ref_name, i);
1711 nbOfEras[i] = 0;
1712 } else {
1713 if (erasNode == nullptr)
1714 erasNode = calNode -> getChildAt(nChild);
1715 nbOfEras[i] = sal::static_int_cast<sal_Int16>( erasNode->getNumberOfChildren() );
1716 if (bGregorian && nbOfEras[i] != 2)
1717 incErrorInt( "Error: A Gregorian calendar must have 2 eras, this one has %d\n", nbOfEras[i]);
1718 elementTag = "era";
1719 for (j = 0; j < nbOfEras[i]; j++) {
1720 LocaleNode *currNode = erasNode -> getChildAt(j);
1721 OUString eraID( currNode->getChildAt(0)->getValue());
1722 of.writeParameter("eraID", eraID, i, j);
1723 if ( j == 0 && bGregorian && eraID != "bc" )
1724 incError( "First era of a Gregorian calendar must be <EraID>bc</EraID>");
1725 if ( j == 1 && bGregorian && eraID != "ad" )
1726 incError( "Second era of a Gregorian calendar must be <EraID>ad</EraID>");
1727 of.writeAsciiString("\n");
1728 of.writeParameter(elementTag, "DefaultAbbrvName",currNode->getChildAt(1)->getValue() ,i, j);
1729 of.writeParameter(elementTag, "DefaultFullName",currNode->getChildAt(2)->getValue() , i, j);
1732 ++nChild;
1734 str = calNode->getChildAt(nChild)->getChildAt(0)->getValue();
1735 if (nbOfDays[i])
1737 for (j = 0; j < nbOfDays[i]; j++)
1739 LocaleNode *currNode = daysNode->getChildAt(j);
1740 OUString dayID( currNode->getChildAt(0)->getValue());
1741 if (str == dayID)
1742 break; // for
1744 if (j >= nbOfDays[i])
1745 incErrorStr( "Error: <StartDayOfWeek> <DayID> must be one of the <DaysOfWeek>, but is: %s\n", str);
1747 of.writeParameter("startDayOfWeek", str, i);
1748 ++nChild;
1750 str = calNode ->getChildAt(nChild)-> getValue();
1751 sal_Int16 nDays = sal::static_int_cast<sal_Int16>( str.toInt32() );
1752 if (nDays < 1 || (0 < nbOfDays[i] && nbOfDays[i] < nDays))
1753 incErrorInt( "Error: Bad value of MinimalDaysInFirstWeek: %d, must be 1 <= value <= days_in_week\n", nDays);
1754 of.writeIntParameter("minimalDaysInFirstWeek", i, nDays);
1756 if (!bHasGregorian)
1757 fprintf( stderr, "Warning: %s\n", "No Gregorian calendar defined, are you sure?");
1759 of.writeAsciiString("static const sal_Int16 calendarsCount = ");
1760 of.writeInt(nbOfCalendars);
1761 of.writeAsciiString(";\n\n");
1763 of.writeAsciiString("static const sal_Unicode nbOfDays[] = {");
1764 for(i = 0; i < nbOfCalendars - 1; i++) {
1765 of.writeInt(nbOfDays[i]);
1766 of.writeAsciiString(", ");
1768 of.writeInt(nbOfDays[i]);
1769 of.writeAsciiString("};\n");
1771 of.writeAsciiString("static const sal_Unicode nbOfMonths[] = {");
1772 for(i = 0; i < nbOfCalendars - 1; i++) {
1773 of.writeInt(nbOfMonths[i]);
1774 of.writeAsciiString(", ");
1776 of.writeInt(nbOfMonths[i]);
1777 of.writeAsciiString("};\n");
1779 of.writeAsciiString("static const sal_Unicode nbOfGenitiveMonths[] = {");
1780 for(i = 0; i < nbOfCalendars - 1; i++) {
1781 of.writeInt(nbOfGenitiveMonths[i]);
1782 of.writeAsciiString(", ");
1784 of.writeInt(nbOfGenitiveMonths[i]);
1785 of.writeAsciiString("};\n");
1787 of.writeAsciiString("static const sal_Unicode nbOfPartitiveMonths[] = {");
1788 for(i = 0; i < nbOfCalendars - 1; i++) {
1789 of.writeInt(nbOfPartitiveMonths[i]);
1790 of.writeAsciiString(", ");
1792 of.writeInt(nbOfPartitiveMonths[i]);
1793 of.writeAsciiString("};\n");
1795 of.writeAsciiString("static const sal_Unicode nbOfEras[] = {");
1796 for(i = 0; i < nbOfCalendars - 1; i++) {
1797 of.writeInt(nbOfEras[i]);
1798 of.writeAsciiString(", ");
1800 of.writeInt(nbOfEras[i]);
1801 of.writeAsciiString("};\n");
1804 of.writeAsciiString("static const sal_Unicode* calendars[] = {\n");
1805 of.writeAsciiString("\tnbOfDays,\n");
1806 of.writeAsciiString("\tnbOfMonths,\n");
1807 of.writeAsciiString("\tnbOfGenitiveMonths,\n");
1808 of.writeAsciiString("\tnbOfPartitiveMonths,\n");
1809 of.writeAsciiString("\tnbOfEras,\n");
1810 for(i = 0; i < nbOfCalendars; i++) {
1811 of.writeAsciiString("\tcalendarID");
1812 of.writeInt(i);
1813 of.writeAsciiString(",\n");
1814 of.writeAsciiString("\tdefaultCalendar");
1815 of.writeInt(i);
1816 of.writeAsciiString(",\n");
1817 lcl_writeAbbrFullNarrArrays( of, nbOfDays[i], "day", i, true);
1818 lcl_writeAbbrFullNarrArrays( of, nbOfMonths[i], "month", i, true);
1819 lcl_writeAbbrFullNarrArrays( of, nbOfGenitiveMonths[i], "genitiveMonth", i, true);
1820 lcl_writeAbbrFullNarrArrays( of, nbOfPartitiveMonths[i], "partitiveMonth", i, true);
1821 lcl_writeAbbrFullNarrArrays( of, nbOfEras[i], "era", i, false /*noNarrow*/);
1822 of.writeAsciiString("\tstartDayOfWeek");of.writeInt(i); of.writeAsciiString(",\n");
1823 of.writeAsciiString("\tminimalDaysInFirstWeek");of.writeInt(i); of.writeAsciiString(",\n");
1826 of.writeAsciiString("};\n\n");
1827 of.writeFunction("getAllCalendars_", "calendarsCount", "calendars");
1830 static bool isIso4217( const OUString& rStr )
1832 const sal_Unicode* p = rStr.getStr();
1833 return rStr.getLength() == 3
1834 && 'A' <= p[0] && p[0] <= 'Z'
1835 && 'A' <= p[1] && p[1] <= 'Z'
1836 && 'A' <= p[2] && p[2] <= 'Z'
1840 void LCCurrencyNode::generateCode (const OFileWriter &of) const
1842 OUString useLocale = getAttr().getValueByName("ref");
1843 if (!useLocale.isEmpty()) {
1844 useLocale = useLocale.replace( '-', '_');
1845 of.writeRefFunction("getAllCurrencies_", useLocale);
1846 return;
1848 sal_Int16 nbOfCurrencies = 0;
1849 OUString str;
1851 bool bTheDefault= false;
1852 bool bTheCompatible = false;
1853 for ( sal_Int32 i = 0; i < getNumberOfChildren(); i++,nbOfCurrencies++) {
1854 LocaleNode * currencyNode = getChildAt (i);
1855 str = currencyNode->getAttr().getValueByName("default");
1856 bool bDefault = of.writeDefaultParameter("Currency", str, nbOfCurrencies);
1857 str = currencyNode->getAttr().getValueByName("usedInCompatibleFormatCodes");
1858 bool bCompatible = of.writeDefaultParameter("CurrencyUsedInCompatibleFormatCodes", str, nbOfCurrencies);
1859 str = currencyNode->getAttr().getValueByName("legacyOnly");
1860 bool bLegacy = of.writeDefaultParameter("CurrencyLegacyOnly", str, nbOfCurrencies);
1861 if (bLegacy && (bDefault || bCompatible))
1862 incError( "Currency: if legacyOnly==true, both 'default' and 'usedInCompatibleFormatCodes' must be false.");
1863 if (bDefault)
1865 if (bTheDefault)
1866 incError( "Currency: more than one default currency.");
1867 bTheDefault = true;
1869 if (bCompatible)
1871 if (bTheCompatible)
1872 incError( "Currency: more than one currency flagged as usedInCompatibleFormatCodes.");
1873 bTheCompatible = true;
1875 str = currencyNode -> findNode ("CurrencyID") -> getValue();
1876 of.writeParameter("currencyID", str, nbOfCurrencies);
1877 // CurrencyID MUST be ISO 4217.
1878 if (!bLegacy && !isIso4217(str))
1879 incError( "CurrencyID is not ISO 4217");
1880 str = currencyNode -> findNode ("CurrencySymbol") -> getValue();
1881 of.writeParameter("currencySymbol", str, nbOfCurrencies);
1882 // Check if this currency really is the one used in number format
1883 // codes. In case of ref=... mechanisms it may be that TheCurrency
1884 // couldn't had been determined from the current locale (i.e. is
1885 // empty), silently assume the referred locale has things right.
1886 if (bCompatible && !sTheCompatibleCurrency.isEmpty() && sTheCompatibleCurrency != str)
1887 incErrorStrStr( "Error: CurrencySymbol \"%s\" flagged as usedInCompatibleFormatCodes doesn't match \"%s\" determined from format codes.\n", str, sTheCompatibleCurrency);
1888 str = currencyNode -> findNode ("BankSymbol") -> getValue();
1889 of.writeParameter("bankSymbol", str, nbOfCurrencies);
1890 // BankSymbol currently must be ISO 4217. May change later if
1891 // application always uses CurrencyID instead of BankSymbol.
1892 if (!bLegacy && !isIso4217(str))
1893 incError( "BankSymbol is not ISO 4217");
1894 str = currencyNode -> findNode ("CurrencyName") -> getValue();
1895 of.writeParameter("currencyName", str, nbOfCurrencies);
1896 str = currencyNode -> findNode ("DecimalPlaces") -> getValue();
1897 sal_Int16 nDecimalPlaces = static_cast<sal_Int16>(str.toInt32());
1898 of.writeIntParameter("currencyDecimalPlaces", nbOfCurrencies, nDecimalPlaces);
1899 of.writeAsciiString("\n");
1902 if (!bTheDefault)
1903 incError( "Currency: no default currency.");
1904 if (!bTheCompatible)
1905 incError( "Currency: no currency flagged as usedInCompatibleFormatCodes.");
1907 of.writeAsciiString("static const sal_Int16 currencyCount = ");
1908 of.writeInt(nbOfCurrencies);
1909 of.writeAsciiString(";\n\n");
1910 of.writeAsciiString("static const sal_Unicode* currencies[] = {\n");
1911 for(sal_Int16 i = 0; i < nbOfCurrencies; i++) {
1912 of.writeAsciiString("\tcurrencyID");
1913 of.writeInt(i);
1914 of.writeAsciiString(",\n");
1915 of.writeAsciiString("\tcurrencySymbol");
1916 of.writeInt(i);
1917 of.writeAsciiString(",\n");
1918 of.writeAsciiString("\tbankSymbol");
1919 of.writeInt(i);
1920 of.writeAsciiString(",\n");
1921 of.writeAsciiString("\tcurrencyName");
1922 of.writeInt(i);
1923 of.writeAsciiString(",\n");
1924 of.writeAsciiString("\tdefaultCurrency");
1925 of.writeInt(i);
1926 of.writeAsciiString(",\n");
1927 of.writeAsciiString("\tdefaultCurrencyUsedInCompatibleFormatCodes");
1928 of.writeInt(i);
1929 of.writeAsciiString(",\n");
1930 of.writeAsciiString("\tcurrencyDecimalPlaces");
1931 of.writeInt(i);
1932 of.writeAsciiString(",\n");
1933 of.writeAsciiString("\tdefaultCurrencyLegacyOnly");
1934 of.writeInt(i);
1935 of.writeAsciiString(",\n");
1937 of.writeAsciiString("};\n\n");
1938 of.writeFunction("getAllCurrencies_", "currencyCount", "currencies");
1941 void LCTransliterationNode::generateCode (const OFileWriter &of) const
1943 OUString useLocale = getAttr().getValueByName("ref");
1944 if (!useLocale.isEmpty()) {
1945 useLocale = useLocale.replace( '-', '_');
1946 of.writeRefFunction("getTransliterations_", useLocale);
1947 return;
1949 sal_Int16 nbOfModules = 0;
1950 OUString str;
1952 for ( sal_Int32 i = 0; i < getNumberOfChildren(); i++,nbOfModules++) {
1953 LocaleNode * transNode = getChildAt (i);
1954 str = transNode->getAttr().getValueByIndex(0);
1955 of.writeParameter("Transliteration", str, nbOfModules);
1957 of.writeAsciiString("static const sal_Int16 nbOfTransliterations = ");
1958 of.writeInt(nbOfModules);
1959 of.writeAsciiString(";\n\n");
1961 of.writeAsciiString("\nstatic const sal_Unicode* LCTransliterationsArray[] = {\n");
1962 for( sal_Int16 i = 0; i < nbOfModules; i++) {
1963 of.writeAsciiString("\tTransliteration");
1964 of.writeInt(i);
1965 of.writeAsciiString(",\n");
1967 of.writeAsciiString("};\n\n");
1968 of.writeFunction("getTransliterations_", "nbOfTransliterations", "LCTransliterationsArray");
1971 struct NameValuePair {
1972 const sal_Char *name;
1973 const sal_Char *value;
1975 static const NameValuePair ReserveWord[] = {
1976 { "trueWord", "true" },
1977 { "falseWord", "false" },
1978 { "quarter1Word", "1st quarter" },
1979 { "quarter2Word", "2nd quarter" },
1980 { "quarter3Word", "3rd quarter" },
1981 { "quarter4Word", "4th quarter" },
1982 { "aboveWord", "above" },
1983 { "belowWord", "below" },
1984 { "quarter1Abbreviation", "Q1" },
1985 { "quarter2Abbreviation", "Q2" },
1986 { "quarter3Abbreviation", "Q3" },
1987 { "quarter4Abbreviation", "Q4" }
1990 void LCMiscNode::generateCode (const OFileWriter &of) const
1992 OUString useLocale = getAttr().getValueByName("ref");
1993 if (!useLocale.isEmpty()) {
1994 useLocale = useLocale.replace( '-', '_');
1995 of.writeRefFunction("getForbiddenCharacters_", useLocale);
1996 of.writeRefFunction("getBreakIteratorRules_", useLocale);
1997 of.writeRefFunction("getReservedWords_", useLocale);
1998 return;
2000 const LocaleNode * reserveNode = findNode("ReservedWords");
2001 if (!reserveNode)
2002 incError( "No ReservedWords element."); // should not happen if validated..
2003 const LocaleNode * forbidNode = findNode("ForbiddenCharacters");
2004 const LocaleNode * breakNode = findNode("BreakIteratorRules");
2006 bool bEnglishLocale = (strncmp( of.getLocale(), "en_", 3) == 0);
2008 sal_Int16 nbOfWords = 0;
2009 OUString str;
2010 sal_Int16 i;
2012 for ( i = 0; i < sal_Int16(SAL_N_ELEMENTS(ReserveWord)); i++,nbOfWords++) {
2013 const LocaleNode * curNode = (reserveNode ? reserveNode->findNode(
2014 ReserveWord[i].name) : nullptr);
2015 if (!curNode)
2016 fprintf( stderr,
2017 "Warning: No %s in ReservedWords, using en_US default: \"%s\".\n",
2018 ReserveWord[i].name, ReserveWord[i].value);
2019 str = curNode ? curNode -> getValue() : OUString::createFromAscii(ReserveWord[i].value);
2020 if (str.isEmpty())
2022 ++nError;
2023 fprintf( stderr, "Error: No content for ReservedWords %s.\n", ReserveWord[i].name);
2025 of.writeParameter("ReservedWord", str, nbOfWords);
2026 // "true", ..., "below" trigger untranslated warning.
2027 if (!bEnglishLocale && curNode && i <= 7 &&
2028 str.equalsIgnoreAsciiCaseAscii( ReserveWord[i].value))
2030 fprintf( stderr,
2031 "Warning: ReservedWord %s seems to be untranslated \"%s\".\n",
2032 ReserveWord[i].name, ReserveWord[i].value);
2035 of.writeAsciiString("static const sal_Int16 nbOfReservedWords = ");
2036 of.writeInt(nbOfWords);
2037 of.writeAsciiString(";\n\n");
2038 of.writeAsciiString("\nstatic const sal_Unicode* LCReservedWordsArray[] = {\n");
2039 for( i = 0; i < nbOfWords; i++) {
2040 of.writeAsciiString("\tReservedWord");
2041 of.writeInt(i);
2042 of.writeAsciiString(",\n");
2044 of.writeAsciiString("};\n\n");
2045 of.writeFunction("getReservedWords_", "nbOfReservedWords", "LCReservedWordsArray");
2047 if (forbidNode) {
2048 of.writeParameter( "forbiddenBegin", forbidNode -> getChildAt(0)->getValue());
2049 of.writeParameter( "forbiddenEnd", forbidNode -> getChildAt(1)->getValue());
2050 of.writeParameter( "hangingChars", forbidNode -> getChildAt(2)->getValue());
2051 } else {
2052 of.writeParameter( "forbiddenBegin", OUString());
2053 of.writeParameter( "forbiddenEnd", OUString());
2054 of.writeParameter( "hangingChars", OUString());
2056 of.writeAsciiString("\nstatic const sal_Unicode* LCForbiddenCharactersArray[] = {\n");
2057 of.writeAsciiString("\tforbiddenBegin,\n");
2058 of.writeAsciiString("\tforbiddenEnd,\n");
2059 of.writeAsciiString("\thangingChars\n");
2060 of.writeAsciiString("};\n\n");
2061 of.writeFunction("getForbiddenCharacters_", "3", "LCForbiddenCharactersArray");
2063 if (breakNode) {
2064 of.writeParameter( "EditMode", breakNode -> getChildAt(0)->getValue());
2065 of.writeParameter( "DictionaryMode", breakNode -> getChildAt(1)->getValue());
2066 of.writeParameter( "WordCountMode", breakNode -> getChildAt(2)->getValue());
2067 of.writeParameter( "CharacterMode", breakNode -> getChildAt(3)->getValue());
2068 of.writeParameter( "LineMode", breakNode -> getChildAt(4)->getValue());
2069 } else {
2070 of.writeParameter( "EditMode", OUString());
2071 of.writeParameter( "DictionaryMode", OUString());
2072 of.writeParameter( "WordCountMode", OUString());
2073 of.writeParameter( "CharacterMode", OUString());
2074 of.writeParameter( "LineMode", OUString());
2076 of.writeAsciiString("\nstatic const sal_Unicode* LCBreakIteratorRulesArray[] = {\n");
2077 of.writeAsciiString("\tEditMode,\n");
2078 of.writeAsciiString("\tDictionaryMode,\n");
2079 of.writeAsciiString("\tWordCountMode,\n");
2080 of.writeAsciiString("\tCharacterMode,\n");
2081 of.writeAsciiString("\tLineMode\n");
2082 of.writeAsciiString("};\n\n");
2083 of.writeFunction("getBreakIteratorRules_", "5", "LCBreakIteratorRulesArray");
2087 void LCNumberingLevelNode::generateCode (const OFileWriter &of) const
2089 of.writeAsciiString("// ---> ContinuousNumbering\n");
2090 OUString useLocale = getAttr().getValueByName("ref");
2091 if (!useLocale.isEmpty()) {
2092 useLocale = useLocale.replace( '-', '_');
2093 of.writeRefFunction2("getContinuousNumberingLevels_", useLocale);
2094 return;
2097 // hard code number of attributes per style.
2098 const int nAttributes = 5;
2099 const char* attr[ nAttributes ] = { "Prefix", "NumType", "Suffix", "Transliteration", "NatNum" };
2101 // record each attribute of each style in a static C++ variable.
2102 // determine number of styles on the fly.
2103 sal_Int32 nStyles = getNumberOfChildren();
2104 sal_Int32 i;
2106 for( i = 0; i < nStyles; ++i )
2108 const Attr &q = getChildAt( i )->getAttr();
2109 for( sal_Int32 j=0; j<nAttributes; ++j )
2111 const char* name = attr[j];
2112 OUString value = q.getValueByName( name );
2113 of.writeParameter("continuous", name, value, sal::static_int_cast<sal_Int16>(i) );
2117 // record number of styles and attributes.
2118 of.writeAsciiString("static const sal_Int16 continuousNbOfStyles = ");
2119 of.writeInt( sal::static_int_cast<sal_Int16>( nStyles ) );
2120 of.writeAsciiString(";\n\n");
2121 of.writeAsciiString("static const sal_Int16 continuousNbOfAttributesPerStyle = ");
2122 of.writeInt( nAttributes );
2123 of.writeAsciiString(";\n\n");
2125 // generate code. (intermediate arrays)
2126 for( i=0; i<nStyles; i++ )
2128 of.writeAsciiString("\nstatic const sal_Unicode* continuousStyle" );
2129 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
2130 of.writeAsciiString("[] = {\n");
2131 for( sal_Int32 j=0; j<nAttributes; j++)
2133 of.writeAsciiString("\t");
2134 of.writeAsciiString( "continuous" );
2135 of.writeAsciiString( attr[j] );
2136 of.writeInt(sal::static_int_cast<sal_Int16>(i));
2137 of.writeAsciiString(",\n");
2139 of.writeAsciiString("\t0\n};\n\n");
2142 // generate code. (top-level array)
2143 of.writeAsciiString("\n");
2144 of.writeAsciiString("static const sal_Unicode** LCContinuousNumberingLevelsArray[] = {\n" );
2145 for( i=0; i<nStyles; i++ )
2147 of.writeAsciiString( "\t" );
2148 of.writeAsciiString( "continuousStyle" );
2149 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
2150 of.writeAsciiString( ",\n");
2152 of.writeAsciiString("\t0\n};\n\n");
2153 of.writeFunction2("getContinuousNumberingLevels_", "continuousNbOfStyles",
2154 "continuousNbOfAttributesPerStyle", "LCContinuousNumberingLevelsArray");
2158 void LCOutlineNumberingLevelNode::generateCode (const OFileWriter &of) const
2160 of.writeAsciiString("// ---> OutlineNumbering\n");
2161 OUString useLocale = getAttr().getValueByName("ref");
2162 if (!useLocale.isEmpty()) {
2163 useLocale = useLocale.replace( '-', '_');
2164 of.writeRefFunction3("getOutlineNumberingLevels_", useLocale);
2165 return;
2168 // hardcode number of attributes per level
2169 const int nAttributes = 11;
2170 const char* attr[ nAttributes ] =
2172 "Prefix",
2173 "NumType",
2174 "Suffix",
2175 "BulletChar",
2176 "BulletFontName",
2177 "ParentNumbering",
2178 "LeftMargin",
2179 "SymbolTextDistance",
2180 "FirstLineOffset",
2181 "Transliteration",
2182 "NatNum",
2185 // record each attribute of each level of each style in a static C++ variable.
2186 // determine number of styles and number of levels per style on the fly.
2187 sal_Int32 nStyles = getNumberOfChildren();
2188 vector<sal_Int32> nLevels; // may be different for each style?
2189 for( sal_Int32 i = 0; i < nStyles; i++ )
2191 LocaleNode* p = getChildAt( i );
2192 nLevels.push_back( p->getNumberOfChildren() );
2193 for( sal_Int32 j=0; j<nLevels.back(); j++ )
2195 const Attr& q = p->getChildAt( j )->getAttr();
2196 for( sal_Int32 k=0; k<nAttributes; ++k )
2198 const char* name = attr[k];
2199 OUString value = q.getValueByName( name );
2200 of.writeParameter("outline", name, value,
2201 sal::static_int_cast<sal_Int16>(i),
2202 sal::static_int_cast<sal_Int16>(j) );
2207 // verify that each style has the same number of levels.
2208 for( size_t i=0; i<nLevels.size(); i++ )
2210 if( nLevels[0] != nLevels[i] )
2212 incError( "Numbering levels don't match.");
2216 // record number of attributes, levels, and styles.
2217 of.writeAsciiString("static const sal_Int16 outlineNbOfStyles = ");
2218 of.writeInt( sal::static_int_cast<sal_Int16>( nStyles ) );
2219 of.writeAsciiString(";\n\n");
2220 of.writeAsciiString("static const sal_Int16 outlineNbOfLevelsPerStyle = ");
2221 of.writeInt( sal::static_int_cast<sal_Int16>( nLevels.back() ) );
2222 of.writeAsciiString(";\n\n");
2223 of.writeAsciiString("static const sal_Int16 outlineNbOfAttributesPerLevel = ");
2224 of.writeInt( nAttributes );
2225 of.writeAsciiString(";\n\n");
2227 // too complicated for now...
2228 // of.writeAsciiString("static const sal_Int16 nbOfOutlineNumberingLevels[] = { ");
2229 // for( sal_Int32 j=0; j<nStyles; j++ )
2230 // {
2231 // of.writeInt( nLevels[j] );
2232 // of.writeAsciiString(", ");
2233 // }
2234 // of.writeAsciiString("};\n\n");
2237 for( sal_Int32 i=0; i<nStyles; i++ )
2239 for( sal_Int32 j=0; j<nLevels.back(); j++ )
2241 of.writeAsciiString("static const sal_Unicode* outline");
2242 of.writeAsciiString("Style");
2243 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
2244 of.writeAsciiString("Level");
2245 of.writeInt( sal::static_int_cast<sal_Int16>(j) );
2246 of.writeAsciiString("[] = { ");
2248 for( sal_Int32 k=0; k<nAttributes; k++ )
2250 of.writeAsciiString( "outline" );
2251 of.writeAsciiString( attr[k] );
2252 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
2253 of.writeInt( sal::static_int_cast<sal_Int16>(j) );
2254 of.writeAsciiString(", ");
2256 of.writeAsciiString("NULL };\n");
2260 of.writeAsciiString("\n");
2263 for( sal_Int32 i=0; i<nStyles; i++ )
2265 of.writeAsciiString("static const sal_Unicode** outline");
2266 of.writeAsciiString( "Style" );
2267 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
2268 of.writeAsciiString("[] = { ");
2270 for( sal_Int32 j=0; j<nLevels.back(); j++ )
2272 of.writeAsciiString("outlineStyle");
2273 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
2274 of.writeAsciiString("Level");
2275 of.writeInt( sal::static_int_cast<sal_Int16>(j) );
2276 of.writeAsciiString(", ");
2278 of.writeAsciiString("NULL };\n");
2280 of.writeAsciiString("\n");
2282 of.writeAsciiString("static const sal_Unicode*** LCOutlineNumberingLevelsArray[] = {\n" );
2283 for( sal_Int32 i=0; i<nStyles; i++ )
2285 of.writeAsciiString( "\t" );
2286 of.writeAsciiString( "outlineStyle" );
2287 of.writeInt( sal::static_int_cast<sal_Int16>(i) );
2288 of.writeAsciiString(",\n");
2290 of.writeAsciiString("\tNULL\n};\n\n");
2291 of.writeFunction3("getOutlineNumberingLevels_", "outlineNbOfStyles", "outlineNbOfLevelsPerStyle",
2292 "outlineNbOfAttributesPerLevel", "LCOutlineNumberingLevelsArray");
2295 Attr::Attr (const Reference< XAttributeList > & attr) {
2296 sal_Int16 len = attr->getLength();
2297 name.realloc (len);
2298 value.realloc (len);
2299 for (sal_Int16 i =0; i< len;i++) {
2300 name[i] = attr->getNameByIndex(i);
2301 value[i] = attr -> getValueByIndex(i);
2305 OUString Attr::getValueByName (const sal_Char *str) const {
2306 sal_Int32 len = name.getLength();
2307 for (sal_Int32 i = 0;i<len;i++)
2308 if (name[i].equalsAscii(str))
2309 return value[i];
2310 return OUString();
2313 const OUString& Attr::getValueByIndex (sal_Int32 idx) const
2315 return value[idx];
2318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */