Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


Am 02.01.2012 23:26, schrieb Eike Rathke:

          if( ! aToken.compareToAscii( "pdf=", 4 ) )
          {
              sal_Int32 nPos = 0;
              aDir = aToken.getToken( 1, '=', nPos );
-            if( ! aDir.Len() )
-                aDir = String( ByteString( getenv( "HOME" ) ), osl_getThreadTextEncoding() );
+            if( aDir.isEmpty() )
+                aDir = rtl::OUString( getenv( "HOME" ), 4, osl_getThreadTextEncoding() );
Trapped ;-)  The string isn't constructed of the word HOME, but the
content of the HOME environment variable instead, so assuming 4 here
isn't correct.
I've corrected that and checked for NULL.
Besides that, already the original code didn't deal with a possible NULL
pointer returned by getenv() in case a HOME variable wasn't set at all..
that should be handled instead of relying on some OUString (back then
String) magic, which it seems OUString does not silently do and would
crash instead if a length>0 was passed.

Otherwise the patch looks good.
I've finished genprnpsp.cxx and had to touch some related files as well (but didn't finish them yet). After a review and removing some unnecessary rtl:: prefices I'd like to push this modified patch.

Thank you for reviewing!

Christina
From 807fc4c27fc8f8b80a1883dd0ef14f0b6749113b Mon Sep 17 00:00:00 2001
From: Christina Rossmanith <ChrRossmanith@web.de>
Date: Mon, 2 Jan 2012 21:56:19 +0100
Subject: [PATCH] Replace (Byte)String with rtl::O(U)String

---
 vcl/generic/print/common_gfx.cxx      |   18 +++++++-------
 vcl/generic/print/genprnpsp.cxx       |   42 ++++++++++++++++----------------
 vcl/generic/print/printerjob.cxx      |    2 +-
 vcl/headless/svpprn.cxx               |    2 +-
 vcl/inc/vcl/ppdparser.hxx             |    3 +-
 vcl/unx/generic/printer/ppdparser.cxx |    4 +-
 6 files changed, 36 insertions(+), 35 deletions(-)

