include/tools/datetimeutils.hxx                     |    6 +++--
 svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx |   11 +++++----
 sw/source/core/doc/docbm.cxx                        |    2 -
 sw/source/core/doc/doclay.cxx                       |    2 -
 sw/source/core/doc/docnum.cxx                       |    2 -
 sw/source/core/doc/doctxm.cxx                       |    2 -
 sw/source/core/docnode/ndsect.cxx                   |    2 -
 sw/source/core/docnode/ndtbl.cxx                    |    2 -
 sw/source/filter/ww8/docxattributeoutput.cxx        |    2 -
 sw/source/writerfilter/rtftok/rtfdispatchvalue.cxx  |    4 ---
 sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx   |    7 ++----
 sw/source/writerfilter/rtftok/rtfdocumentimpl.hxx   |    2 -
 tools/source/datetime/datetimeutils.cxx             |   23 +++++++++++++++-----
 13 files changed, 40 insertions(+), 27 deletions(-)

New commits:
commit 98746cca55dd088c34339682e98504dadb11d2c7
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri May 10 11:42:45 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Mon May 13 14:44:27 2024 +0200

    createFromAscii -> OUString literals in StylesPreviewToolBoxControl
    
    Change-Id: Ica3c79facee725effcfb160738305c599c5de1ba
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167575
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Tested-by: Jenkins

