diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-11-17 08:59:01 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-11-17 09:22:14 +0100 |
commit | acd78552de4179d869cf7061dffab22063466f1c (patch) | |
tree | f6a4290977b5c9a7ea35373ac5f9b366b5b0f48a | |
parent | e47b43f4c2fd2a634469b3f2797352d0e3d09ca3 (diff) |
Add rtl::OUString::toUtf8()
There is rtl::OUStringToOString() already to do OUString to OString conversion
using UTF-8 encoding on a best effort basis. However multiple modules have
code where we assume that such a conversion is perfect. Add a new method that
asserts such an expected success instead of duplicating it at multiple places.
Change-Id: I0e55b53f558df82b67af6a463c8144655cf0ca74
-rw-r--r-- | include/rtl/ustring.hxx | 23 | ||||
-rw-r--r-- | oox/source/export/drawingml.cxx | 6 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 2 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexport.cxx | 4 |
4 files changed, 29 insertions, 6 deletions
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx index b9a868b314a0..66b320f09636 100644 --- a/include/rtl/ustring.hxx +++ b/include/rtl/ustring.hxx @@ -2106,6 +2106,29 @@ public: } /** + * Convert this string to an OString, assuming that the string can be + * UTF-8-encoded successfully. + * + * In other words, you must not use this method on a random sequence of + * UTF-16 code units, but only at places where it is assumed that the + * content is a proper string. + * + * @since LibreOffice 4.4 + */ + inline OString toUtf8() const + { + OString aTarget; + bool bSuccess = rtl_convertUStringToString(&aTarget.pData, + getStr(), + getLength(), + RTL_TEXTENCODING_UTF8, + RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR|RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR); + (void) bSuccess; + assert(bSuccess); + return aTarget; + } + + /** Returns the string representation of the integer argument. This function can't be used for language specific conversion. diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index 6b0e4dc73ff0..79a2c2d41808 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -931,7 +931,7 @@ OUString DrawingML::WriteBlip( Reference< XPropertySet > rXPropSet, const OUStri GET( nContrast, AdjustContrast ); mpFS->startElementNS( XML_a, XML_blip, - FSNS( XML_r, XML_embed), OUStringToOString( sRelId, RTL_TEXTENCODING_UTF8 ).getStr(), + FSNS( XML_r, XML_embed), sRelId.toUtf8().getStr(), FSEND ); if( nBright || nContrast ) { @@ -1693,7 +1693,7 @@ void DrawingML::WriteParagraphNumbering( Reference< XPropertySet > rXPropSet, sa XML_val, IS( std::max( (sal_Int32)25000, std::min( (sal_Int32)400000, 1000*( (sal_Int32)nBulletRelSize ) ) ) ), FSEND ); if( bHasFontDesc ) mpFS->singleElementNS( XML_a, XML_buFont, - XML_typeface, OUStringToOString( aFontDesc.Name, RTL_TEXTENCODING_UTF8 ).getStr(), + XML_typeface, aFontDesc.Name.toUtf8().getStr(), XML_charset, (aFontDesc.CharSet == awt::CharSet::SYMBOL) ? "2" : NULL, FSEND ); @@ -1934,7 +1934,7 @@ void DrawingML::WriteText( Reference< XInterface > rXIface, const OUString& pres FSEND ); if( presetWarp != NULL && !presetWarp.isEmpty()) { - mpFS->singleElementNS(XML_a, XML_prstTxWarp, XML_prst,OUStringToOString(presetWarp, RTL_TEXTENCODING_UTF8 ).getStr(), + mpFS->singleElementNS(XML_a, XML_prstTxWarp, XML_prst, presetWarp.toUtf8().getStr(), FSEND ); } if (GetDocumentType() == DOCUMENT_DOCX) diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 479d2caab220..7444240746aa 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -2296,7 +2296,7 @@ void DocxAttributeOutput::Redline( const SwRedlineData* pRedlineData) OString aId( OString::number( pRedlineData->GetSeqNo() ) ); const OUString &rAuthor( SW_MOD()->GetRedlineAuthor( pRedlineData->GetAuthor() ) ); - OString aAuthor( OUStringToOString( rAuthor, RTL_TEXTENCODING_UTF8 ) ); + OString aAuthor( rAuthor.toUtf8() ); OString aDate( DateTimeToOString( pRedlineData->GetTimeStamp() ) ); switch( pRedlineData->GetType() ) diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index 1150463f2feb..5b4c38193e3d 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -207,7 +207,7 @@ OString DocxExport::AddRelation( const OUString& rType, const OUString& rTarget OUString sId = m_pFilter->addRelation( m_pDocumentFS->getOutputStream(), rType, rTarget, true ); - return OUStringToOString( sId, RTL_TEXTENCODING_UTF8 ); + return sId.toUtf8(); } bool DocxExport::DisallowInheritingOutlineNumbering( const SwFmt& rFmt ) @@ -750,7 +750,7 @@ void DocxExport::WriteHeaderFooter( const SwFmt& rFmt, bool bHeader, const char* // and write the reference m_pDocumentFS->singleElementNS( XML_w, nReference, FSNS( XML_w, XML_type ), pType, - FSNS( XML_r, XML_id ), OUStringToOString( aRelId, RTL_TEXTENCODING_UTF8 ).getStr(), + FSNS( XML_r, XML_id ), aRelId.toUtf8().getStr(), FSEND ); } |