diff --git a/vcl/generic/print/common_gfx.cxx b/vcl/generic/print/common_gfx.cxx
index 43c2cbb..cc3ac02 100644
--- a/vcl/generic/print/common_gfx.cxx
+++ b/vcl/generic/print/common_gfx.cxx
@@ -1188,26 +1188,26 @@ PrinterGfx::DrawEPS( const Rectangle& rBoundingBox, void* pPtr, sal_uInt32 
nSize
     // first search the BoundingBox of the EPS data
     SvMemoryStream aStream( pPtr, nSize, STREAM_READ );
     aStream.Seek( STREAM_SEEK_TO_BEGIN );
-    ByteString aLine;
+    rtl::OString aLine;
 
     rtl::OString aDocTitle;
     double fLeft = 0, fRight = 0, fTop = 0, fBottom = 0;
     bool bEndComments = false;
     while( ! aStream.IsEof()
            && ( ( fLeft == 0 && fRight == 0 && fTop == 0 && fBottom == 0 ) ||
-                ( aDocTitle.getLength() == 0 && bEndComments == false ) )
+                ( aDocTitle.isEmpty() && bEndComments == false ) )
            )
     {
         aStream.ReadLine( aLine );
-        if( aLine.Len() > 1 && aLine.GetChar( 0 ) == '%' )
+        if( aLine.getLength() > 1 && aLine[0] == '%' )
         {
-            char cChar = aLine.GetChar(1);
+            char cChar = aLine[1];
             if( cChar == '%' )
             {
-                if( aLine.CompareIgnoreCaseToAscii( "%%BoundingBox:", 14 ) == COMPARE_EQUAL )
+                if( comphelper::string::matchIgnoreAsciiCaseL( aLine, "%%BoundingBox:", 14 ) == 
sal_True )
                 {
                     aLine = WhitespaceToSpace( comphelper::string::getToken(aLine, 1, ':') );
-                    if( aLine.Len() && aLine.Search( "atend" ) == STRING_NOTFOUND )
+                    if( !aLine.isEmpty() && aLine.indexOf( "atend" ) < 0 )
                     {
                         fLeft   = StringToDouble( GetCommandLineToken( 0, aLine ) );
                         fBottom = StringToDouble( GetCommandLineToken( 1, aLine ) );
@@ -1215,9 +1215,9 @@ PrinterGfx::DrawEPS( const Rectangle& rBoundingBox, void* pPtr, sal_uInt32 
nSize
                         fTop    = StringToDouble( GetCommandLineToken( 3, aLine ) );
                     }
                 }
-                else if( aLine.CompareIgnoreCaseToAscii( "%%Title:", 8 ) == COMPARE_EQUAL )
-                    aDocTitle = WhitespaceToSpace( aLine.Copy( 8 ) );
-                else if( aLine.CompareIgnoreCaseToAscii( "%%EndComments", 13 ) == COMPARE_EQUAL )
+                else if( comphelper::string::matchIgnoreAsciiCaseL( aLine, "%%Title:", 8 ) == 
sal_True )
+                    aDocTitle = WhitespaceToSpace( aLine.copy( 0, 8 ) );
+                else if( comphelper::string::matchIgnoreAsciiCaseL( aLine, "%%EndComments", 13 ) 
== sal_True )
                     bEndComments = true;
             }
             else if( cChar == ' ' || cChar == '\t' || cChar == '\r' || cChar == '\n' )
diff --git a/vcl/generic/print/genprnpsp.cxx b/vcl/generic/print/genprnpsp.cxx
index 23a7bf5..25b21d9 100644
--- a/vcl/generic/print/genprnpsp.cxx
+++ b/vcl/generic/print/genprnpsp.cxx
@@ -47,6 +47,7 @@
 #endif
 
 #include "rtl/ustring.hxx"
+#include "comphelper/string.hxx"
 
 #include "osl/module.h"
 
@@ -86,19 +87,19 @@ typedef int(*faxFunction)(String&);
 static faxFunction pFaxNrFunction           = NULL;
 }
 
-static String getPdfDir( const PrinterInfo& rInfo )
+static rtl::OUString getPdfDir( const PrinterInfo& rInfo )
 {
-    String aDir;
+    rtl::OUString aDir;
     sal_Int32 nIndex = 0;
     while( nIndex != -1 )
     {
-        OUString aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) );
+        rtl::OUString aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) );
         if( ! aToken.compareToAscii( "pdf=", 4 ) )
         {
             sal_Int32 nPos = 0;
             aDir = aToken.getToken( 1, '=', nPos );
-            if( ! aDir.Len() )
-                aDir = String( ByteString( getenv( "HOME" ) ), osl_getThreadTextEncoding() );
+            if( aDir.isEmpty() && getenv( "HOME" ) )
+                aDir = rtl::OUString( getenv( "HOME" ), strlen( getenv( "HOME" ) ), 
osl_getThreadTextEncoding() );
             break;
         }
     }
@@ -137,7 +138,7 @@ static void copyJobDataToJobSetup( ImplJobSetup* pJobSetup, JobData& rData )
     pJobSetup->meOrientation    = (Orientation)(rData.m_eOrientation == orientation::Landscape ? 
ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT);
 
     // copy page size
-    String aPaper;
+    OUString aPaper;
     int width, height;
 
     rData.m_aContext.getPageSize( aPaper, width, height );
@@ -235,20 +236,19 @@ static bool passFileToCommandLine( const String& rFilename, const String& 
rComma
     bool bSuccess = false;
 
     rtl_TextEncoding aEncoding = osl_getThreadTextEncoding();
-    ByteString aCmdLine(rtl::OUStringToOString(rCommandLine, aEncoding));
+    rtl::OString aCmdLine(rtl::OUStringToOString(rCommandLine, aEncoding));
     rtl::OString aFilename(rtl::OUStringToOString(rFilename, aEncoding));
 
-    bool bPipe = aCmdLine.Search( "(TMP)" ) != STRING_NOTFOUND ? false : true;
+    bool bPipe = aCmdLine.indexOf( "(TMP)" ) >= 0 ? false : true;
 
     // setup command line for exec
     if( ! bPipe )
-        while( aCmdLine.SearchAndReplace( "(TMP)", aFilename ) != STRING_NOTFOUND )
-            ;
+        aCmdLine = comphelper::string::replace( aCmdLine, rtl::OString("(TMP)"), aFilename );
 
 #if OSL_DEBUG_LEVEL > 1
     fprintf( stderr, "%s commandline: \"%s\"\n",
              bPipe ? "piping to" : "executing",
-             aCmdLine.GetBuffer() );
+             aCmdLine.getStr() );
     struct stat aStat;
     if( stat( aFilename.getStr(), &aStat ) )
         fprintf( stderr, "stat( %s ) failed\n", aFilename.getStr() );