diff --git a/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx 
b/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx
index 2870e5dc36b7..5496f4d4ae9a 100644
--- a/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx
+++ b/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx
@@ -62,7 +62,7 @@ void StylesPreviewToolBoxControl::InitializeStyles(
         {
             css::uno::Reference<css::container::XNameAccess> xParaStyles;
             
xStylesSupplier->getStyleFamilies()->getByName(u"ParagraphStyles"_ustr) >>= 
xParaStyles;
-            static const std::vector<OUString> aWriterStyles = {
+            static constexpr OUString aWriterStyles[]{
                 u"Standard"_ustr,   u"Text body"_ustr,        u"Heading 
1"_ustr, u"Heading 2"_ustr,
                 u"Heading 3"_ustr,  u"Heading 4"_ustr,        u"Title"_ustr,   
  u"Subtitle"_ustr,
                 u"Quotations"_ustr, u"Preformatted Text"_ustr
@@ -88,15 +88,16 @@ void StylesPreviewToolBoxControl::InitializeStyles(
         }
         else if 
(xServices->supportsService(u"com.sun.star.sheet.SpreadsheetDocument"_ustr))
         {
-            static const char* aCalcStyles[] = { "Default",   "Accent 1",  
"Accent 2", "Accent 3",
-                                                 "Heading 1", "Heading 2", 
"Result" };
+            static constexpr OUString aCalcStyles[]{ u"Default"_ustr,   
u"Accent 1"_ustr,
+                                                     u"Accent 2"_ustr,  
u"Accent 3"_ustr,
+                                                     u"Heading 1"_ustr, 
u"Heading 2"_ustr,
+                                                     u"Result"_ustr };
             css::uno::Reference<css::container::XNameAccess> xCellStyles;
             xStylesSupplier->getStyleFamilies()->getByName(u"CellStyles"_ustr) 
>>= xCellStyles;
-            for (const char* pCalcStyle : aCalcStyles)
+            for (const OUString& sStyleName : aCalcStyles)
             {
                 try
                 {
-                    const OUString 
sStyleName(OUString::createFromAscii(pCalcStyle));
                     if (xCellStyles->hasByName(sStyleName))
                     {
                         css::uno::Reference<css::beans::XPropertySet> xStyle(
commit 57dc0cbd8ebfe465f9e21a47c253a8437f8860a9
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri May 10 11:39:18 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Mon May 13 14:44:19 2024 +0200

    do less OString->OUString conversion in tools datetime functions
    
    Change-Id: I93d012f32b8006019c431b8bf88ab9c7ffb4d3a0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167574
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Tested-by: Jenkins

diff --git a/include/tools/datetimeutils.hxx b/include/tools/datetimeutils.hxx
index 3df6229cb574..deb7d7ee4f4c 100644
--- a/include/tools/datetimeutils.hxx
+++ b/include/tools/datetimeutils.hxx
@@ -14,12 +14,14 @@
 
 // This function converts a 'DateTime' object to an 'OString' object
 TOOLS_DLLPUBLIC OString DateTimeToOString(const DateTime& rDateTime);
+// This function converts a 'DateTime' object to an 'OUString' object
+TOOLS_DLLPUBLIC OUString DateTimeToOUString(const DateTime& rDateTime);
 
 // This function converts a 'Date' object to an 'OString' object in ISO-8601 
representation
 TOOLS_DLLPUBLIC OString DateToOString(const Date& rDate);
 
-// This function converts a 'Date' object to an 'OString' object in DD/MM/YYYY 
format
-TOOLS_DLLPUBLIC OString DateToDDMMYYYYOString(const Date& rDate);
+// This function converts a 'Date' object to an 'OUString' object in 
DD/MM/YYYY format
+TOOLS_DLLPUBLIC OUString DateToDDMMYYYYOUString(const Date& rDate);
 
 #endif
 
diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index fb741e749fb5..6f8a091f6741 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -1807,7 +1807,7 @@ namespace sw::mark
         if( m_rDoc.IsInMailMerge())
         {
             OUString newName = rName + "MailMergeMark"
-                    + OStringToOUString( DateTimeToOString( DateTime( 
DateTime::SYSTEM )), RTL_TEXTENCODING_ASCII_US )
+                    + DateTimeToOUString( DateTime( DateTime::SYSTEM ) )
                     + OUString::number( m_vAllMarks.size() + 1 );
             return newName;
         }
diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx
index 0371bd66ce7f..611c1a862a15 100644
--- a/sw/source/core/doc/doclay.cxx
+++ b/sw/source/core/doc/doclay.cxx
@@ -1326,7 +1326,7 @@ static OUString lcl_GetUniqueFlyName(const SwDoc& rDoc, 
TranslateId pDefStrId, s
     if (rDoc.IsInMailMerge())
     {
         OUString newName = "MailMergeFly"
-            + OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM 
)), RTL_TEXTENCODING_ASCII_US )
+            + DateTimeToOUString( DateTime( DateTime::SYSTEM ) )
             + OUString::number( rDoc.GetSpzFrameFormats()->size() + 1 );
         return newName;
     }
diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx
index 73b04ad24122..5378a960320d 100644
--- a/sw/source/core/doc/docnum.cxx
+++ b/sw/source/core/doc/docnum.cxx
@@ -2543,7 +2543,7 @@ OUString SwDoc::GetUniqueNumRuleName( const OUString* 
pChkStr, bool bAutoNum ) c
     if( IsInMailMerge() && !pChkStr )
     {
         OUString newName = "MailMergeNumRule"
-            + OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM 
)), RTL_TEXTENCODING_ASCII_US )
+            + DateTimeToOUString( DateTime( DateTime::SYSTEM ) )
             + OUString::number( mpNumRuleTable->size() + 1 );
         return newName;
     }
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index 9e2c409d9511..6b22fcad413a 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -643,7 +643,7 @@ OUString SwDoc::GetUniqueTOXBaseName( const SwTOXType& 
rType,
     if( IsInMailMerge())
     {
         OUString newName = "MailMergeTOX"
-            + OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM 
)), RTL_TEXTENCODING_ASCII_US )
+            + DateTimeToOUString( DateTime( DateTime::SYSTEM ) )
             + OUString::number( mpSectionFormatTable->size() + 1 );
         if( !sChkStr.isEmpty())
             newName += sChkStr;
diff --git a/sw/source/core/docnode/ndsect.cxx 
b/sw/source/core/docnode/ndsect.cxx
index 57413039bcff..7480279c9194 100644
--- a/sw/source/core/docnode/ndsect.cxx
+++ b/sw/source/core/docnode/ndsect.cxx
@@ -1388,7 +1388,7 @@ OUString SwDoc::GetUniqueSectionName( const OUString* 
pChkStr ) const
     if( IsInMailMerge())
     {
         OUString newName = "MailMergeSection"
-            + OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM 
)), RTL_TEXTENCODING_ASCII_US )
+            + DateTimeToOUString( DateTime( DateTime::SYSTEM ) )
             + OUString::number( mpSectionFormatTable->size() + 1 );
         if( pChkStr )
             newName += *pChkStr;
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 7bc214fca871..1f932f6b2f2c 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -3946,7 +3946,7 @@ OUString SwDoc::GetUniqueTableName() const
     if( IsInMailMerge())
     {
         OUString newName = "MailMergeTable"
-            + OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM 
)), RTL_TEXTENCODING_ASCII_US )
+            + DateTimeToOUString( DateTime( DateTime::SYSTEM ) )
             + OUString::number( mpTableFrameFormatTable->size() + 1 );
         return newName;
     }
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 31711eb4e887..d6a2674a9f8d 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -5611,7 +5611,7 @@ void DocxAttributeOutput::WritePostponedFormControl(const 
SdrObject* pObject)
             bHasDate = true;
             Date aDate(aUNODate.Day, aUNODate.Month, aUNODate.Year);
             sDate = DateToOString(aDate);
