[Libreoffice-commits] core.git: sw/inc sw/source

Matteo Casalin matteo.casalin at yahoo.com
Fri Aug 16 15:08:09 PDT 2013


 sw/inc/section.hxx                 |    2 +
 sw/source/core/docnode/section.cxx |   35 +++++++++++++++++++++++----------
 sw/source/ui/dialog/uiregionsw.cxx |   39 +++++++++++++++++--------------------
 3 files changed, 45 insertions(+), 31 deletions(-)

New commits:
commit 714b30109d0f145d669aebdf08ded251c7f78d52
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date:   Thu Aug 15 20:10:00 2013 +0200

    String to OUString and use helper function
    
    Change-Id: I4c554eb5bf8f15eece755453398d1f1bce24b98b
    Reviewed-on: https://gerrit.libreoffice.org/5442
    Reviewed-by: Michael Stahl <mstahl at redhat.com>
    Tested-by: Michael Stahl <mstahl at redhat.com>

diff --git a/sw/inc/section.hxx b/sw/inc/section.hxx
index db6ce8a..0aea68b 100644
--- a/sw/inc/section.hxx
+++ b/sw/inc/section.hxx
@@ -142,6 +142,8 @@ public:
 
     bool IsConnectFlag() const                  { return m_bConnectFlag; }
     void SetConnectFlag(bool const bFlag = true){ m_bConnectFlag = bFlag; }
+
+    static OUString CollapseWhiteSpaces(const OUString sName);
 };
 
 class SW_DLLPUBLIC SwSection
diff --git a/sw/source/core/docnode/section.cxx b/sw/source/core/docnode/section.cxx
index 6f607e7..bc22f90 100644
--- a/sw/source/core/docnode/section.cxx
+++ b/sw/source/core/docnode/section.cxx
@@ -180,6 +180,23 @@ bool SwSectionData::operator==(SwSectionData const& rOther) const
     // FIXME: old code ignored m_bCondHiddenFlag m_bHiddenFlag m_bConnectFlag
 }
 
+OUString SwSectionData::CollapseWhiteSpaces(const OUString sName)
+{
+    const sal_Int32 nLen = sName.getLength();
+    const sal_Unicode cRef = ' ';
+    OUStringBuffer aBuf(nLen+1);
+    for (sal_Int32 i = 0; i<nLen; )
+    {
+        const sal_Unicode cCur = sName[i++];
+        aBuf.append(cCur);
+        if (cCur!=cRef)
+            continue;
+        while (i<nLen && sName[i]==cRef)
+            ++i;
+    }
+    return aBuf.makeStringAndClear();
+}
+
 // SwSection ===========================================================
 
 SwSection::SwSection(
@@ -1512,11 +1529,7 @@ void SwSection::CreateLink( LinkCreateType eCreateType )
     SwIntrnlSectRefLink *const pLnk =
         static_cast<SwIntrnlSectRefLink*>(& m_RefLink);
 
-    String sCmd( m_Data.GetLinkFileName() );
-    xub_StrLen nPos;
-    while( STRING_NOTFOUND != (nPos = sCmd.SearchAscii( "  " )) )
-        sCmd.Erase( nPos, 1 );
-
+    const OUString sCmd(SwSectionData::CollapseWhiteSpaces(m_Data.GetLinkFileName()));
     pLnk->SetUpdateMode( nUpdateType );
     pLnk->SetVisible( pFmt->GetDoc()->IsVisibleLinks() );
 
@@ -1529,13 +1542,15 @@ void SwSection::CreateLink( LinkCreateType eCreateType )
     case FILE_LINK_SECTION:
         {
             pLnk->SetContentType( FORMAT_FILE );
-            String sFltr( sCmd.GetToken( 1, sfx2::cTokenSeparator ) );
-            String sRange( sCmd.GetToken( 2, sfx2::cTokenSeparator ) );
+            sal_Int32 nIndex = 0;
+            const OUString sFile(sCmd.getToken( 0, sfx2::cTokenSeparator, nIndex ));
+            const OUString sFltr(sCmd.getToken( 0, sfx2::cTokenSeparator, nIndex ));
+            const OUString sRange(sCmd.getToken( 0, sfx2::cTokenSeparator, nIndex ));
             pFmt->GetDoc()->GetLinkManager().InsertFileLink( *pLnk,
                                 static_cast<sal_uInt16>(m_Data.GetType()),
-                                sCmd.GetToken( 0, sfx2::cTokenSeparator ),
-                                ( sFltr.Len() ? &sFltr : 0 ),
-                                ( sRange.Len() ? &sRange : 0 ) );
+                                sFile,
+                                ( !sFltr.isEmpty() ? &sFltr : 0 ),
+                                ( !sRange.isEmpty() ? &sRange : 0 ) );
         }
         break;
     default:
