[Libreoffice-commits] .: l10ntools/inc l10ntools/source

Stephan Bergmann sbergmann at kemper.freedesktop.org
Fri Feb 10 12:55:29 PST 2012


 l10ntools/inc/export.hxx      |   12 +-
 l10ntools/inc/lngmerge.hxx    |    8 -
 l10ntools/source/cfgmerge.cxx |   47 ++++++----
 l10ntools/source/export.cxx   |   75 ++++++++---------
 l10ntools/source/export2.cxx  |   27 ++----
 l10ntools/source/lngmerge.cxx |  184 +++++++++++++++++++-----------------------
 l10ntools/source/makefile.mk  |    5 -
 l10ntools/source/merge.cxx    |   58 +++++--------
 8 files changed, 198 insertions(+), 218 deletions(-)

New commits:
commit b57f88ce679bba4758db98ab130548db224b6a1f
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Feb 10 21:53:20 2012 +0100

    Various more l10ntools clean up

diff --git a/l10ntools/inc/export.hxx b/l10ntools/inc/export.hxx
index e6d0057..ff6a960 100644
--- a/l10ntools/inc/export.hxx
+++ b/l10ntools/inc/export.hxx
@@ -34,8 +34,6 @@
 #include <cstddef>
 #include <fstream>
 
-#include <comphelper/string.hxx>
-
 #ifndef L10NTOOLS_DIRECTORY_HXX
 #define L10NTOOLS_DIRECTORY_HXX
 #include <l10ntools/directory.hxx>
@@ -56,6 +54,8 @@
 #include <direct.h>
 #endif
 
+#include "helper.hxx"
+
 #define NO_TRANSLATE_ISO        "x-no-translate"
 
 class PFormEntrys;
@@ -196,8 +196,8 @@ public:
             pPairedList( NULL ),
             sPForm( rPF )
     {
-        sGId = comphelper::string::remove(sGId, '\r');
-        sPForm = comphelper::string::remove(sPForm, '\r');
+        helper::searchAndReplaceAll(&sGId, "\r", rtl::OString());
+        helper::searchAndReplaceAll(&sPForm, "\r", rtl::OString());
     }
 
     ResData(const rtl::OString &rPF, const rtl::OString &rGId , const rtl::OString &rFilename)
@@ -227,8 +227,8 @@ public:
             pPairedList( NULL ),
             sPForm( rPF )
     {
-        sGId = comphelper::string::remove(sGId, '\r');
-        sPForm = comphelper::string::remove(sPForm, '\r');
+        helper::searchAndReplaceAll(&sGId, "\r", rtl::OString());
+        helper::searchAndReplaceAll(&sPForm, "\r", rtl::OString());
     }
 };
 
diff --git a/l10ntools/inc/lngmerge.hxx b/l10ntools/inc/lngmerge.hxx
index 99c852d..9649c34 100644
--- a/l10ntools/inc/lngmerge.hxx
+++ b/l10ntools/inc/lngmerge.hxx
@@ -36,11 +36,9 @@
 typedef std::vector< rtl::OString* > LngLineList;
 
 #define LNG_OK              0x0000
-#define LNG_FILE_NOTFOUND   0x0001
-#define LNG_COULD_NOT_OPEN  0x0002
-#define SDF_OK              0x0003
-#define SDF_FILE_NOTFOUND   0x0004
-#define SDF_COULD_NOT_OPEN  0x0005
+#define LNG_COULD_NOT_OPEN  0x0001
+#define SDF_OK              0x0002
+#define SDF_COULD_NOT_OPEN  0x0003
 
 //
 // class LngParser
diff --git a/l10ntools/source/cfgmerge.cxx b/l10ntools/source/cfgmerge.cxx
index 60872d8..1d15fc7 100644
--- a/l10ntools/source/cfgmerge.cxx
+++ b/l10ntools/source/cfgmerge.cxx
@@ -34,8 +34,7 @@
 #include <cstring>
 
 #include "boost/scoped_ptr.hpp"
-
-#include <comphelper/string.hxx>
+#include "rtl/strbuf.hxx"
 
 #include "common.hxx"
 #include "helper.hxx"
@@ -43,8 +42,6 @@
 #include "cfgmerge.hxx"
 #include "tokens.h"
 
