diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-11-16 22:19:58 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-11-17 23:04:10 +0000 |
commit | dca04e236193db7de908aad746fd4539e78eb428 (patch) | |
tree | 9808f843924944a740ca8037094d4d5c4553bbc8 /l10ntools | |
parent | c4927a1b76b728b2208c29d09dbf54e70bb26e13 (diff) |
add a StringUtils-alike remove (can replace EraseAllChars)
Diffstat (limited to 'l10ntools')
-rw-r--r-- | l10ntools/inc/export.hxx | 4 | ||||
-rw-r--r-- | l10ntools/source/export2.cxx | 54 | ||||
-rw-r--r-- | l10ntools/source/lngmerge.cxx | 15 |
3 files changed, 45 insertions, 28 deletions
diff --git a/l10ntools/inc/export.hxx b/l10ntools/inc/export.hxx index 0058cf143f9c..94d59256f127 100644 --- a/l10ntools/inc/export.hxx +++ b/l10ntools/inc/export.hxx @@ -329,8 +329,8 @@ public: static std::vector<ByteString> GetForcedLanguages(); static void SetLanguages( std::vector<ByteString> val ); - static void RemoveUTF8ByteOrderMarker( ByteString &rString ); - static bool hasUTF8ByteOrderMarker( const ByteString &rString ); + static void RemoveUTF8ByteOrderMarker( rtl::OString &rString ); + static bool hasUTF8ByteOrderMarker( const rtl::OString &rString ); static void RemoveUTF8ByteOrderMarkerFromFile( const ByteString &rFilename ); static bool fileHasUTF8ByteOrderMarker( const ByteString &rString ); static void QuotHTML( ByteString &rString ); diff --git a/l10ntools/source/export2.cxx b/l10ntools/source/export2.cxx index 26f99b59e7c8..72ffde06f777 100644 --- a/l10ntools/source/export2.cxx +++ b/l10ntools/source/export2.cxx @@ -192,35 +192,43 @@ void Export::QuotHTML( ByteString &rString ) rString = sReturn.makeStringAndClear(); } -void Export::RemoveUTF8ByteOrderMarker( ByteString &rString ){ +void Export::RemoveUTF8ByteOrderMarker( rtl::OString &rString ) +{ if( hasUTF8ByteOrderMarker( rString ) ) - rString.Erase( 0 , 3 ); + rString = rString.copy(3); } -bool Export::hasUTF8ByteOrderMarker( const ByteString &rString ){ - return rString.Len() >= 3 && - rString.GetChar( 0 ) == '\xEF' && - rString.GetChar( 1 ) == '\xBB' && - rString.GetChar( 2 ) == '\xBF' ; +bool Export::hasUTF8ByteOrderMarker( const rtl::OString &rString ) +{ + return rString.getLength() >= 3 && rString[0] == '\xEF' && + rString[1] == '\xBB' && rString[2] == '\xBF' ; } -bool Export::fileHasUTF8ByteOrderMarker( const ByteString &rString ){ + +bool Export::fileHasUTF8ByteOrderMarker( const ByteString &rString ) +{ SvFileStream aFileIn( String( rString , RTL_TEXTENCODING_ASCII_US ) , STREAM_READ ); - ByteString sLine; - if( !aFileIn.IsEof() ) { + rtl::OString sLine; + if( !aFileIn.IsEof() ) + { aFileIn.ReadLine( sLine ); - if( aFileIn.IsOpen() ) aFileIn.Close(); + if( aFileIn.IsOpen() ) + aFileIn.Close(); return hasUTF8ByteOrderMarker( sLine ); } if( aFileIn.IsOpen() ) aFileIn.Close(); return false; } -void Export::RemoveUTF8ByteOrderMarkerFromFile( const ByteString &rFilename ){ + +void Export::RemoveUTF8ByteOrderMarkerFromFile( const ByteString &rFilename ) +{ SvFileStream aFileIn( String( rFilename , RTL_TEXTENCODING_ASCII_US ) , STREAM_READ ); - ByteString sLine; - if( !aFileIn.IsEof() ) { + rtl::OString sLine; + if( !aFileIn.IsEof() ) + { aFileIn.ReadLine( sLine ); // Test header - if( hasUTF8ByteOrderMarker( sLine ) ){ + if( hasUTF8ByteOrderMarker( sLine ) ) + { DirEntry aTempFile = Export::GetTempFile(); ByteString sTempFile = ByteString( aTempFile.GetFull() , RTL_TEXTENCODING_ASCII_US ); SvFileStream aNewFile( String( sTempFile , RTL_TEXTENCODING_ASCII_US ) , STREAM_WRITE ); @@ -228,7 +236,8 @@ void Export::RemoveUTF8ByteOrderMarkerFromFile( const ByteString &rFilename ){ RemoveUTF8ByteOrderMarker( sLine ); aNewFile.WriteLine( sLine ); // Copy the rest - while( !aFileIn.IsEof() ){ + while( !aFileIn.IsEof() ) + { aFileIn.ReadLine( sLine ); aNewFile.WriteLine( sLine ); } @@ -239,7 +248,8 @@ void Export::RemoveUTF8ByteOrderMarkerFromFile( const ByteString &rFilename ){ DirEntry( sTempFile ).MoveTo( DirEntry( rFilename.GetBuffer() ) ); } } - if( aFileIn.IsOpen() ) aFileIn.Close(); + if( aFileIn.IsOpen() ) + aFileIn.Close(); } bool Export::CopyFile( const ByteString& source , const ByteString& dest ) @@ -398,12 +408,14 @@ sal_Bool Export::ConvertLineEnds( return sal_False; } - ByteString sLine; + rtl::OString sLine; - while ( !aSource.IsEof()) { + while ( !aSource.IsEof()) + { aSource.ReadLine( sLine ); - if ( !aSource.IsEof()) { - sLine.EraseAllChars( '\r' ); + if ( !aSource.IsEof()) + { + sLine = comphelper::string::remove(sLine, '\r'); aDestination.WriteLine( sLine ); } else diff --git a/l10ntools/source/lngmerge.cxx b/l10ntools/source/lngmerge.cxx index f166595c09bf..7592d4979160 100644 --- a/l10ntools/source/lngmerge.cxx +++ b/l10ntools/source/lngmerge.cxx @@ -52,15 +52,20 @@ LngParser::LngParser( const ByteString &rLngFile, sal_Bool bUTF8, sal_Bool bULFF { pLines = new LngLineList(); DirEntry aEntry( String( sSource, RTL_TEXTENCODING_ASCII_US )); - if ( aEntry.Exists()) { + if ( aEntry.Exists()) + { SvFileStream aStream( String( sSource, RTL_TEXTENCODING_ASCII_US ), STREAM_STD_READ ); - if ( aStream.IsOpen()) { - ByteString sLine; + if ( aStream.IsOpen()) + { + rtl::OString sLine; bool bFirstLine = true; - while ( !aStream.IsEof()) { + while ( !aStream.IsEof()) + { aStream.ReadLine( sLine ); - if( bFirstLine ){ // Always remove UTF8 BOM from the first line + if( bFirstLine ) + { + // Always remove UTF8 BOM from the first line Export::RemoveUTF8ByteOrderMarker( sLine ); bFirstLine = false; } |