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


Hi,

currently I'm removing the Fill() method for strings. Comments are very welcome.

Christina
From 278bc39f8f3914cff1b5d860b74dd5c12d17af7c Mon Sep 17 00:00:00 2001
From: Christina Rossmanith <ChrRossmanith@web.de>
Date: Fri, 11 Nov 2011 23:09:26 +0100
Subject: [PATCH] Remove String::Fill() usage

---
 sc/source/ui/docshell/docsh.cxx |   41 ++++++++++++++++++++++----------------
 1 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 93bb4bc..4a0981d 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -134,6 +134,7 @@
 #include <rtl/logfile.hxx>
 
 #include <comphelper/processfactory.hxx>
+#include <comphelper/string.hxx>
 #include "uiitems.hxx"
 #include "cellsuno.hxx"
 #include "dpobject.hxx"
@@ -1593,7 +1594,7 @@ sal_Bool ScDocShell::IsInformationLost()
 
 
 // Xcl-like column width measured in characters of standard font.
-xub_StrLen lcl_ScDocShell_GetColWidthInChars( sal_uInt16 nWidth )
+sal_Int32 lcl_ScDocShell_GetColWidthInChars( sal_uInt16 nWidth )
 {
     double f = nWidth;
     f *= 1328.0 / 25.0;
@@ -1601,46 +1602,52 @@ xub_StrLen lcl_ScDocShell_GetColWidthInChars( sal_uInt16 nWidth )
     f *= 1.0 / 23.0;
     f /= 256.0;
 
-    return xub_StrLen( f );
+    return sal_Int32( f );
 }
 
 
 void lcl_ScDocShell_GetFixedWidthString( rtl::OUString& rStr, const ScDocument& rDoc,
         SCTAB nTab, SCCOL nCol, sal_Bool bValue, SvxCellHorJustify eHorJust )
 {
-    String aString = rStr;
-    xub_StrLen nLen = lcl_ScDocShell_GetColWidthInChars(
+    rtl::OUString aString = rStr;
+    sal_Int32 nLen = lcl_ScDocShell_GetColWidthInChars(
             rDoc.GetColWidth( nCol, nTab ) );
-    if ( nLen < aString.Len() )
+    if ( nLen < aString.getLength() )
     {
         if ( bValue )
-            aString.AssignAscii( "###" );
-        aString.Erase( nLen );
+            aString = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "###" ));
     }
-    if ( nLen > aString.Len() )
+    if ( nLen > aString.getLength() )
     {
         if ( bValue && eHorJust == SVX_HOR_JUSTIFY_STANDARD )
             eHorJust = SVX_HOR_JUSTIFY_RIGHT;
+        sal_Int32  nBlanks = nLen - aString.getLength();
         switch ( eHorJust )
         {
             case SVX_HOR_JUSTIFY_RIGHT:
             {
-                String aTmp;
-                aTmp.Fill( nLen - aString.Len() );
-                aString.Insert( aTmp, 0 );
+                rtl::OUStringBuffer aTmp;
+                aTmp = comphelper::string::padToLength( aTmp, nBlanks, ' ' );
+                aString = aTmp.append(aString).makeStringAndClear();
             }
             break;
             case SVX_HOR_JUSTIFY_CENTER:
             {
-                xub_StrLen nLen2 = (nLen - aString.Len()) / 2;
-                String aTmp;
-                aTmp.Fill( nLen2 );
-                aString.Insert( aTmp, 0 );
-                aString.Expand( nLen );
+                sal_Int32 nLen2 = nBlanks / 2;
+                rtl::OUStringBuffer aLeft;
+                rtl::OUStringBuffer aRight;
+                aLeft = comphelper::string::padToLength( aLeft, nLen2, ' ' );
+                aRight = comphelper::string::padToLength( aRight, nBlanks - nLen2, ' ' );
+                aString = aLeft.append(aString).makeStringAndClear();
+                aString += aRight.makeStringAndClear();
             }
             break;
             default:
-                aString.Expand( nLen );
+            {
+                rtl::OUStringBuffer aTmp;
+                comphelper::string::padToLength( aTmp, nBlanks, ' ' );
+                aString += aTmp.makeStringAndClear();
+            }
         }
     }
     rStr = aString;
-- 
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.