-            aContentText = 
OUString::createFromAscii(DateToDDMMYYYYOString(aDate));
+            aContentText = DateToDDMMYYYYOUString(aDate);
             sDateFormat = "dd/MM/yyyy";
         }
         else
diff --git a/sw/source/writerfilter/rtftok/rtfdispatchvalue.cxx 
b/sw/source/writerfilter/rtftok/rtfdispatchvalue.cxx
index 1e7552dd71b1..801aeb2e321b 100644
--- a/sw/source/writerfilter/rtftok/rtfdispatchvalue.cxx
+++ b/sw/source/writerfilter/rtftok/rtfdispatchvalue.cxx
@@ -1446,9 +1446,7 @@ RTFError RTFDocumentImpl::dispatchValue(RTFKeyword 
nKeyword, int nParam)
         case RTFKeyword::REVDTTM:
         case RTFKeyword::REVDTTMDEL:
         {
-            OUString aStr(
-                OStringToOUString(DTTM22OString(nParam), 
m_aStates.top().getCurrentEncoding()));
-            auto pValue = new RTFValue(aStr);
+            auto pValue = new RTFValue(DTTM22OUString(nParam));
             putNestedAttribute(m_aStates.top().getCharacterSprms(), 
NS_ooxml::LN_trackchange,
                                NS_ooxml::LN_CT_TrackChange_date, pValue);
         }
diff --git a/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx 
b/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx
index d22c648edb2f..a57af7c330e2 100644
--- a/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx
+++ b/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx
@@ -210,9 +210,9 @@ void putBorderProperty(RTFStack& aStates, Id nId, const 
RTFValue::Pointer_t& pVa
         pAttributes->set(nId, pValue);
 }
 
-OString DTTM22OString(tools::Long nDTTM)
+OUString DTTM22OUString(tools::Long nDTTM)
 {
-    return DateTimeToOString(msfilter::util::DTTM2DateTime(nDTTM));
+    return DateTimeToOUString(msfilter::util::DTTM2DateTime(nDTTM));
 }
 
 static RTFSprms lcl_getBookmarkProperties(int nPos, const OUString& rString)
@@ -2835,8 +2835,7 @@ RTFError RTFDocumentImpl::beforePopState(RTFParserState& 
rState)
             OUStringBuffer* pCurrentDestinationText = 
m_aStates.top().getCurrentDestinationText();
             if (&m_aStates.top().getDestinationText() != 
pCurrentDestinationText)
                 break; // not for nested group
-            OUString 
aStr(OStringToOUString(DTTM22OString(o3tl::toInt32(*pCurrentDestinationText)),
-                                            rState.getCurrentEncoding()));
+            OUString 
aStr(DTTM22OUString(o3tl::toInt32(*pCurrentDestinationText)));
             pCurrentDestinationText->setLength(0);
             auto pValue = new RTFValue(aStr);
             RTFSprms aAnnAttributes;
