summaryrefslogtreecommitdiff
path: root/transex3
diff options
context:
space:
mode:
authorPascal Junck <pjunck@openoffice.org>2004-11-02 15:04:16 +0000
committerPascal Junck <pjunck@openoffice.org>2004-11-02 15:04:16 +0000
commit4c44f70f636b3b9dc7beb07aef73dd1c881e2fb0 (patch)
tree4ab0d2ced091e698ac69bccd0b181c0526c72428 /transex3
parentc25ed27fae7fc817661272a1cb5709bf64cd5a2b (diff)
INTEGRATION: CWS ivo05 (1.25.16); FILE MERGED
2004/09/22 17:21:53 ihi 1.25.16.3: Cleanup 2004/09/17 15:06:38 ihi 1.25.16.2: RESYNC: (1.25-1.26); FILE MERGED 2004/09/17 14:52:22 ihi 1.25.16.1: #i34128# Strip UTF8 Byte Order Marker / Repeated language initialisation fixed
Diffstat (limited to 'transex3')
-rw-r--r--transex3/source/export2.cxx86
1 files changed, 74 insertions, 12 deletions
diff --git a/transex3/source/export2.cxx b/transex3/source/export2.cxx
index 5b2236e42869..a232feadba82 100644
--- a/transex3/source/export2.cxx
+++ b/transex3/source/export2.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: export2.cxx,v $
*
- * $Revision: 1.26 $
+ * $Revision: 1.27 $
*
- * last change: $Author: kz $ $Date: 2004-08-30 17:30:29 $
+ * last change: $Author: pjunck $ $Date: 2004-11-02 16:04:16 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -66,6 +66,9 @@
#include <stdio.h>
#include <osl/file.hxx>
#include <rtl/ustring.hxx>
+#include <iostream>
+
+using namespace std;
//
// class ResData();
//
@@ -225,6 +228,62 @@ void Export::QuotHTML( ByteString &rString )
rString = sReturn;
}
+void Export::RemoveUTF8ByteOrderMarker( ByteString &rString ){
+ if( hasUTF8ByteOrderMarker( rString ) )
+ rString.Erase( 0 , 3 );
+}
+
+bool Export::hasUTF8ByteOrderMarker( const ByteString &rString ){
+ // Byte order marker signature
+ const char bom[ 3 ] = { 0xEF , 0xBB , 0xBF };
+
+ return rString.Len() >= 3 &&
+ rString.GetChar( 0 ) == bom[ 0 ] &&
+ rString.GetChar( 1 ) == bom[ 1 ] &&
+ rString.GetChar( 2 ) == bom[ 2 ] ;
+}
+bool Export::fileHasUTF8ByteOrderMarker( const ByteString &rString ){
+ SvFileStream aFileIn( String( rString , RTL_TEXTENCODING_ASCII_US ) , STREAM_READ );
+ ByteString sLine;
+ if( !aFileIn.IsEof() ) {
+ aFileIn.ReadLine( sLine );
+ if( aFileIn.IsOpen() ) aFileIn.Close();
+ return hasUTF8ByteOrderMarker( sLine );
+ }
+ if( aFileIn.IsOpen() ) aFileIn.Close();
+ return false;
+}
+void Export::RemoveUTF8ByteOrderMarkerFromFile( const ByteString &rFilename ){
+ SvFileStream aFileIn( String( rFilename , RTL_TEXTENCODING_ASCII_US ) , STREAM_READ );
+ ByteString sLine;
+ if( !aFileIn.IsEof() ) {
+ aFileIn.ReadLine( sLine );
+ // Test header
+ if( hasUTF8ByteOrderMarker( sLine ) ){
+ //cout << "UTF8 Header found!\n";
+ DirEntry aTempFile = Export::GetTempFile();
+ ByteString sTempFile = ByteString( aTempFile.GetFull() , RTL_TEXTENCODING_ASCII_US );
+ SvFileStream aNewFile( String( sTempFile , RTL_TEXTENCODING_ASCII_US ) , STREAM_WRITE );
+ // Remove header
+ RemoveUTF8ByteOrderMarker( sLine );
+ //cout << "Copy stripped stuff to " << sTempFile.GetBuffer() << endl;
+ aNewFile.WriteLine( sLine );
+ // Copy the rest
+ while( !aFileIn.IsEof() ){
+ aFileIn.ReadLine( sLine );
+ aNewFile.WriteLine( sLine );
+ }
+ if( aFileIn.IsOpen() ) aFileIn.Close();
+ if( aNewFile.IsOpen() ) aNewFile.Close();
+ DirEntry aEntry( rFilename.GetBuffer() );
+ //cout << "Removing file " << rFilename.GetBuffer() << "\n";
+ aEntry.Kill();
+ //cout << "Renaming file " << sTempFile.GetBuffer() << " to " << rFilename.GetBuffer() << "\n";
+ DirEntry( sTempFile ).MoveTo( DirEntry( rFilename.GetBuffer() ) );
+ }
+ }
+ if( aFileIn.IsOpen() ) aFileIn.Close();
+}
/*****************************************************************************/
void Export::UnquotHTML( ByteString &rString )
/*****************************************************************************/
@@ -271,17 +330,20 @@ bool Export::isInitialized = false;
/*****************************************************************************/
void Export::InitLanguages( bool bMergeMode ){
/*****************************************************************************/
- ByteString sTmp;
- ByteStringBoolHashMap aEnvLangs;
- for ( USHORT x = 0; x < sLanguages.GetTokenCount( ',' ); x++ ){
- sTmp = sLanguages.GetToken( x, ',' ).GetToken( 0, '=' );
- sTmp.EraseLeadingAndTrailingChars();
- if( bMergeMode && ( sTmp.EqualsIgnoreCaseAscii("de") || sTmp.EqualsIgnoreCaseAscii("en-US") )){}
- else if( !( (sTmp.GetChar(0)=='x' || sTmp.GetChar(0)=='X') && sTmp.GetChar(1)=='-' ) )
- aLanguages.push_back( sTmp );
+ if( !isInitialized ){
+ ByteString sTmp;
+ ByteStringBoolHashMap aEnvLangs;
+ for ( USHORT x = 0; x < sLanguages.GetTokenCount( ',' ); x++ ){
+ sTmp = sLanguages.GetToken( x, ',' ).GetToken( 0, '=' );
+ sTmp.EraseLeadingAndTrailingChars();
+ if( bMergeMode && ( sTmp.EqualsIgnoreCaseAscii("de") || sTmp.EqualsIgnoreCaseAscii("en-US") )){}
+ else if( !( (sTmp.GetChar(0)=='x' || sTmp.GetChar(0)=='X') && sTmp.GetChar(1)=='-' ) ){
+ aLanguages.push_back( sTmp );
+ }
+ }
+ InitForcedLanguages( bMergeMode );
+ isInitialized = true;
}
- InitForcedLanguages( bMergeMode );
- isInitialized = true;
}
/*****************************************************************************/
void Export::InitForcedLanguages( bool bMergeMode ){