[Libreoffice-commits] .: Branch 'feature/killsdf' - l10ntools/inc l10ntools/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Oct 1 11:54:28 PDT 2012


 l10ntools/inc/po.hxx       |    2 ++
 l10ntools/source/merge.cxx |   24 +++++++++++++++++++-----
 l10ntools/source/po.cxx    |   15 ++++++++++++---
 3 files changed, 33 insertions(+), 8 deletions(-)

New commits:
commit 8b22407ef36d1a8934f3d917354d95f37d4aab65
Author: Zolnai Tamás <zolnaitamas2000 at gmail.com>
Date:   Mon Oct 1 20:26:05 2012 +0200

    Add some new checking
    
    Plus use UpperCamelCase name for some
    variable.
    
    Change-Id: Iaba8b6f47f03b723aa31ef4b45f8b6fd78b7866f

diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx
index 76312a4..9163e6a 100644
--- a/l10ntools/inc/po.hxx
+++ b/l10ntools/inc/po.hxx
@@ -113,6 +113,8 @@ public:
     friend class PoOfstream;
     friend class PoIfstream;
 
+    enum Exception { NOLANG };
+
                     PoHeader();
                     PoHeader( const OString& rExtSrc );
                     PoHeader( std::ifstream& rOldPo );
diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx
index a588075..5738565 100644
--- a/l10ntools/source/merge.cxx
+++ b/l10ntools/source/merge.cxx
@@ -165,7 +165,7 @@ MergeDataFile::MergeDataFile(
     bool bFirstLang = true;
     while( !aInputStream.eof() )
     {
-        const OString sHACK("HACK");
+        const OString sHack("HACK");
         const OString sFileName( lcl_NormalizeFilename(rFile) );
         PoIfstream aPoInput;
         aPoInput.open( OString(sPoFileName.data(), sPoFileName.length()) );
@@ -189,8 +189,22 @@ MergeDataFile::MergeDataFile(
                 return;
             }
         }
-        const OString nLANG = aPoHeader.getLanguage();
-        aLanguageSet.insert( nLANG );
+        OString sLang;
+        try
+        {
+            sLang = aPoHeader.getLanguage();
+        }
+        catch( PoHeader::Exception& aException )
+        {
+            if( aException = PoHeader::NOLANG )
+            {
+                printf(
+                    "Warning : %s' header not has language specification\n",
+                    sPoFileName.c_str() );
+                return;
+            }
+        }
+        aLanguageSet.insert( sLang );
         PoEntry aNextPo;
         do
         {
@@ -247,7 +261,7 @@ MergeDataFile::MergeDataFile(
 
             InsertEntry(
                 aActPo.getResourceType(), aActPo.getGroupId(),
-                aActPo.getLocalId(), sHACK, nLANG, sText,
+                aActPo.getLocalId(), sHack, sLang, sText,
                 sQHText, sTitle, sFileName, bCaseSensitive );
 
             if( bFirstLang )
@@ -255,7 +269,7 @@ MergeDataFile::MergeDataFile(
                 aLanguageSet.insert("qtz");
                 InsertEntry(
                     aActPo.getResourceType(), aActPo.getGroupId(),
-                    aActPo.getLocalId(), sHACK, "qtz",
+                    aActPo.getLocalId(), sHack, "qtz",
                     sQTZText + "||" + sExText, sQTZQHText + "||" + sExQHText,
                     sQTZTitle + "||" + sExTitle, sFileName, bCaseSensitive );
             }
diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx
index a922575..465e18e 100644
--- a/l10ntools/source/po.cxx
+++ b/l10ntools/source/po.cxx
@@ -537,6 +537,7 @@ void PoEntry::setFuzzy(const bool bFuzzy)
 //Check whether po-s belong to the same localization component
 bool PoEntry::IsInSameComp(const PoEntry& rPo1,const PoEntry& rPo2)
 {
+    assert( rPo1.m_bIsInitialized && rPo2.m_bIsInitialized );
     return ( rPo1.getSourceFile() == rPo2.getSourceFile() &&
              rPo1.getGroupId() == rPo2.getGroupId() &&
              rPo1.getLocalId() == rPo2.getLocalId() &&
@@ -632,7 +633,11 @@ OString PoHeader::getLanguage() const
     const OString sTransStr = m_aGenPo.getTransStr();
     const sal_Int32 nFirstIndex = sTransStr.indexOf(sLang)+sLang.getLength();
     const sal_Int32 nCount = sTransStr.indexOf('\n',nFirstIndex)-nFirstIndex;
-    return sTransStr.copy(nFirstIndex,nCount);
+    if( nFirstIndex == sLang.getLength()-1 || nCount == -nFirstIndex-1 )
+    {
+        throw NOLANG;
+    }
+    return sTransStr.copy( nFirstIndex, nCount );
 }
 
 //Class PoOfstream
@@ -741,12 +746,16 @@ void PoIfstream::readEntry( PoEntry& rPoEntry )
     else
     {
         const OString sContext = aGenPo.getContext();
+        const sal_Int32 nFirstEndLine = sContext.indexOf('\n');
+        const sal_Int32 nLastEndLine = sContext.lastIndexOf('\n');
         const sal_Int32 nLastDot = sContext.lastIndexOf('.');
         const OString sType = sContext.copy( nLastDot + 1 );
         if( !aGenPo.getReference().isEmpty() &&
-            sContext.indexOf('\n') > 0 &&
+            nFirstEndLine > 0 &&
+            (nLastEndLine == nFirstEndLine ||
+                nLastEndLine == sContext.indexOf('\n',nFirstEndLine+1)) &&
+            nLastDot - nLastEndLine > 1 &&
             (sType == "text" || sType == "quickhelptext" || sType == "title") &&
-            nLastDot - sContext.lastIndexOf('\n') > 0 &&
             !aGenPo.getUnTransStr().isEmpty() )
         {
             rPoEntry.m_aGenPo = aGenPo;


More information about the Libreoffice-commits mailing list