i18npool/source/localedata/LocaleNode.cxx |   63 ++++++++++++++++++++----------
 i18npool/source/localedata/LocaleNode.hxx |    3 +
 2 files changed, 46 insertions(+), 20 deletions(-)

New commits:
commit 998c0845e6a4fdcfdfee59af59dd997fc99a23f0
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Thu Mar 12 20:34:07 2020 +0100
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Sun Mar 15 18:23:04 2020 +0100

    Check for some more expected calendar elements
    
    Change-Id: I615ffc60fcc235fcc84848a22fd7bd3b0d8179d1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90441
    Tested-by: Jenkins
    Reviewed-by: Eike Rathke <er...@redhat.com>

diff --git a/i18npool/source/localedata/LocaleNode.cxx 
b/i18npool/source/localedata/LocaleNode.cxx
index 558967cbc978..38c0bce2055d 100644
--- a/i18npool/source/localedata/LocaleNode.cxx
+++ b/i18npool/source/localedata/LocaleNode.cxx
@@ -1527,6 +1527,24 @@ static void lcl_writeAbbrFullNarrArrays( const 
OFileWriter & of, sal_Int16 nCoun
     }
 }
 
+bool LCCalendarNode::expectedCalendarElement( const OUString& rName,
+        const LocaleNode* pNode, sal_Int16 nChild, const OUString& rCalendarID 
) const
+{
+    bool bFound = true;
+    if (nChild >= 0)
+    {
+        if (nChild >= pNode->getNumberOfChildren())
+            bFound = false;
+        else
+            pNode = pNode->getChildAt(nChild);
+    }
+    if (bFound && (!pNode || pNode->getName() != rName))
+        bFound = false;
+    if (!bFound)
+        incErrorStrStr( "Error: <%s> element expected in calendar '%s'\n", 
rName, rCalendarID);
+    return bFound;
+}
+
 void LCCalendarNode::generateCode (const OFileWriter &of) const
 {
     OUString useLocale =   getAttr().getValueByName("ref");
@@ -1717,9 +1735,8 @@ void LCCalendarNode::generateCode (const OFileWriter &of) 
const
         } else {
             if (erasNode == nullptr)
                 erasNode = calNode -> getChildAt(nChild);
-            if (!erasNode || erasNode->getName() != "Eras")
+            if (!expectedCalendarElement("Eras", erasNode, -1, calendarID))
             {
-                incErrorStr( "Error: <Eras> element expected in calendar 
'%s'\n", calendarID);
                 --nChild;
             }
             else
@@ -1730,9 +1747,8 @@ void LCCalendarNode::generateCode (const OFileWriter &of) 
const
                 elementTag = "era";
                 for (j = 0; j < nbOfEras[i]; j++) {
                     LocaleNode *currNode = erasNode -> getChildAt(j);
-                    if (!currNode || currNode->getName() != "Era")
+                    if (!expectedCalendarElement("Era", currNode, -1, 
calendarID))
                     {
-                        incError("<Era> element expected");
                         continue;   // for
                     }
                     OUString eraID( currNode->getChildAt(0)->getValue());
@@ -1749,27 +1765,34 @@ void LCCalendarNode::generateCode (const OFileWriter 
&of) const
         }
         ++nChild;
 
-        str = calNode->getChildAt(nChild)->getChildAt(0)->getValue();
-        if (nbOfDays[i])
+        if (expectedCalendarElement("StartDayOfWeek", calNode, nChild, 
calendarID))
         {
-            for (j = 0; j < nbOfDays[i]; j++)
+            str = calNode->getChildAt(nChild)->getChildAt(0)->getValue();
+            if (nbOfDays[i])
             {
-                LocaleNode *currNode = daysNode->getChildAt(j);
-                OUString dayID( currNode->getChildAt(0)->getValue());
-                if (str == dayID)
-                    break;  // for
+                for (j = 0; j < nbOfDays[i]; j++)
+                {
+                    LocaleNode *currNode = daysNode->getChildAt(j);
+                    OUString dayID( currNode->getChildAt(0)->getValue());
+                    if (str == dayID)
+                        break;  // for
+                }
+                if (j >= nbOfDays[i])
+                    incErrorStr( "Error: <StartDayOfWeek> <DayID> must be one 
of the <DaysOfWeek>, but is: %s\n", str);
             }
-            if (j >= nbOfDays[i])
-                incErrorStr( "Error: <StartDayOfWeek> <DayID> must be one of 
the <DaysOfWeek>, but is: %s\n", str);
+            of.writeParameter("startDayOfWeek", str, i);
+            ++nChild;
         }
-        of.writeParameter("startDayOfWeek", str, i);
-        ++nChild;
 
-        str = calNode ->getChildAt(nChild)-> getValue();
-        sal_Int16 nDays = sal::static_int_cast<sal_Int16>( str.toInt32() );
-        if (nDays < 1 || (0 < nbOfDays[i] && nbOfDays[i] < nDays))
-            incErrorInt( "Error: Bad value of MinimalDaysInFirstWeek: %d, must 
be 1 <= value <= days_in_week\n",  nDays);
-        of.writeIntParameter("minimalDaysInFirstWeek", i, nDays);
+        if (expectedCalendarElement("MinimalDaysInFirstWeek", calNode, nChild, 
calendarID))
+        {
+            str = calNode ->getChildAt(nChild)-> getValue();
+            sal_Int16 nDays = sal::static_int_cast<sal_Int16>( str.toInt32() );
+            if (nDays < 1 || (0 < nbOfDays[i] && nbOfDays[i] < nDays))
+                incErrorInt( "Error: Bad value of MinimalDaysInFirstWeek: %d, 
must be 1 <= value <= days_in_week\n",
+                        nDays);
+            of.writeIntParameter("minimalDaysInFirstWeek", i, nDays);
+        }
     }
     if (!bHasGregorian)
         fprintf( stderr, "Warning: %s\n", "No Gregorian calendar defined, are 
you sure?");
diff --git a/i18npool/source/localedata/LocaleNode.hxx 
b/i18npool/source/localedata/LocaleNode.hxx
index 3663478853a3..f5990fcb772b 100644
--- a/i18npool/source/localedata/LocaleNode.hxx
+++ b/i18npool/source/localedata/LocaleNode.hxx
@@ -175,6 +175,9 @@ public:
                 const Reference< XAttributeList > & attr) : LocaleNode (name, 
attr) { ; };
 
     virtual void generateCode (const OFileWriter &of) const override;
+
+    bool expectedCalendarElement( const OUString& rName,
+            const LocaleNode* pNode, sal_Int16 nChild, const OUString& 
rCalendarID ) const;
 };
 
 class LCCurrencyNode : public LocaleNode {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to