[Libreoffice-commits] core.git: include/rtl oox/source sw/source

Miklos Vajna vmiklos at collabora.co.uk
Mon Nov 17 00:22:48 PST 2014


 include/rtl/ustring.hxx                      |   23 +++++++++++++++++++++++
 oox/source/export/drawingml.cxx              |    6 +++---
 sw/source/filter/ww8/docxattributeoutput.cxx |    2 +-
 sw/source/filter/ww8/docxexport.cxx          |    4 ++--
 4 files changed, 29 insertions(+), 6 deletions(-)

New commits:
commit acd78552de4179d869cf7061dffab22063466f1c
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Nov 17 08:59:01 2014 +0100

    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

diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index b9a868b..66b320f 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 6b0e4dc..79a2c2d 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 479d2ca..7444240 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 1150463..5b4c381 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 );
 }
 


More information about the Libreoffice-commits mailing list