-using comphelper::string::getToken;
-
 extern "C" { int yyerror(char const *); }
 
 namespace {
@@ -277,7 +274,12 @@ int CfgParser::ExecuteAnalyzedToken( int nToken, char *pToken )
         case ANYTOKEN:
         case CFG_TEXT_START:
         {
-            sTokenName = getToken(getToken(getToken(sToken, 1, '<'), 0, '>'), 0, ' ');
+            sal_Int32 n = 0;
+            rtl::OString t(sToken.getToken(1, '<', n));
+            n = 0;
+            t = t.getToken(0, '>', n);
+            n = 0;
+            sTokenName = t.getToken(0, ' ', n);
 
               if ( !IsTokenClosed( sToken )) {
                 rtl::OString sSearch;
@@ -305,15 +307,16 @@ int CfgParser::ExecuteAnalyzedToken( int nToken, char *pToken )
                         if ( sCurrentResTyp != sTokenName ) {
                             WorkOnRessourceEnd();
                             rtl::OString sCur;
-                            for( unsigned int n = 0; n < aLanguages.size(); n++ ){
-                                sCur = aLanguages[ n ];
+                            for( unsigned int i = 0; i < aLanguages.size(); ++i ){
+                                sCur = aLanguages[ i ];
                                 pStackData->sText[ sCur ] = rtl::OString();
                             }
                          }
                         sCurrentResTyp = sTokenName;
 
                         rtl::OString sTemp = sToken.copy( sToken.indexOf( "xml:lang=" ));
-                        sCurrentIsoLang = getToken(getToken(sTemp, 1, '\"'), 0, '\"');
+                        n = 0;
+                        sCurrentIsoLang = sTemp.getToken(1, '"', n);
 
                         if ( sCurrentIsoLang == NO_TRANSLATE_ISO )
                             bLocalize = sal_False;
@@ -327,7 +330,8 @@ int CfgParser::ExecuteAnalyzedToken( int nToken, char *pToken )
                 if ( !sSearch.isEmpty())
                 {
                     rtl::OString sTemp = sToken.copy( sToken.indexOf( sSearch ));
-                    sTokenId = getToken(getToken(sTemp, 1, '\"'), 0, '\"');
+                    n = 0;
+                    sTokenId = sTemp.getToken(1, '"', n);
                 }
                 pStackData = aStack.Push( sTokenName, sTokenId );
 
@@ -341,8 +345,8 @@ int CfgParser::ExecuteAnalyzedToken( int nToken, char *pToken )
                 if ( sCurrentResTyp != sTokenName ) {
                     WorkOnRessourceEnd();
                     rtl::OString sCur;
-                    for( unsigned int n = 0; n < aLanguages.size(); n++ ){
-                        sCur = aLanguages[ n ];
+                    for( unsigned int i = 0; i < aLanguages.size(); ++i ){
+                        sCur = aLanguages[ i ];
                         pStackData->sText[ sCur ] = rtl::OString();
                     }
                 }
@@ -351,7 +355,13 @@ int CfgParser::ExecuteAnalyzedToken( int nToken, char *pToken )
         }
         break;
         case CFG_CLOSETAG:
-            sTokenName = getToken(getToken(getToken(sToken, 1, '/'), 0, '>'), 0, ' ');
+        {
+            sal_Int32 n = 0;
+            rtl::OString t(sToken.getToken(1, '/', n));
+            n = 0;
+            t = t.getToken(0, '>', n);
+            n = 0;
+            sTokenName = t.getToken(0, ' ', n);
             if ( aStack.GetStackData() && ( aStack.GetStackData()->GetTagType() == sTokenName ))
             {
                 if (sCurrentText.isEmpty())
@@ -369,6 +379,7 @@ int CfgParser::ExecuteAnalyzedToken( int nToken, char *pToken )
                 Error( sError );
                 std::exit(EXIT_FAILURE);
             }
+        }
         break;
 
         case CFG_TEXTCHAR:
@@ -625,8 +636,8 @@ void CfgMerge::WorkOnRessourceEnd()
         if ( pEntrys ) {
             rtl::OString sCur;
 
-            for( unsigned int n = 0; n < aLanguages.size(); n++ ){
-                sCur = aLanguages[ n ];
+            for( unsigned int i = 0; i < aLanguages.size(); ++i ){
+                sCur = aLanguages[ i ];
 
                 rtl::OString sContent;
                 pEntrys->GetText( sContent, STRING_TYP_TEXT, sCur , sal_True );
@@ -643,12 +654,14 @@ void CfgMerge::WorkOnRessourceEnd()
                     rtl::OString sTextTag = pStackData->sTextTag;
                     rtl::OString sTemp = sTextTag.copy( sTextTag.indexOf( "xml:lang=" ));
 
-                    rtl::OString sSearch = getToken(sTemp, 0, '\"');
+                    sal_Int32 n = 0;
+                    rtl::OString sSearch = sTemp.getToken(0, '"', n);
                     sSearch += "\"";
-                    sSearch += getToken(sTemp, 1, '\"');
+                    sSearch += sTemp.getToken(0, '"', n);
                     sSearch += "\"";
 
-                    rtl::OString sReplace = getToken(sTemp, 0, '\"');
+                    n = 0;
+                    rtl::OString sReplace = sTemp.getToken(0, '"', n);
                     sReplace += "\"";
                     sReplace += sCur;
                     sReplace += "\"";
diff --git a/l10ntools/source/export.cxx b/l10ntools/source/export.cxx
index f638a10..746785a 100644
--- a/l10ntools/source/export.cxx
+++ b/l10ntools/source/export.cxx
@@ -31,6 +31,8 @@
 #include <cstddef>
 #include <cstring>
 
+#include "comphelper/string.hxx"
+
 #include "boost/scoped_ptr.hpp"
 #include <stdio.h>
 #include <stdlib.h>
@@ -40,14 +42,13 @@
 #include "tokens.h"
 #include <iostream>
 #include <rtl/strbuf.hxx>
-#include <comphelper/string.hxx>
-
-using comphelper::string::getToken;
-using comphelper::string::getTokenCount;
 
 extern "C" { int yyerror( const char * ); }
 extern "C" { int YYWarning( const char * ); }
 
+using comphelper::string::getToken;
+using comphelper::string::getTokenCount;
+
 namespace {
 
 rtl::OString sActFileName; //TODO
@@ -245,9 +246,7 @@ sal_Bool ResData::SetId( const rtl::OString& rId, sal_uInt16 nLevel )
         if ( sId.getLength() > 255 )
         {
             YYWarning( "LocalId > 255 chars, truncating..." );
-            sId = sId.copy(0, 255);
-            sId = comphelper::string::stripEnd(sId, ' ');
-            sId = comphelper::string::stripEnd(sId, '\t');
+            sId = helper::trimAscii(sId.copy(0, 255));
         }
 
         return sal_True;
@@ -366,11 +365,11 @@ int Export::Execute( int nToken, const char * pToken )
     if ( nToken == CONDITION )
     {
         rtl::OString sTestToken(pToken);
-        sTestToken = comphelper::string::remove(sTestToken, '\t');
-        sTestToken = comphelper::string::remove(sTestToken, ' ');
-        if (( !bReadOver ) && ( comphelper::string::indexOfL(sTestToken, RTL_CONSTASCII_STRINGPARAM("#ifndef__RSC_PARSER")) == 0 ))
+        helper::searchAndReplaceAll(&sTestToken, "\t", rtl::OString());
+        helper::searchAndReplaceAll(&sTestToken, " ", rtl::OString());
+        if (( !bReadOver ) && ( sTestToken.indexOf("#ifndef__RSC_PARSER") == 0 ))
             bReadOver = sal_True;
-        else if (( bReadOver ) && ( comphelper::string::indexOfL(sTestToken, RTL_CONSTASCII_STRINGPARAM("#endif")) == 0 ))
+        else if (( bReadOver ) && ( sTestToken.indexOf("#endif") == 0 ))
             bReadOver = sal_False;
     }
     if ((( nToken < FILTER_LEVEL ) || ( bReadOver )) &&
@@ -491,12 +490,13 @@ int Export::Execute( int nToken, const char * pToken )
 
             pResData = new ResData( sActPForm, FullId() , sFilename );
             aResStack.push_back( pResData );
-            sToken = comphelper::string::remove(sToken, '\n');
-            sToken = comphelper::string::remove(sToken, '\r');
-            sToken = comphelper::string::remove(sToken, '{');
-            while( helper::searchAndReplace(&sToken, "\t", " " ) != -1 ) {};
-            sToken = comphelper::string::stripEnd(sToken, ' ');
-            rtl::OString sTLower = getToken(sToken, 0, ' ').toAsciiLowerCase();
+            helper::searchAndReplaceAll(&sToken, "\n", rtl::OString());
+            helper::searchAndReplaceAll(&sToken, "\r", rtl::OString());
+            helper::searchAndReplaceAll(&sToken, "{", rtl::OString());
+            helper::searchAndReplaceAll(&sToken, "\t", " ");
+            sToken = helper::trimAscii(sToken);
+            sal_Int32 n = 0;
+            rtl::OString sTLower = sToken.getToken(0, ' ', n).toAsciiLowerCase();
             pResData->sResTyp = sTLower;
             rtl::OString sId( sToken.copy( pResData->sResTyp.getLength() + 1 ));
             rtl::OString sCondition;
@@ -504,12 +504,14 @@ int Export::Execute( int nToken, const char * pToken )
             {
                 // between ResTyp, Id and paranthes is a precomp. condition
                 sCondition = "#";
-                sCondition += getToken(sId, 1, '#');
-                sId = getToken(sId, 0, '#');
+                n = 0;
+                sId = sId.getToken(0, '#', n);
+                sCondition += sId.getToken(0, '#', n);
             }
-            sId = getToken(sId, 0, '/');
+            n = 0;
+            sId = sId.getToken(0, '/', n);
             CleanValue( sId );
-            sId = comphelper::string::remove(sId, '\t');
+            helper::searchAndReplaceAll(&sId, "\t", rtl::OString());
             pResData->SetId( sId, ID_LEVEL_IDENTIFIER );
             if (!sCondition.isEmpty())
             {
@@ -530,12 +532,12 @@ int Export::Execute( int nToken, const char * pToken )
 
             pResData = new ResData( sActPForm, FullId() , sFilename );
             aResStack.push_back( pResData );
-            sToken = comphelper::string::remove(sToken, '\n');
-            sToken = comphelper::string::remove(sToken, '\r');
-            sToken = comphelper::string::remove(sToken, '{');
-            sToken = comphelper::string::remove(sToken, '\t');
-            sToken = comphelper::string::remove(sToken, ' ');
-            sToken = comphelper::string::remove(sToken, '\\');
+            helper::searchAndReplaceAll(&sToken, "\n", rtl::OString());
+            helper::searchAndReplaceAll(&sToken, "\r", rtl::OString());
+            helper::searchAndReplaceAll(&sToken, "{", rtl::OString());
+            helper::searchAndReplaceAll(&sToken, "\t", rtl::OString());
+            helper::searchAndReplaceAll(&sToken, " ", rtl::OString());
+            helper::searchAndReplaceAll(&sToken, "\\", rtl::OString());
             sToken = sToken.toAsciiLowerCase();
             pResData->sResTyp = sToken;
         }
@@ -595,16 +597,18 @@ int Export::Execute( int nToken, const char * pToken )
         {
             bDontWriteOutput = sal_False;
             // interpret different types of assignement
-            rtl::OString sKey = getToken(sToken, 0, '=');
-            sKey = comphelper::string::remove(sKey, ' ');
-            sKey = comphelper::string::remove(sKey, '\t');
-            rtl::OString sValue = getToken(sToken, 1, '=');
+            sal_Int32 n = 0;
+            rtl::OString sKey = sToken.getToken(0, '=', n);
+            helper::searchAndReplaceAll(&sKey, " ", rtl::OString());
+            helper::searchAndReplaceAll(&sKey, "\t", rtl::OString());
+            rtl::OString sValue = sToken.getToken(0, '=', n);
             CleanValue( sValue );
             sKey = sKey.toAsciiUpperCase();
             if (sKey.equalsL(RTL_CONSTASCII_STRINGPARAM("IDENTIFIER")))
             {
-                rtl::OString sId(comphelper::string::remove(sValue, '\t'));
-                sId = comphelper::string::remove(sId, ' ');
+                rtl::OString sId(sValue);
+                helper::searchAndReplaceAll(&sId, "\t", rtl::OString());
+                helper::searchAndReplaceAll(&sId, " ", rtl::OString());
                 pResData->SetId(sId, ID_LEVEL_IDENTIFIER);
             }
             else if (sKey.equalsL(RTL_CONSTASCII_STRINGPARAM("HELPID")))
@@ -1113,11 +1117,8 @@ sal_Bool Export::WriteData( ResData *pResData, sal_Bool bCreateNew )
 rtl::OString Export::GetPairedListID(const rtl::OString& rText)
 {
 // < "STRING" ; IDENTIFIER ; > ;
-    rtl::OString sIdent(
+    return helper::trimAscii(
         getToken(rText, 1, ';').toAsciiUpperCase().replace('\t', ' '));
-    sIdent = comphelper::string::stripEnd(sIdent, ' ');
-    sIdent = comphelper::string::stripStart(sIdent, ' ');
-    return sIdent;
 }
 
 rtl::OString Export::GetPairedListString(const rtl::OString& rText)
diff --git a/l10ntools/source/export2.cxx b/l10ntools/source/export2.cxx
index 12d1a5a..3212f6c 100644
--- a/l10ntools/source/export2.cxx
+++ b/l10ntools/source/export2.cxx
@@ -29,20 +29,19 @@
 #include "sal/config.h"
 
 #include "export.hxx"
+#include "helper.hxx"
 #include <stdio.h>
 #include <osl/time.h>
 #include <osl/process.h>
+#include <rtl/strbuf.hxx>
 #include <rtl/ustring.hxx>
 #include <sal/macros.h>
 #include <iostream>
 #include <iomanip>
 #include <tools/urlobj.hxx>
-#include <comphelper/string.hxx>
 #include <time.h>
 #include <stdlib.h>
 
-using namespace std;
-using comphelper::string::getToken;
 //
 // class ResData();
 //
@@ -216,14 +215,14 @@ bool Export::CopyFile(const rtl::OString& rSource, const rtl::OString& rDest)
     FILE* IN_FILE = fopen( rSource.getStr() , "r" );
     if( IN_FILE == NULL )
     {
-        cerr << "Export::CopyFile WARNING: Could not open " << rSource.getStr() << "\n";
+        std::cerr << "Export::CopyFile WARNING: Could not open " << rSource.getStr() << "\n";
         return false;
     }
 
     FILE* OUT_FILE = fopen( rDest.getStr() , "w" );
     if( OUT_FILE == NULL )
     {
-        cerr << "Export::CopyFile WARNING: Could not open/create " << rDest.getStr() << " for writing\n";
+        std::cerr << "Export::CopyFile WARNING: Could not open/create " << rDest.getStr() << " for writing\n";
         fclose( IN_FILE );
         return false;
     }
@@ -232,7 +231,7 @@ bool Export::CopyFile(const rtl::OString& rSource, const rtl::OString& rDest)
     {
         if( fputs( buf , OUT_FILE ) == EOF )
         {
-            cerr << "Export::CopyFile WARNING: Write problems " << rSource.getStr() << "\n";
+            std::cerr << "Export::CopyFile WARNING: Write problems " << rSource.getStr() << "\n";
             fclose( IN_FILE );
             fclose( OUT_FILE );
             return false;
@@ -240,7 +239,7 @@ bool Export::CopyFile(const rtl::OString& rSource, const rtl::OString& rDest)
     }
     if( ferror( IN_FILE ) )
     {
-        cerr << "Export::CopyFile WARNING: Read problems " << rDest.getStr() << "\n";
+        std::cerr << "Export::CopyFile WARNING: Read problems " << rDest.getStr() << "\n";
         fclose( IN_FILE );
         fclose( OUT_FILE );
         return false;
@@ -304,8 +303,8 @@ void Export::InitLanguages( bool bMergeMode ){
         do
         {
             rtl::OString aToken = sLanguages.getToken(0, ',', nIndex);
-            sTmp = getToken(aToken, 0, '=');
-            sTmp = comphelper::string::strip(sTmp, ' ');
+            sal_Int32 n = 0;
+            sTmp = helper::trimAscii(aToken.getToken(0, '=', n));
             if( bMergeMode && !isAllowed( sTmp ) ){}
             else if( !( (sTmp[0]=='x' || sTmp[0]=='X') && sTmp[1]=='-' ) ){
                 aLanguages.push_back( sTmp );
@@ -328,8 +327,8 @@ void Export::InitForcedLanguages( bool bMergeMode ){
     {
         rtl::OString aToken = sForcedLanguages.getToken(0, ',', nIndex);
 
-        sTmp = getToken(aToken, 0, '=');
-        sTmp = comphelper::string::strip(sTmp, ' ');
+        sal_Int32 n = 0;
+        sTmp = helper::trimAscii(aToken.getToken(0, '=', n));
         if( bMergeMode && isAllowed( sTmp ) ){}
         else if( !( (sTmp[0]=='x' || sTmp[0]=='X') && sTmp[1]=='-' ) )
             aForcedLanguages.push_back( sTmp );
@@ -353,14 +352,14 @@ const char* Export::GetEnv( const char *pVar )
         return pRet;
 }
 
-void Export::getCurrentDir( string& dir )
+void Export::getCurrentDir( std::string& dir )
 {
     char buffer[64000];
     if( getcwd( buffer , sizeof( buffer ) ) == 0 ){
-        cerr << "Error: getcwd failed!\n";
+        std::cerr << "Error: getcwd failed!\n";
         exit( -1 );
     }
-    dir = string( buffer );
+    dir = std::string( buffer );
 }
 
 
diff --git a/l10ntools/source/lngmerge.cxx b/l10ntools/source/lngmerge.cxx
index 059a046..00a997a 100644
--- a/l10ntools/source/lngmerge.cxx
+++ b/l10ntools/source/lngmerge.cxx
@@ -30,17 +30,23 @@
 
 #include <cstddef>
 #include <fstream>
+#include <iterator>
 #include <string>
 
-#include <tools/fsys.hxx>
-#include <comphelper/string.hxx>
-
+#include "common.hxx"
+#include "helper.hxx"
 #include "lngmerge.hxx"
-#include <iostream>
 
-using namespace std;
-using comphelper::string::getToken;
-using comphelper::string::getTokenCount;
+namespace {
+
+rtl::OString getBracketedContent(rtl::OString text) {
+    sal_Int32 n = 0;
+    rtl::OString t(text.getToken(1, '[', n));
+    n = 0;
+    return t.getToken(0, ']', n);
+}
+
+}
 
 //
 // class LngParser
@@ -54,34 +60,28 @@ LngParser::LngParser(const rtl::OString &rLngFile, sal_Bool bUTF8,
     , bULF( bULFFormat )
 {
     pLines = new LngLineList();
-    DirEntry aEntry(rtl::OStringToOUString(sSource, RTL_TEXTENCODING_ASCII_US));
-    if ( aEntry.Exists())
+    std::ifstream aStream(sSource.getStr());
+    if (aStream.is_open())
     {
-        std::ifstream aStream(sSource.getStr());
-        if (aStream.is_open())
+        bool bFirstLine = true;
+        while (!aStream.eof())
         {
-            bool bFirstLine = true;
-            while (!aStream.eof())
-            {
-                std::string s;
-                std::getline(aStream, s);
-                rtl::OString sLine(s.data(), s.length());
+            std::string s;
+            std::getline(aStream, s);
+            rtl::OString sLine(s.data(), s.length());
 
-                if( bFirstLine )
-                {
-                    // Always remove UTF8 BOM from the first line
-                    Export::RemoveUTF8ByteOrderMarker( sLine );
-                    bFirstLine = false;
-                }
-
-                pLines->push_back( new rtl::OString(sLine) );
+            if( bFirstLine )
+            {
+                // Always remove UTF8 BOM from the first line
+                Export::RemoveUTF8ByteOrderMarker( sLine );
+                bFirstLine = false;
             }
+
+            pLines->push_back( new rtl::OString(sLine) );
         }
-        else
-            nError = LNG_COULD_NOT_OPEN;
     }
     else
-        nError = LNG_FILE_NOTFOUND;
+        nError = LNG_COULD_NOT_OPEN;
 }
 
 LngParser::~LngParser()
@@ -104,17 +104,8 @@ sal_Bool LngParser::CreateSDF(const rtl::OString &rSDFFile,
         nError = SDF_COULD_NOT_OPEN;
     }
     nError = SDF_OK;
-    DirEntry aEntry(rtl::OStringToOUString(sSource, RTL_TEXTENCODING_ASCII_US));
-    aEntry.ToAbs();
-    rtl::OUString sFullEntry(aEntry.GetFull());
-    aEntry += DirEntry(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("..")));
-    aEntry += DirEntry( rRoot );
-    rtl::OString sPrjEntry(rtl::OUStringToOString(aEntry.GetFull(),
-        osl_getThreadTextEncoding()));
-    rtl::OString sActFileName(rtl::OUStringToOString(
-        sFullEntry.copy(sPrjEntry.getLength() + 1),
-        osl_getThreadTextEncoding()));
-    sActFileName = sActFileName.replace('/', '\\');
+    rtl::OString sActFileName(
+        common::pathnameToken(sSource.getStr(), rRoot.getStr()));
 
     size_t nPos  = 0;
     sal_Bool bStart = true;
@@ -171,13 +162,10 @@ void LngParser::WriteSDF(std::ofstream &aSDFStream,
 
 bool LngParser::isNextGroup(rtl::OString &sGroup_out, rtl::OString &sLine_in)
 {
-    sLine_in = comphelper::string::stripStart(sLine_in, ' ');
-    sLine_in = comphelper::string::stripEnd(sLine_in, ' ');
+    sLine_in = helper::trimAscii(sLine_in);
     if ((sLine_in[0] == '[') && (sLine_in[sLine_in.getLength() - 1] == ']'))
     {
-        sGroup_out = getToken(getToken(sLine_in, 1, '['), 0, ']');
-        sGroup_out = comphelper::string::stripStart(sGroup_out, ' ');
-        sGroup_out = comphelper::string::stripEnd(sGroup_out, ' ');
+        sGroup_out = helper::trimAscii(getBracketedContent(sLine_in));
         return true;
     }
     return false;
@@ -186,12 +174,13 @@ bool LngParser::isNextGroup(rtl::OString &sGroup_out, rtl::OString &sLine_in)
 void LngParser::ReadLine(const rtl::OString &rLine_in,
         OStringHashMap &rText_inout)
 {
-   rtl::OString sLang = getToken(rLine_in, 0, '=');
-   sLang = comphelper::string::stripStart(sLang, ' ');
-   sLang = comphelper::string::stripEnd(sLang, ' ');
-   rtl::OString sText = getToken(getToken(rLine_in, 1, '\"'), 0, '\"');
-   if (!sLang.isEmpty())
-       rText_inout[ sLang ] = sText;
+    sal_Int32 n = 0;
+    rtl::OString sLang(helper::trimAscii(rLine_in.getToken(0, '=', n)));
+    if (!sLang.isEmpty()) {
+        n = 0;
+        rtl::OString sText(rLine_in.getToken(1, '"', n));
+        rText_inout[sLang] = sText;
+    }
 }
 
 sal_Bool LngParser::Merge(
@@ -220,14 +209,11 @@ sal_Bool LngParser::Merge(
     while ( nPos < pLines->size() && !bGroup )
     {
         rtl::OString sLine( *(*pLines)[ nPos ] );
-        sLine = comphelper::string::stripStart(sLine, ' ');
-        sLine = comphelper::string::stripEnd(sLine, ' ');
+        sLine = helper::trimAscii(sLine);
         if (( sLine[0] == '[' ) &&
             ( sLine[sLine.getLength() - 1] == ']' ))
         {
-            sGroup = getToken(getToken(sLine, 1, '['), 0, ']');
-            sGroup = comphelper::string::stripStart(sGroup, ' ');
-            sGroup = comphelper::string::stripEnd(sGroup, ' ');
+            sGroup = helper::trimAscii(getBracketedContent(sLine));
             bGroup = sal_True;
         }
         nPos ++;
@@ -249,63 +235,65 @@ sal_Bool LngParser::Merge(
         while ( nPos < pLines->size() && !bGroup )
         {
             rtl::OString sLine( *(*pLines)[ nPos ] );
-            sLine = comphelper::string::stripStart(sLine, ' ');
-            sLine = comphelper::string::stripEnd(sLine, ' ');
+            sLine = helper::trimAscii(sLine);
             if (( sLine[0] == '[' ) &&
                 ( sLine[sLine.getLength() - 1] == ']' ))
             {
-                sGroup = getToken(getToken(sLine, 1, '['), 0, ']');
-                sGroup = comphelper::string::stripStart(sGroup, ' ');
-                sGroup = comphelper::string::stripEnd(sGroup, ' ');
+                sGroup = helper::trimAscii(getBracketedContent(sLine));
                 bGroup = sal_True;
                 nPos ++;
                 sLanguagesDone = "";
             }
-            else if ( getTokenCount(sLine, '=') > 1 )
+            else
             {
-                rtl::OString sLang = getToken(sLine, 0, '=');
-                sLang = comphelper::string::stripStart(sLang, ' ');
-                sLang = comphelper::string::stripEnd(sLang, ' ');
-
-                rtl::OString sSearch( ";" );
-                sSearch += sLang;
-                sSearch += ";";
-
-                if (( sLanguagesDone.indexOf( sSearch ) != -1 )) {
-                    LngLineList::iterator it = pLines->begin();
-                    ::std::advance( it, nPos );
-                    pLines->erase( it );
+                sal_Int32 n = 0;
+                rtl::OString sLang(sLine.getToken(0, '=', n));
+                if (n == -1)
+                {
+                    ++nPos;
                 }
-                if( bULF && pEntrys )
+                else
                 {
-                    if( !sLang.isEmpty() )
+                    sLang = helper::trimAscii(sLang);
+
+                    rtl::OString sSearch( ";" );
+                    sSearch += sLang;
+                    sSearch += ";";
+
+                    if (( sLanguagesDone.indexOf( sSearch ) != -1 )) {
+                        LngLineList::iterator it = pLines->begin();
+                        std::advance( it, nPos );
+                        pLines->erase( it );
+                    }
+                    if( bULF && pEntrys )
                     {
-                        rtl::OString sNewText;
-                        pEntrys->GetText( sNewText, STRING_TYP_TEXT, sLang, sal_True );
-
-                        if ( !sNewText.isEmpty()) {
-                            rtl::OString *pLine = (*pLines)[ nPos ];
-
-                            rtl::OString sText1( sLang );
-                            sText1 += " = \"";
-                            sText1 += sNewText;
-                            sText1 += "\"";
-                            *pLine = sText1;
-                            Text[ sLang ] = sNewText;
+                        if( !sLang.isEmpty() )
+                        {
+                            rtl::OString sNewText;
+                            pEntrys->GetText( sNewText, STRING_TYP_TEXT, sLang, sal_True );
+
+                            if ( !sNewText.isEmpty()) {
+                                rtl::OString *pLine = (*pLines)[ nPos ];
+
+                                rtl::OString sText1( sLang );
+                                sText1 += " = \"";
+                                sText1 += sNewText;
+                                sText1 += "\"";
+                                *pLine = sText1;
+                                Text[ sLang ] = sNewText;
+                            }
                         }
+                        nLastLangPos = nPos;
+                        nPos ++;
+                        sLanguagesDone += sSearch;
+                    }
+                    else {
+                        nLastLangPos = nPos;
+                        nPos ++;
+                        sLanguagesDone += sSearch;
                     }
-                    nLastLangPos = nPos;
-                    nPos ++;
-                    sLanguagesDone += sSearch;
-                }
-                else {
-                    nLastLangPos = nPos;
-                    nPos ++;
-                    sLanguagesDone += sSearch;
                 }
             }
-            else
-                nPos++;
         }
         rtl::OString sCur;
         if ( nLastLangPos )
@@ -332,7 +320,7 @@ sal_Bool LngParser::Merge(
 
                         if ( nLastLangPos < pLines->size() ) {
                             LngLineList::iterator it = pLines->begin();
-                            ::std::advance( it, nLastLangPos );
+                            std::advance( it, nLastLangPos );
                             pLines->insert( it, new rtl::OString(sLine) );
                         } else {
                             pLines->push_back( new rtl::OString(sLine) );
diff --git a/l10ntools/source/makefile.mk b/l10ntools/source/makefile.mk
index bd9780b..02b0696 100644
--- a/l10ntools/source/makefile.mk
+++ b/l10ntools/source/makefile.mk
@@ -75,7 +75,6 @@ APP1TARGET=  transex3
 APP1OBJS=   $(OBJ)$/src_yy_wrapper.obj
 APP1RPATH=  NONE
 APP1STDLIBS+= \
-            $(TOOLSLIB) \
             $(COMPHELPERLIB) \
             $(SALLIB)
 
@@ -96,8 +95,6 @@ APP3TARGET= ulfex
 APP3OBJS=   $(OBJ)$/lngmerge.obj $(OBJ)$/merge.obj $(OBJ)$/export2.obj $(OBJ)$/lngex.obj
 APP3RPATH=  NONE
 APP3STDLIBS+= \
-            $(TOOLSLIB) \
-            $(COMPHELPERLIB) \
             $(SALLIB)
 
 # tag checker for *.gsi
@@ -112,8 +109,6 @@ APP6TARGET= cfgex
 APP6OBJS=   $(OBJ)$/cfgmerge.obj $(OBJ)$/cfg_yy_wrapper.obj  $(OBJ)$/merge.obj $(OBJ)$/export2.obj
 APP6RPATH=  NONE
 APP6STDLIBS+= \
-            $(TOOLSLIB) \
-            $(COMPHELPERLIB) \
             $(SALLIB)
 
 # extractor and merger for *.xrm
diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx
index e078e30..65c720a 100644
--- a/l10ntools/source/merge.cxx
+++ b/l10ntools/source/merge.cxx
@@ -28,25 +28,20 @@
 
 #include "sal/config.h"
 
+#include <algorithm>
 #include <fstream>
 #include <string>
+#include <vector>
 
-#include <stdio.h>
-#include <tools/fsys.hxx>
-#include <comphelper/string.hxx>
 #include "export.hxx"
-#include <iostream>
-
-using namespace std;
-using comphelper::string::getToken;
-using comphelper::string::getTokenCount;
+#include "helper.hxx"
 
 namespace
 {
     static ::rtl::OString lcl_NormalizeFilename(const ::rtl::OString& rFilename)
     {
         return rFilename.copy(
-            ::std::max(
+            std::max(
                 rFilename.lastIndexOf( "\\" ),
                 rFilename.lastIndexOf( "/" ))+1);
     };
@@ -195,37 +190,28 @@ MergeDataFile::MergeDataFile(
         std::string buf;
         std::getline(aInputStream, buf);
         rtl::OString sLine(buf.data(), buf.length());
-        xub_StrLen nToks = getTokenCount(sLine, '\t');
-        if ( nToks == 15 )
+        sal_Int32 n = 0;
+        // Skip all wrong filenames
+        const ::rtl::OString filename = lcl_NormalizeFilename(sLine.getToken(1, '\t', n)); // token 1
+        if(isFileEmpty || sFileNormalized.equals("") || (!isFileEmpty && filename.equals(sFileNormalized)) )
         {
-            // Skip all wrong filenames
-            const ::rtl::OString filename = lcl_NormalizeFilename(getToken(sLine, 1 , '\t'));
-            if(isFileEmpty || sFileNormalized.equals("") || (!isFileEmpty && filename.equals(sFileNormalized)) )
+            const rtl::OString sTYP = sLine.getToken( 1, '\t', n ); // token 3
+            const rtl::OString sGID = sLine.getToken( 0, '\t', n ); // token 4
+            const rtl::OString sLID = sLine.getToken( 0, '\t', n ); // token 5
+            rtl::OString sPFO = sLine.getToken( 1, '\t', n ); // token 7
+            sPFO = sHACK;
+            rtl::OString nLANG = sLine.getToken( 1, '\t', n ); // token 9
+            nLANG = helper::trimAscii(nLANG);
+            const rtl::OString sTEXT = sLine.getToken( 0, '\t', n ); // token 10
+            const rtl::OString sQHTEXT = sLine.getToken( 1, '\t', n ); // token 12
+            const rtl::OString sTITLE = sLine.getToken( 0, '\t', n ); // token 13
+
+            if (!nLANG.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("en-US")))
             {
-                sal_Int32 rIdx = 0;
-                const rtl::OString sTYP = sLine.getToken( 3, '\t', rIdx );
-                const rtl::OString sGID = sLine.getToken( 0, '\t', rIdx ); // 4
-                const rtl::OString sLID = sLine.getToken( 0, '\t', rIdx ); // 5
-                rtl::OString sPFO = sLine.getToken( 1, '\t', rIdx ); // 7
-                sPFO = sHACK;
-                rtl::OString nLANG = sLine.getToken( 1, '\t', rIdx ); // 9
-                nLANG = comphelper::string::strip(nLANG, ' ');
-                const rtl::OString sTEXT = sLine.getToken( 0, '\t', rIdx ); // 10
-                const rtl::OString sQHTEXT = sLine.getToken( 1, '\t', rIdx ); // 12
-                const rtl::OString sTITLE = sLine.getToken( 0, '\t', rIdx );  // 13
-
-
-                if (!nLANG.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("en-US")))
-                {
-                    aLanguageSet.insert(nLANG);
-                    InsertEntry( sTYP, sGID, sLID, sPFO, nLANG, sTEXT, sQHTEXT, sTITLE, filename, bCaseSensitive );
-                }
+                aLanguageSet.insert(nLANG);
+                InsertEntry( sTYP, sGID, sLID, sPFO, nLANG, sTEXT, sQHTEXT, sTITLE, filename, bCaseSensitive );
             }
         }
-        else if ( nToks == 10 )
-        {
-            printf("ERROR: File format is obsolete and no longer supported!\n");
-        }
     }
     aInputStream.close();
 }


More information about the Libreoffice-commits mailing list