[Libreoffice-commits] core.git: sw/source
Matteo Casalin
matteo.casalin at yahoo.com
Sun Aug 25 08:13:21 PDT 2013
sw/source/filter/ww8/attributeoutputbase.hxx | 3
sw/source/filter/ww8/docxattributeoutput.cxx | 42 ++++-------
sw/source/filter/ww8/docxattributeoutput.hxx | 2
sw/source/filter/ww8/wrtw8nds.cxx | 98 +++++++++++----------------
sw/source/filter/ww8/wrtww8.hxx | 2
sw/source/filter/ww8/ww8atr.cxx | 7 -
sw/source/filter/ww8/ww8attributeoutput.hxx | 2
7 files changed, 66 insertions(+), 90 deletions(-)
New commits:
commit e19804aabac1e6beae444bc9d8918b8fc78868cd
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date: Sat Aug 24 17:29:44 2013 +0200
String to OUString and some cleanup
Change-Id: I78790a84fc86bd852899aebbaff526c7cec224cf
Reviewed-on: https://gerrit.libreoffice.org/5618
Reviewed-by: Michael Stahl <mstahl at redhat.com>
Tested-by: Michael Stahl <mstahl at redhat.com>
diff --git a/sw/source/filter/ww8/attributeoutputbase.hxx b/sw/source/filter/ww8/attributeoutputbase.hxx
index cadce5a..c415d3c 100644
--- a/sw/source/filter/ww8/attributeoutputbase.hxx
+++ b/sw/source/filter/ww8/attributeoutputbase.hxx
@@ -118,6 +118,7 @@ class SwNumRule;
class wwFont;
class String;
+namespace rtl { class OUString; }
class MSWordExportBase;
@@ -574,7 +575,7 @@ protected:
virtual bool DropdownField( const SwField* pFld ) = 0;
virtual bool PlaceholderField( const SwField* pFld ) = 0;
- virtual bool AnalyzeURL( const String& rUrl, const String& rTarget, String* pLinkURL, String* pMark );
+ virtual bool AnalyzeURL( const OUString& rUrl, const OUString& rTarget, OUString* pLinkURL, OUString* pMark );
ww8::GridColsPtr GetGridCols( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner );
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 8188fd6..5fa9713 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -1260,48 +1260,38 @@ void DocxAttributeOutput::EndRuby()
m_pSerializer->endElementNS( XML_w, XML_ruby );
}
-bool DocxAttributeOutput::AnalyzeURL( const String& rUrl, const String& rTarget, String* pLinkURL, String* pMark )
+bool DocxAttributeOutput::AnalyzeURL( const OUString& rUrl, const OUString& rTarget, OUString* pLinkURL, OUString* pMark )
{
bool bBookMarkOnly = AttributeOutputBase::AnalyzeURL( rUrl, rTarget, pLinkURL, pMark );
- String sURL = *pLinkURL;
- String sMark = *pMark;
-
- bool bOutputField = sMark.Len();
-
- if ( bOutputField )
+ if ( !pMark->isEmpty() )
{
+ OUString sURL = *pLinkURL;
+
if ( bBookMarkOnly )
sURL = FieldString( ww::eHYPERLINK );
else
- {
- String sFld( FieldString( ww::eHYPERLINK ) );
- sFld.AppendAscii( "\"" );
- sURL.Insert( sFld, 0 );
- sURL += '\"';
- }
+ sURL = FieldString( ww::eHYPERLINK ) + "\"" + sURL + "\"";
- if ( sMark.Len() )
- ( ( sURL.AppendAscii( " \\l \"" ) ) += sMark ) += '\"';
+ sURL += " \\l \"" + *pMark + "\"";
- if ( rTarget.Len() )
- ( sURL.AppendAscii( " \\n " ) ) += rTarget;
- }
+ if ( !rTarget.isEmpty() )
+ sURL += " \\n " + rTarget;
- *pLinkURL = sURL;
- *pMark = sMark;
+ *pLinkURL = sURL;
+ }
return bBookMarkOnly;
}
bool DocxAttributeOutput::StartURL( const String& rUrl, const String& rTarget )
{
- String sMark;
- String sUrl;
+ OUString sMark;
+ OUString sUrl;
bool bBookmarkOnly = AnalyzeURL( rUrl, rTarget, &sUrl, &sMark );
- if ( sMark.Len() && !bBookmarkOnly )
+ if ( !sMark.isEmpty() && !bBookmarkOnly )
{
m_rExport.OutputField( NULL, ww::eHYPERLINK, sUrl );
}
@@ -1312,17 +1302,15 @@ bool DocxAttributeOutput::StartURL( const String& rUrl, const String& rTarget )
if ( !bBookmarkOnly )
{
- OUString osUrl( sUrl );
-
OString sId = OUStringToOString( GetExport().GetFilter().addRelation( m_pSerializer->getOutputStream(),
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",
- osUrl, true ), RTL_TEXTENCODING_UTF8 );
+ sUrl, true ), RTL_TEXTENCODING_UTF8 );
m_pHyperlinkAttrList->add( FSNS( XML_r, XML_id), sId.getStr());
}
else
m_pHyperlinkAttrList->add( FSNS( XML_w, XML_anchor ),
- OUStringToOString( OUString( sMark ), RTL_TEXTENCODING_UTF8 ).getStr( ) );
+ OUStringToOString( sMark, RTL_TEXTENCODING_UTF8 ).getStr( ) );
OUString sTarget( rTarget );
if ( !sTarget.isEmpty() )
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index e02eaae..a6c4532 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -578,7 +578,7 @@ protected:
virtual bool DropdownField( const SwField* pFld );
virtual bool PlaceholderField( const SwField* pFld );
- virtual bool AnalyzeURL( const String& rURL, const String& rTarget, String* pLinkURL, String* pMark );
+ virtual bool AnalyzeURL( const OUString& rURL, const OUString& rTarget, OUString* pLinkURL, OUString* pMark );
/// Reference to the export, where to get the data from
DocxExport &m_rExport;
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx
index 7af0c2e..4664938 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -749,84 +749,73 @@ String &TruncateBookmark( String &rRet )
return rRet;
}
-bool AttributeOutputBase::AnalyzeURL( const String& rUrl, const String& /*rTarget*/, String* pLinkURL, String* pMark )
+bool AttributeOutputBase::AnalyzeURL( const OUString& rUrl, const OUString& /*rTarget*/, OUString* pLinkURL, OUString* pMark )
{
bool bBookMarkOnly = false;
- INetURLObject aURL( rUrl );
- String sMark;
- String sURL;
+ OUString sMark;
+ OUString sURL;
- if ( rUrl.Len() > 1 && rUrl.GetChar(0) == INET_MARK_TOKEN )
+ if ( rUrl.getLength() > 1 && rUrl[0] == INET_MARK_TOKEN )
{
- sMark = BookmarkToWriter( rUrl.Copy(1) );
+ sMark = BookmarkToWriter( rUrl.copy(1) );
- xub_StrLen nPos = sMark.SearchBackward( cMarkSeparator );
+ const sal_Int32 nPos = sMark.lastIndexOf( cMarkSeparator );
- String sRefType(comphelper::string::remove(sMark.Copy(nPos+1), ' '));
+ const OUString sRefType(nPos>=0 && nPos+1<sMark.getLength() ?
+ sMark.copy(nPos+1).replaceAll(" ", "") :
+ OUString());
// #i21465# Only interested in outline references
- if ( sRefType.EqualsAscii( pMarkToOutline ) )
+ if ( sRefType.equalsAscii( pMarkToOutline ) )
{
- String sLink = sMark.Copy(0, nPos);
+ OUString sLink = sMark.copy(0, nPos);
SwImplBookmarksIter bkmkIterEnd = GetExport().maImplicitBookmarks.end();
for ( SwImplBookmarksIter aIter = GetExport().maImplicitBookmarks.begin(); aIter != bkmkIterEnd; ++aIter )
{
- String bkmkName = aIter->first;
-
- if ( bkmkName == sLink )
+ if ( aIter->first == sLink )
{
- sMark = String( "_toc" );
- sMark += OUString::number( aIter->second );
+ sMark = "_toc" + OUString::number( aIter->second );
}
}
}
}
else
{
+ INetURLObject aURL( rUrl );
sURL = aURL.GetURLNoMark( INetURLObject::DECODE_UNAMBIGUOUS );
sMark = aURL.GetMark( INetURLObject::DECODE_UNAMBIGUOUS );
-
}
- if ( sMark.Len() && !sURL.Len() )
+ if ( !sMark.isEmpty() && sURL.isEmpty() )
bBookMarkOnly = true;
-
-
*pMark = sMark;
*pLinkURL = sURL;
return bBookMarkOnly;
}
-bool WW8AttributeOutput::AnalyzeURL( const String& rUrl, const String& rTarget, String* pLinkURL, String* pMark )
+bool WW8AttributeOutput::AnalyzeURL( const OUString& rUrl, const OUString& rTarget, OUString* pLinkURL, OUString* pMark )
{
bool bBookMarkOnly = AttributeOutputBase::AnalyzeURL( rUrl, rTarget, pLinkURL, pMark );
- String sURL = *pLinkURL;
- String sMark = *pMark;
+ OUString sURL = *pLinkURL;
- if ( sURL.Len() )
+ if ( !sURL.isEmpty() )
sURL = URIHelper::simpleNormalizedMakeRelative( m_rWW8Export.GetWriter().GetBaseURL(), sURL );
if ( bBookMarkOnly )
sURL = FieldString( ww::eHYPERLINK );
else
- {
- String sFld( FieldString( ww::eHYPERLINK ) );
- sFld.AppendAscii( "\"" );
- sURL.Insert( sFld, 0 );
- sURL += '\"';
- }
+ sURL = FieldString( ww::eHYPERLINK ) + "\"" + sURL + "\"";
- if ( sMark.Len() )
- ( ( sURL.AppendAscii( " \\l \"" ) ) += sMark ) += '\"';
+ if ( !pMark->isEmpty() )
+ sURL += " \\l \"" + *pMark + "\"";
- if ( rTarget.Len() )
- ( sURL.AppendAscii( " \\n " ) ) += rTarget;
+ if ( !rTarget.isEmpty() )
+ sURL += " \\n " + rTarget;
*pLinkURL = sURL;
- *pMark = sMark;
return bBookMarkOnly;
}
@@ -838,8 +827,8 @@ bool WW8AttributeOutput::StartURL( const String &rUrl, const String &rTarget )
return false;
INetURLObject aURL( rUrl );
- String sURL;
- String sMark;
+ OUString sURL;
+ OUString sMark;
bool bBookMarkOnly = AnalyzeURL( rUrl, rTarget, &sURL, &sMark );
@@ -895,7 +884,7 @@ bool WW8AttributeOutput::StartURL( const String &rUrl, const String &rTarget )
m_rWW8Export.pDataStrm->Write( aURLData1, sizeof( aURLData1 ) );
/* Write HFD Structure */
sal_uInt8 nAnchor = 0x00;
- if ( sMark.Len() )
+ if ( !sMark.isEmpty() )
nAnchor = 0x08;
m_rWW8Export.pDataStrm->Write( &nAnchor, 1 ); // HFDBits
m_rWW8Export.pDataStrm->Write( MAGIC_A, sizeof(MAGIC_A) ); //clsid
@@ -905,7 +894,7 @@ bool WW8AttributeOutput::StartURL( const String &rUrl, const String &rTarget )
sal_uInt32 nFlag = bBookMarkOnly ? 0 : 0x01;
if ( bAbsolute )
nFlag |= 0x02;
- if ( sMark.Len() )
+ if ( !sMark.isEmpty() )
nFlag |= 0x08;
SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, nFlag );
@@ -928,37 +917,36 @@ bool WW8AttributeOutput::StartURL( const String &rUrl, const String &rTarget )
// save the links to files as relative
sURL = URIHelper::simpleNormalizedMakeRelative( m_rWW8Export.GetWriter().GetBaseURL(), sURL );
- if ( eProto == INET_PROT_FILE && sURL.EqualsAscii( "/", 0, 1 ) )
+ if ( eProto == INET_PROT_FILE && sURL.startsWith( "/" ) )
sURL = aURL.PathToFileName();
// special case for the absolute windows names
// (convert '/c:/foo/bar.doc' into 'c:\foo\bar.doc')
- sal_Unicode aDrive = ( sURL.Len() > 1 )? sURL.GetChar( 1 ): 0;
- if ( sURL.EqualsAscii( "/", 0, 1 ) &&
- ( ( aDrive >= 'A' && aDrive <= 'Z' ) || ( aDrive >= 'a' && aDrive <= 'z' ) ) &&
- sURL.EqualsAscii( ":", 2, 1 ) )
+ if (sURL.getLength()>=3)
{
- sURL.Erase( 0, 1 );
- sURL.SearchAndReplaceAll( '/', '\\' );
+ const sal_Unicode aDrive = sURL[1];
+ if ( sURL[0]=='/' && sURL[2]==':' &&
+ ( (aDrive>='A' && aDrive<='Z' ) || (aDrive>='a' && aDrive<='z') ) )
+ {
+ sURL = sURL.copy(1).replaceAll("/", "\\");
+ }
}
// n#261623 convert smb notation to '\\'
const char pSmb[] = "smb://";
- if ( eProto == INET_PROT_SMB &&
- sURL.EqualsAscii( pSmb, 0, sizeof( pSmb ) - 1 ) )
+ if ( eProto == INET_PROT_SMB && sURL.startsWith( pSmb ) )
{
- sURL.Erase( 0, sizeof( pSmb ) - 3 );
- sURL.SearchAndReplaceAll( '/', '\\' );
+ sURL = sURL.copy( sizeof(pSmb)-3 ).replaceAll( "/", "\\" );
}
m_rWW8Export.pDataStrm->Write( MAGIC_C, sizeof(MAGIC_C) );
- SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, sURL.Len()+1 );
+ SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, sURL.getLength()+1 );
SwWW8Writer::WriteString8( *m_rWW8Export.pDataStrm, sURL, true,
RTL_TEXTENCODING_MS_1252 );
m_rWW8Export.pDataStrm->Write( MAGIC_D, sizeof( MAGIC_D ) );
- SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, 2*sURL.Len() + 6 );
- SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, 2*sURL.Len() );
+ SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, 2*sURL.getLength() + 6 );
+ SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, 2*sURL.getLength() );
SwWW8Writer::WriteShort( *m_rWW8Export.pDataStrm, 3 );
SwWW8Writer::WriteString16( *m_rWW8Export.pDataStrm, sURL, false );
}
@@ -974,13 +962,13 @@ bool WW8AttributeOutput::StartURL( const String &rUrl, const String &rTarget )
};
m_rWW8Export.pDataStrm->Write( MAGIC_B, sizeof(MAGIC_B) );
- SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, 2 * ( sURL.Len() + 1 ) );
+ SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, 2 * ( sURL.getLength() + 1 ) );
SwWW8Writer::WriteString16( *m_rWW8Export.pDataStrm, sURL, true );
}
- if ( sMark.Len() )
+ if ( !sMark.isEmpty() )
{
- SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, sMark.Len()+1 );
+ SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, sMark.getLength()+1 );
SwWW8Writer::WriteString16( *m_rWW8Export.pDataStrm, sMark, true );
}
SwWW8Writer::WriteLong( *m_rWW8Export.pDataStrm, nDataStt,
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index 01d32c2..b082755 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -1546,7 +1546,7 @@ public:
sal_Int16 GetWordFirstLineOffset(const SwNumFmt &rFmt);
// A bit of a bag on the side for now
-String FieldString(ww::eField eIndex);
+OUString FieldString(ww::eField eIndex);
String BookmarkToWord(const String &rBookmark);
class WW8SHDLong
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 2133eb5..188b995 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -2401,12 +2401,11 @@ void WW8Export::WritePostItBegin( ww::bytes* pOut )
pChpPlc->AppendFkpEntry( Strm().Tell(), static_cast< short >(pArr - aArr), aArr );
}
-String FieldString(ww::eField eIndex)
+OUString FieldString(ww::eField eIndex)
{
- String sRet(OUString(" "));
if (const char *pField = ww::GetEnglishFieldName(eIndex))
- sRet.InsertAscii(pField, 1);
- return sRet;
+ return " " + OUString::createFromAscii(pField) + " ";
+ return OUString(" ");
}
void WW8AttributeOutput::HiddenField( const SwField& rFld )
diff --git a/sw/source/filter/ww8/ww8attributeoutput.hxx b/sw/source/filter/ww8/ww8attributeoutput.hxx
index 97419ba..3ffb2aa 100644
--- a/sw/source/filter/ww8/ww8attributeoutput.hxx
+++ b/sw/source/filter/ww8/ww8attributeoutput.hxx
@@ -396,7 +396,7 @@ protected:
virtual bool DropdownField( const SwField* pFld );
virtual bool PlaceholderField( const SwField* pFld );
- virtual bool AnalyzeURL( const String& rURL, const String& rTarget, String* pLinkURL, String* pMark );
+ virtual bool AnalyzeURL( const OUString& rURL, const OUString& rTarget, OUString* pLinkURL, OUString* pMark );
/// Reference to the export, where to get the data from
WW8Export &m_rWW8Export;
More information about the Libreoffice-commits
mailing list