diff --git a/sw/source/ui/dialog/uiregionsw.cxx b/sw/source/ui/dialog/uiregionsw.cxx
index 6f90f31..b3a3b4d 100644
--- a/sw/source/ui/dialog/uiregionsw.cxx
+++ b/sw/source/ui/dialog/uiregionsw.cxx
@@ -1168,13 +1168,13 @@ IMPL_LINK( SwEditRegionDlg, FileNameHdl, Edit *, pEdit )
         m_pSubRegionED->Clear();
         if (m_pDDECB->IsChecked())
         {
-            String sLink( pEdit->GetText() );
-            sal_uInt16 nPos = 0;
-            while( STRING_NOTFOUND != (nPos = sLink.SearchAscii( "  ", nPos )) )
-                sLink.Erase( nPos--, 1 );
-
-            nPos = sLink.SearchAndReplace( ' ', sfx2::cTokenSeparator );
-            sLink.SearchAndReplace( ' ', sfx2::cTokenSeparator, nPos );
+            OUString sLink( SwSectionData::CollapseWhiteSpaces(pEdit->GetText()) );
+            sal_Int32 nPos = 0;
+            sLink = sLink.replaceFirst( " ", OUString(sfx2::cTokenSeparator), &nPos );
+            if (nPos>=0)
+            {
+                sLink = sLink.replaceFirst( " ", OUString(sfx2::cTokenSeparator), &nPos );
+            }
 
             pSectRepr->GetSectionData().SetLinkFileName( sLink );
             pSectRepr->GetSectionData().SetType( DDE_LINK_SECTION );
@@ -1635,17 +1635,16 @@ sal_Bool SwInsertSectionTabPage::FillItemSet( SfxItemSet& )
     sal_Bool bDDe = m_pDDECB->IsChecked();
     if(m_pFileCB->IsChecked() && (sFileName.Len() || sSubRegion.Len() || bDDe))
     {
-        String aLinkFile;
+        OUString aLinkFile;
         if( bDDe )
         {
-            aLinkFile = sFileName;
-
-            sal_uInt16 nPos = 0;
-            while( STRING_NOTFOUND != (nPos = aLinkFile.SearchAscii( "  ", nPos )) )
-                aLinkFile.Erase( nPos--, 1 );
-
-            nPos = aLinkFile.SearchAndReplace( ' ', sfx2::cTokenSeparator );
-            aLinkFile.SearchAndReplace( ' ', sfx2::cTokenSeparator, nPos );
+            aLinkFile = SwSectionData::CollapseWhiteSpaces(sFileName);
+            sal_Int32 nPos = 0;
+            aLinkFile = aLinkFile.replaceFirst( " ", OUString(sfx2::cTokenSeparator), &nPos );
+            if (nPos>=0)
+            {
+                aLinkFile = aLinkFile.replaceFirst( " ", OUString(sfx2::cTokenSeparator), &nPos );
+            }
         }
         else
         {
@@ -1660,14 +1659,12 @@ sal_Bool SwInsertSectionTabPage::FillItemSet( SfxItemSet& )
                 aSection.SetLinkFilePassword( m_sFilePasswd );
             }
 
-            aLinkFile += sfx2::cTokenSeparator;
-            aLinkFile += m_sFilterName;
-            aLinkFile += sfx2::cTokenSeparator;
-            aLinkFile += sSubRegion;
+            aLinkFile += OUString(sfx2::cTokenSeparator) + m_sFilterName
+                      +  OUString(sfx2::cTokenSeparator) + sSubRegion;
         }
 
         aSection.SetLinkFileName(aLinkFile);
-        if(aLinkFile.Len())
+        if (!aLinkFile.isEmpty())
         {
             aSection.SetType( m_pDDECB->IsChecked() ?
                                     DDE_LINK_SECTION :


More information about the Libreoffice-commits mailing list