@@ -258,7 +258,7 @@ static bool passFileToCommandLine( const String& rFilename, const String& rComma
     if( ! ( argv[ 0 ] = getenv( "SHELL" ) ) )
         argv[ 0 ] = "/bin/sh";
     argv[ 1 ] = "-c";
-    argv[ 2 ] = aCmdLine.GetBuffer();
+    argv[ 2 ] = aCmdLine.getStr();
     argv[ 3 ] = 0;
 
     bool bHavePipes = false;
@@ -301,7 +301,7 @@ static bool passFileToCommandLine( const String& rFilename, const String& rComma
                 dup2( fd[0], STDIN_FILENO );
         }
         execv( argv[0], const_cast<char**>(argv) );
-        fprintf( stderr, "failed to execute \"%s\"\n", aCmdLine.GetBuffer() );
+        fprintf( stderr, "failed to execute \"%s\"\n", aCmdLine.getStr() );
         _exit( 1 );
     }
     else
@@ -487,8 +487,8 @@ void SalGenericInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList )
         sal_Int32 nIndex = 0;
         while( nIndex != -1 )
         {
-            String aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) );
-            if( aToken.CompareToAscii( "pdf=", 4 ) == COMPARE_EQUAL )
+            rtl::OUString aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) );
+            if( aToken.compareToAscii( "pdf=", 4 ) == 0 )
             {
                 pInfo->maLocation = getPdfDir( rInfo );
                 break;
@@ -774,7 +774,7 @@ void PspSalInfoPrinter::GetPageInfo(
     if( aData.m_pParser )
     {
 
-        String aPaper;
+        OUString aPaper;
         int width, height;
         int left = 0, top = 0, right = 0, bottom = 0;
         int nDPI = aData.m_aContext.getRenderResolution();
@@ -808,7 +808,7 @@ sal_uLong PspSalInfoPrinter::GetPaperBinCount( const ImplJobSetup* pJobSetup )
     JobData aData;
     JobData::constructFromStreamBuffer( pJobSetup->mpDriverData, pJobSetup->mnDriverDataLen, aData 
);
 
-    const PPDKey* pKey = aData.m_pParser ? aData.m_pParser->getKey( String( 
RTL_CONSTASCII_USTRINGPARAM( "InputSlot" ) ) ): NULL;
+    const PPDKey* pKey = aData.m_pParser ? aData.m_pParser->getKey( OUString( 
RTL_CONSTASCII_USTRINGPARAM( "InputSlot" ) ) ): NULL;
     return pKey ? pKey->countValues() : 0;
 }
 
@@ -817,10 +817,10 @@ rtl::OUString PspSalInfoPrinter::GetPaperBinName( const ImplJobSetup* 
pJobSetup,
     JobData aData;
     JobData::constructFromStreamBuffer( pJobSetup->mpDriverData, pJobSetup->mnDriverDataLen, aData 
);
 
-    String aRet;
+    OUString aRet;
     if( aData.m_pParser )
     {
-        const PPDKey* pKey = aData.m_pParser ? aData.m_pParser->getKey( String( 
RTL_CONSTASCII_USTRINGPARAM( "InputSlot" ) ) ): NULL;
+        const PPDKey* pKey = aData.m_pParser ? aData.m_pParser->getKey( OUString( 
RTL_CONSTASCII_USTRINGPARAM( "InputSlot" ) ) ): NULL;
         if( ! pKey || nPaperBin >= (sal_uLong)pKey->countValues() )
             aRet = aData.m_pParser->getDefaultInputSlot();
         else
@@ -848,8 +848,8 @@ sal_uLong PspSalInfoPrinter::GetCapabilities( const ImplJobSetup* pJobSetup, sal
             JobData aData;
             JobData::constructFromStreamBuffer( pJobSetup->mpDriverData, 
pJobSetup->mnDriverDataLen, aData );
 
-            const PPDKey* pKey = aData.m_pParser ? aData.m_pParser->getKey( String( 
RTL_CONSTASCII_USTRINGPARAM( "Collate" ) ) ) : NULL;
-            const PPDValue* pVal = pKey ? pKey->getValue( String( RTL_CONSTASCII_USTRINGPARAM( 
"True" ) ) ) : NULL;
+            const PPDKey* pKey = aData.m_pParser ? aData.m_pParser->getKey( OUString( 
RTL_CONSTASCII_USTRINGPARAM( "Collate" ) ) ) : NULL;
+            const PPDValue* pVal = pKey ? pKey->getValue( OUString( RTL_CONSTASCII_USTRINGPARAM( 
"True" ) ) ) : NULL;
 
             // PPDs don't mention the number of possible collated copies.
             // so let's guess as many as we want ?
diff --git a/vcl/generic/print/printerjob.cxx b/vcl/generic/print/printerjob.cxx
index 33a32da..423424d 100644
--- a/vcl/generic/print/printerjob.cxx
+++ b/vcl/generic/print/printerjob.cxx
@@ -578,7 +578,7 @@ PrinterJob::InitPaperSize (const JobData& rJobSetup)
 {
     int nRes = rJobSetup.m_aContext.getRenderResolution ();
 
-    String aPaper;
+    rtl::OUString aPaper;
     int nWidth, nHeight;
     rJobSetup.m_aContext.getPageSize (aPaper, nWidth, nHeight);
 
diff --git a/vcl/headless/svpprn.cxx b/vcl/headless/svpprn.cxx
index b7e4dbb..eca65e3 100644
--- a/vcl/headless/svpprn.cxx
+++ b/vcl/headless/svpprn.cxx
@@ -78,7 +78,7 @@ static void copyJobDataToJobSetup( ImplJobSetup* pJobSetup, JobData& rData )
     pJobSetup->meOrientation    = (Orientation)(rData.m_eOrientation == orientation::Landscape ? 
ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT);
 
     // copy page size
-    String aPaper;
+    OUString aPaper;
     int width, height;
 
     rData.m_aContext.getPageSize( aPaper, width, height );
diff --git a/vcl/inc/vcl/ppdparser.hxx b/vcl/inc/vcl/ppdparser.hxx
index 0437c5b..0cc316c 100644
--- a/vcl/inc/vcl/ppdparser.hxx
+++ b/vcl/inc/vcl/ppdparser.hxx
@@ -34,6 +34,7 @@
 
 #include "tools/string.hxx"
 #include "tools/stream.hxx"
+#include "rtl/string.hxx"
 
 #include "vcl/dllapi.h"
 
@@ -309,7 +310,7 @@ public:
 
     // width, height in points, paper will contain the name of the selected
     // paper after the call
-    void getPageSize( String& rPaper, int& rWidth, int& rHeight ) const;
+    void getPageSize( rtl::OUString& rPaper, int& rWidth, int& rHeight ) const;
 };
 
 } // namespace
diff --git a/vcl/unx/generic/printer/ppdparser.cxx b/vcl/unx/generic/printer/ppdparser.cxx
index 738df2d..a34d9c9 100644
--- a/vcl/unx/generic/printer/ppdparser.cxx
+++ b/vcl/unx/generic/printer/ppdparser.cxx
@@ -1969,10 +1969,10 @@ int PPDContext::getRenderResolution() const
 
 // -------------------------------------------------------------------
 
-void PPDContext::getPageSize( String& rPaper, int& rWidth, int& rHeight ) const
+void PPDContext::getPageSize( rtl::OUString& rPaper, int& rWidth, int& rHeight ) const
 {
     // initialize to reasonable default, if parser is not set
-    rPaper  = String( RTL_CONSTASCII_USTRINGPARAM( "A4" ) );
+    rPaper  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "A4" ) );
     rWidth  = 595;
     rHeight = 842;
     if( m_pParser )
-- 
1.7.4.1


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.