[Libreoffice-commits] .: l10ntools/inc l10ntools/source
Joseph Powers
jpowers at kemper.freedesktop.org
Sun Jan 23 06:36:26 PST 2011
l10ntools/inc/lngmerge.hxx | 9 ++-
l10ntools/source/lngmerge.cxx | 102 +++++++++++++++++++++---------------------
2 files changed, 57 insertions(+), 54 deletions(-)
New commits:
commit e7594d5f002725509e013dc2a5c5e811e03d37eb
Author: Joseph Powers <jpowers27 at cox.net>
Date: Sun Jan 23 06:36:20 2011 -0800
Remove DECLARE_LIST( LngLineList, ByteString* )
diff --git a/l10ntools/inc/lngmerge.hxx b/l10ntools/inc/lngmerge.hxx
index 1ffa8d8..100441b 100644
--- a/l10ntools/inc/lngmerge.hxx
+++ b/l10ntools/inc/lngmerge.hxx
@@ -2,7 +2,7 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
@@ -27,8 +27,9 @@
************************************************************************/
// local includes
#include "export.hxx"
+#include <vector>
-DECLARE_LIST( LngLineList, ByteString * )
+typedef ::std::vector< ByteString* > LngLineList;
#define LNG_OK 0x0000
#define LNG_FILE_NOTFOUND 0x0001
@@ -55,8 +56,8 @@ private:
void FillInFallbacks( ByteStringHashMap Text );
bool isNextGroup( ByteString &sGroup_out , ByteString &sLine_in);
void ReadLine( const ByteString &sLine_in , ByteStringHashMap &rText_inout );
- void WriteSDF( SvFileStream &aSDFStream , ByteStringHashMap &rText_inout ,
- const ByteString &rPrj ,
+ void WriteSDF( SvFileStream &aSDFStream , ByteStringHashMap &rText_inout ,
+ const ByteString &rPrj ,
const ByteString &rRoot , const ByteString &sActFileName , const ByteString &sID );
public:
LngParser( const ByteString &rLngFile, BOOL bUTF8, BOOL bULFFormat );
diff --git a/l10ntools/source/lngmerge.cxx b/l10ntools/source/lngmerge.cxx
index 6e17c7f..5f6273a 100644
--- a/l10ntools/source/lngmerge.cxx
+++ b/l10ntools/source/lngmerge.cxx
@@ -2,7 +2,7 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
@@ -48,22 +48,22 @@ LngParser::LngParser( const ByteString &rLngFile, BOOL bUTF8, BOOL bULFFormat )
bDBIsUTF8( bUTF8 ),
bULF( bULFFormat )
{
- pLines = new LngLineList( 100, 100 );
+ pLines = new LngLineList();
DirEntry aEntry( String( sSource, RTL_TEXTENCODING_ASCII_US ));
if ( aEntry.Exists()) {
SvFileStream aStream( String( sSource, RTL_TEXTENCODING_ASCII_US ), STREAM_STD_READ );
if ( aStream.IsOpen()) {
ByteString sLine;
- bool bFirstLine = true;
+ bool bFirstLine = true;
while ( !aStream.IsEof()) {
aStream.ReadLine( sLine );
-
+
if( bFirstLine ){ // Always remove UTF8 BOM from the first line
Export::RemoveUTF8ByteOrderMarker( sLine );
bFirstLine = false;
}
-
- pLines->Insert( new ByteString( sLine ), LIST_APPEND );
+
+ pLines->push_back( new ByteString( sLine ) );
}
}
else
@@ -77,8 +77,9 @@ LngParser::LngParser( const ByteString &rLngFile, BOOL bUTF8, BOOL bULFFormat )
LngParser::~LngParser()
/*****************************************************************************/
{
- for ( ULONG i = 0; i < pLines->Count(); i++ )
- delete pLines->GetObject( i );
+ for ( size_t i = 0, n = pLines->size(); i < n; i++ )
+ delete (*pLines)[ i ];
+ pLines->clear();
delete pLines;
}
@@ -89,7 +90,7 @@ void LngParser::FillInFallbacks( ByteStringHashMap Text )
ByteString sCur;
for( unsigned int n = 0; n < aLanguages.size(); n++ ){
sCur = aLanguages[ n ];
-
+
if( Export::isAllowed( sCur ) ){
ByteString sFallbackLang = Export::GetFallbackLanguage( sCur );
if( sFallbackLang.Len() ){
@@ -113,7 +114,7 @@ BOOL LngParser::CreateSDF(
if ( !aSDFStream.IsOpen()) {
nError = SDF_COULD_NOT_OPEN;
}
- aSDFStream.SetStreamCharSet( RTL_TEXTENCODING_UTF8 );
+ aSDFStream.SetStreamCharSet( RTL_TEXTENCODING_UTF8 );
nError = SDF_OK;
DirEntry aEntry( String( sSource, RTL_TEXTENCODING_ASCII_US ));
aEntry.ToAbs();
@@ -125,38 +126,37 @@ BOOL LngParser::CreateSDF(
sFullEntry.Copy( sPrjEntry.Len() + 1 ), gsl_getSystemTextEncoding());
sActFileName.SearchAndReplaceAll( "/", "\\" );
- ULONG nPos = 0;
+ size_t nPos = 0;
BOOL bStart = true;
ByteString sGroup;
- ByteStringHashMap Text;
+ ByteStringHashMap Text;
ByteString sID;
ByteString sLine;
- while( nPos < pLines->Count() ){
- sLine = *pLines->GetObject( nPos++ );
- while( nPos < pLines->Count() && !isNextGroup( sGroup , sLine ) ){
+ while( nPos < pLines->size() ) {
+ sLine = *(*pLines)[ nPos++ ];
+ while( nPos < pLines->size() && !isNextGroup( sGroup , sLine ) ) {
ReadLine( sLine , Text );
sID = sGroup;
- sLine = *pLines->GetObject( nPos++ );
+ sLine = *(*pLines)[ nPos++ ];
};
- if( bStart ){
+ if( bStart ) {
bStart = false;
sID = sGroup;
}
else {
-
- WriteSDF( aSDFStream , Text , rPrj , rRoot , sActFileName , sID );
+ WriteSDF( aSDFStream , Text , rPrj , rRoot , sActFileName , sID );
}
}
aSDFStream.Close();
return true;
}
- void LngParser::WriteSDF( SvFileStream &aSDFStream , ByteStringHashMap &rText_inout ,
+ void LngParser::WriteSDF( SvFileStream &aSDFStream , ByteStringHashMap &rText_inout ,
const ByteString &rPrj , const ByteString &rRoot ,
const ByteString &sActFileName , const ByteString &sID )
{
-
+
BOOL bExport = true;
if ( bExport ) {
ByteString sTimeStamp( Export::GetTimeStamp());
@@ -164,10 +164,10 @@ BOOL LngParser::CreateSDF(
FillInFallbacks( rText_inout );
for( unsigned int n = 0; n < aLanguages.size(); n++ ){
sCur = aLanguages[ n ];
- ByteString sAct = rText_inout[ sCur ];
+ ByteString sAct = rText_inout[ sCur ];
if ( !sAct.Len() && sCur.Len() )
sAct = rText_inout[ ByteString("en-US") ];
-
+
ByteString sOutput( rPrj ); sOutput += "\t";
if ( rRoot.Len())
sOutput += sActFileName;
@@ -177,7 +177,6 @@ BOOL LngParser::CreateSDF(
sOutput += sCur; sOutput += "\t";
sOutput += sAct; sOutput += "\t\t\t\t";
sOutput += sTimeStamp;
- //if( !sCur.EqualsIgnoreCaseAscii("de") ||( sCur.EqualsIgnoreCaseAscii("de") && !Export::isMergingGermanAllowed( rPrj ) ) )
aSDFStream.WriteLine( sOutput );
}
}
@@ -195,13 +194,12 @@ BOOL LngParser::CreateSDF(
return false;
}
void LngParser::ReadLine( const ByteString &sLine_in , ByteStringHashMap &rText_inout){
- //printf("sLine -> '%s'\n",sLine_in.GetBuffer());
ByteString sLang = sLine_in.GetToken( 0, '=' );
sLang.EraseLeadingChars( ' ' );
sLang.EraseTrailingChars( ' ' );
ByteString sText = sLine_in.GetToken( 1, '\"' ).GetToken( 0, '\"' );
if( sLang.Len() )
- rText_inout[ sLang ] = sText;
+ rText_inout[ sLang ] = sText;
}
/*****************************************************************************/
@@ -218,21 +216,20 @@ BOOL LngParser::Merge(
nError = LNG_COULD_NOT_OPEN;
}
nError = LNG_OK;
-// MergeDataFile( const ByteString &rFileName, const ByteString& rFile , BOOL bErrLog, CharSet aCharSet, BOOL bUTF8 );
MergeDataFile aMergeDataFile( rSDFFile, sSource , FALSE, RTL_TEXTENCODING_MS_1252);//, bDBIsUTF8 );
ByteString sTmp( Export::sLanguages );
- if( sTmp.ToUpperAscii().Equals("ALL") )
+ if( sTmp.ToUpperAscii().Equals("ALL") )
Export::SetLanguages( aMergeDataFile.GetLanguages() );
aLanguages = Export::GetLanguages();
- ULONG nPos = 0;
+ size_t nPos = 0;
BOOL bGroup = FALSE;
ByteString sGroup;
// seek to next group
- while ( nPos < pLines->Count() && !bGroup ) {
- ByteString sLine( *pLines->GetObject( nPos ));
+ while ( nPos < pLines->size() && !bGroup ) {
+ ByteString sLine( *(*pLines)[ nPos ] );
sLine.EraseLeadingChars( ' ' );
sLine.EraseTrailingChars( ' ' );
if (( sLine.GetChar( 0 ) == '[' ) &&
@@ -246,7 +243,7 @@ BOOL LngParser::Merge(
nPos ++;
}
- while ( nPos < pLines->Count()) {
+ while ( nPos < pLines->size()) {
ByteStringHashMap Text;
ByteString sID( sGroup );
ULONG nLastLangPos = 0;
@@ -259,8 +256,8 @@ BOOL LngParser::Merge(
ByteString sLanguagesDone;
- while ( nPos < pLines->Count() && !bGroup ) {
- ByteString sLine( *pLines->GetObject( nPos ));
+ while ( nPos < pLines->size() && !bGroup ) {
+ ByteString sLine( *(*pLines)[ nPos ] );
sLine.EraseLeadingChars( ' ' );
sLine.EraseTrailingChars( ' ' );
if (( sLine.GetChar( 0 ) == '[' ) &&
@@ -283,7 +280,9 @@ BOOL LngParser::Merge(
sSearch += ";";
if (( sLanguagesDone.Search( sSearch ) != STRING_NOTFOUND )) {
- pLines->Remove( nPos );
+ LngLineList::iterator it = pLines->begin();
+ ::std::advance( it, nPos );
+ pLines->erase( it );
}
if( bULF && pEntrys )
{
@@ -294,14 +293,13 @@ BOOL LngParser::Merge(
pEntrys->GetText( sNewText, STRING_TYP_TEXT, sLang, TRUE );
if ( sNewText.Len()) {
- ByteString *pLine = pLines->GetObject( nPos );
-
- ByteString sText1( sLang );
- sText1 += " = \"";
- sText1 += sNewText;
- sText1 += "\"";
- *pLine = sText1;
- //}
+ ByteString *pLine = (*pLines)[ nPos ];
+
+ ByteString sText1( sLang );
+ sText1 += " = \"";
+ sText1 += sNewText;
+ sText1 += "\"";
+ *pLine = sText1;
Text[ sLang ] = sNewText;
}
}
@@ -322,10 +320,8 @@ BOOL LngParser::Merge(
if ( nLastLangPos ) {
for( unsigned int n = 0; n < aLanguages.size(); n++ ){
sCur = aLanguages[ n ];
- if( //( !sCur.EqualsIgnoreCaseAscii("de") ||
- //( sCur.EqualsIgnoreCaseAscii("de") && Export::isMergingGermanAllowed( rPrj ) ) )
- !sCur.EqualsIgnoreCaseAscii("en-US") && !Text[ sCur ].Len() && pEntrys ){
-
+ if( !sCur.EqualsIgnoreCaseAscii("en-US") && !Text[ sCur ].Len() && pEntrys ) {
+
ByteString sNewText;
pEntrys->GetText( sNewText, STRING_TYP_TEXT, sCur, TRUE );
if (( sNewText.Len()) &&
@@ -340,7 +336,13 @@ BOOL LngParser::Merge(
nLastLangPos++;
nPos++;
- pLines->Insert( new ByteString( sLine ), nLastLangPos );
+ if ( nLastLangPos < pLines->size() ) {
+ LngLineList::iterator it = pLines->begin();
+ ::std::advance( it, nLastLangPos );
+ pLines->insert( it, new ByteString( sLine ) );
+ } else {
+ pLines->push_back( new ByteString( sLine ) );
+ }
}
}
}
@@ -349,8 +351,8 @@ BOOL LngParser::Merge(
delete pResData;
}
- for ( ULONG i = 0; i < pLines->Count(); i++ )
- aDestination.WriteLine( *pLines->GetObject( i ));
+ for ( size_t i = 0; i < pLines->size(); i++ )
+ aDestination.WriteLine( *(*pLines)[ i ] );
aDestination.Close();
return TRUE;
More information about the Libreoffice-commits
mailing list