diff --git a/sw/source/writerfilter/rtftok/rtfdocumentimpl.hxx 
b/sw/source/writerfilter/rtftok/rtfdocumentimpl.hxx
index e1ab4be1dd7a..775923088497 100644
--- a/sw/source/writerfilter/rtftok/rtfdocumentimpl.hxx
+++ b/sw/source/writerfilter/rtftok/rtfdocumentimpl.hxx
@@ -679,7 +679,7 @@ RTFValue::Pointer_t getNestedSprm(RTFSprms& rSprms, Id 
nParent, Id nId);
 bool findPropertyName(const std::vector<css::beans::PropertyValue>& 
rProperties,
                       const OUString& rName);
 RTFSprms& getLastAttributes(RTFSprms& rSprms, Id nId);
-OString DTTM22OString(tools::Long nDTTM);
+OUString DTTM22OUString(tools::Long nDTTM);
 
 /// Implementation of the RTFDocument interface.
 class RTFDocumentImpl : public RTFDocument, public RTFListener
diff --git a/tools/source/datetime/datetimeutils.cxx 
b/tools/source/datetime/datetimeutils.cxx
index 4c3b28d49dc6..345e18f4a721 100644
--- a/tools/source/datetime/datetimeutils.cxx
+++ b/tools/source/datetime/datetimeutils.cxx
@@ -9,10 +9,12 @@
 
 #include <tools/datetimeutils.hxx>
 #include <rtl/strbuf.hxx>
+#include <rtl/ustrbuf.hxx>
 
 
 /// Append the number as 2-digit when less than 10.
-static void lcl_AppendTwoDigits( OStringBuffer &rBuffer, sal_Int32 nNum )
+template<class TStringBuffer>
+static void lcl_AppendTwoDigits( TStringBuffer &rBuffer, sal_Int32 nNum )
 {
     if ( nNum < 0 || nNum > 99 )
     {
@@ -26,14 +28,15 @@ static void lcl_AppendTwoDigits( OStringBuffer &rBuffer, 
sal_Int32 nNum )
     rBuffer.append( nNum );
 }
 
-OString DateTimeToOString( const DateTime& rDateTime )
+template<class TString, class TStringBuffer>
+static TString DateTimeToStringImpl( const DateTime& rDateTime )
 {
     const DateTime& aInUTC( rDateTime );
 // HACK: this is correct according to the spec, but MSOffice believes 
everybody lives
 // in UTC+0 when reading it back
 //    aInUTC.ConvertToUTC();
 
-    OStringBuffer aBuffer( 25 );
+    TStringBuffer aBuffer( 25 );
     aBuffer.append( sal_Int32( aInUTC.GetYear() ) );
     aBuffer.append( '-' );
 
@@ -55,15 +58,25 @@ OString DateTimeToOString( const DateTime& rDateTime )
     return aBuffer.makeStringAndClear();
 }
 
+OString DateTimeToOString( const DateTime& rDateTime )
+{
+    return DateTimeToStringImpl<OString,OStringBuffer>(rDateTime);
+}
+
+OUString DateTimeToOUString( const DateTime& rDateTime )
+{
+    return DateTimeToStringImpl<OUString,OUStringBuffer>(rDateTime);
+}
+
 OString DateToOString( const Date& rDate )
 {
     tools::Time aTime( tools::Time::EMPTY );
     return DateTimeToOString( DateTime( rDate, aTime ) );
 }
 
-OString DateToDDMMYYYYOString( const Date& rDate )
+OUString DateToDDMMYYYYOUString( const Date& rDate )
 {
-    OStringBuffer aBuffer( 25 );
+    OUStringBuffer aBuffer( 25 );
     lcl_AppendTwoDigits( aBuffer, rDate.GetDay() );
     aBuffer.append( '/' );
 

Reply via email to