framework/inc/xml/toolboxconfigurationdefines.hxx   |   18 +++++-----
 framework/source/fwe/xml/toolboxdocumenthandler.cxx |    6 +--
 include/rtl/ustring.hxx                             |   35 ++++++++++++++++++++
 3 files changed, 47 insertions(+), 12 deletions(-)

New commits:
commit a4d4286a6ae5ad7f57db4f34380ed170b92ced06
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Nov 12 12:20:18 2021 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Nov 12 18:37:38 2021 +0100

    introduce OUStringConstExpr
    
    so we can declare compile-time constant arrays and structs
    containing OUStringLiteral
    
    Change-Id: I51fd743f2e461a36bb4a0a17c6ff107f86096895
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125045
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/framework/inc/xml/toolboxconfigurationdefines.hxx 
b/framework/inc/xml/toolboxconfigurationdefines.hxx
index c84adff58e8b..b4aca76a6bef 100644
--- a/framework/inc/xml/toolboxconfigurationdefines.hxx
+++ b/framework/inc/xml/toolboxconfigurationdefines.hxx
@@ -52,14 +52,14 @@
 #define ATTRIBUTE_BOOLEAN_TRUE      "true"
 #define ATTRIBUTE_BOOLEAN_FALSE     "false"
 
-#define ATTRIBUTE_ITEMSTYLE_RADIO           "radio"
-#define ATTRIBUTE_ITEMSTYLE_AUTO            "auto"
-#define ATTRIBUTE_ITEMSTYLE_LEFT            "left"
-#define ATTRIBUTE_ITEMSTYLE_AUTOSIZE        "autosize"
-#define ATTRIBUTE_ITEMSTYLE_DROPDOWN        "dropdown"
-#define ATTRIBUTE_ITEMSTYLE_REPEAT          "repeat"
-#define ATTRIBUTE_ITEMSTYLE_TEXT    "text"
-#define ATTRIBUTE_ITEMSTYLE_DROPDOWNONLY    "dropdownonly"
-#define ATTRIBUTE_ITEMSTYLE_IMAGE    "image"
+constexpr OUStringLiteral ATTRIBUTE_ITEMSTYLE_RADIO = u"radio";
+constexpr OUStringLiteral ATTRIBUTE_ITEMSTYLE_AUTO = u"auto";
+constexpr OUStringLiteral ATTRIBUTE_ITEMSTYLE_LEFT = u"left";
+constexpr OUStringLiteral ATTRIBUTE_ITEMSTYLE_AUTOSIZE = u"autosize";
+constexpr OUStringLiteral ATTRIBUTE_ITEMSTYLE_DROPDOWN = u"dropdown";
+constexpr OUStringLiteral ATTRIBUTE_ITEMSTYLE_REPEAT = u"repeat";
+constexpr OUStringLiteral ATTRIBUTE_ITEMSTYLE_TEXT = u"text";
+constexpr OUStringLiteral ATTRIBUTE_ITEMSTYLE_DROPDOWNONLY = u"dropdownonly";
+constexpr OUStringLiteral ATTRIBUTE_ITEMSTYLE_IMAGE = u"image";
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/framework/source/fwe/xml/toolboxdocumenthandler.cxx 
b/framework/source/fwe/xml/toolboxdocumenthandler.cxx
index 4fd152a6f03e..11385edd9b5c 100644
--- a/framework/source/fwe/xml/toolboxdocumenthandler.cxx
+++ b/framework/source/fwe/xml/toolboxdocumenthandler.cxx
@@ -85,12 +85,12 @@ namespace {
 struct ToolboxStyleItem
 {
     sal_Int16 nBit;
-    const char* attrName;
+    rtl::OUStringConstExpr attrName;
 };
 
 }
 
-const ToolboxStyleItem Styles[ ] = {
+constexpr ToolboxStyleItem Styles[ ] = {
     { css::ui::ItemStyle::RADIO_CHECK,   ATTRIBUTE_ITEMSTYLE_RADIO },
     { css::ui::ItemStyle::ALIGN_LEFT,    ATTRIBUTE_ITEMSTYLE_LEFT },
     { css::ui::ItemStyle::AUTO_SIZE,     ATTRIBUTE_ITEMSTYLE_AUTO },
@@ -703,7 +703,7 @@ void OWriteToolBoxDocumentHandler::WriteToolBoxItem(
             {
                 if ( !aValue.isEmpty() )
                     aValue.append(" ");
-                aValue.appendAscii( pStyle->attrName );
+                aValue.append( OUString(pStyle->attrName) );
             }
         }
         pList->AddAttribute( m_aXMLToolbarNS + ATTRIBUTE_ITEMSTYLE,
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 1a5ff2d97d6c..6cf92e1d3599 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -84,6 +84,7 @@ template<std::size_t N> class SAL_WARN_UNUSED OUStringLiteral 
{
     static_assert(N != 0);
     static_assert(N - 1 <= std::numeric_limits<sal_Int32>::max(), "literal too 
long");
     friend class OUString;
+    friend class OUStringConstExpr;
 
 public:
 #if HAVE_CPP_CONSTEVAL
@@ -138,6 +139,34 @@ template<std::size_t N> struct 
ExceptCharArrayDetector<OUStringLiteral<N>> {};
 }
 #endif
 
+/**
+  This is intended to be used when declaring compile-time-constant structs or 
arrays
+  that can be initialised from named OUStringLiteral e.g.
+
+    constexpr OUStringLiteral AAA = u"aaa";
+    constexpr OUStringLiteral BBB = u"bbb";
+    constexpr OUStringConstExpr FOO[] { AAA, BBB };
+*/
+class OUString;
+class OUStringConstExpr
+{
+public:
+    template<std::size_t N> constexpr OUStringConstExpr(OUStringLiteral<N> 
const & literal):
+        pData(const_cast<rtl_uString *>(&literal.str)) {}
+    
+    // prevent mis-use
+    template<std::size_t N> constexpr OUStringConstExpr(OUStringLiteral<N> && 
literal)
+        = delete;
+
+    // no destructor necessary because we know we are pointing at a 
compile-time
+    // constant OUStringLiteral, which bypasses ref-counting.
+
+    inline operator OUString() const;
+
+private:
+    rtl_uString* pData;
+};
+
 /// @endcond
 #endif
 
@@ -3268,6 +3297,11 @@ private:
 
 };
 
+#if defined LIBO_INTERNAL_ONLY
+// Can only define this after we define OUString
+inline OUStringConstExpr::operator OUString() const { return 
OUString::unacquired(&pData); }
+#endif
+
 #if defined LIBO_INTERNAL_ONLY
 // Prevent the operator ==/!= overloads with 'sal_Unicode const *' parameter 
from
 // being selected for nonsensical code like
@@ -3328,6 +3362,7 @@ inline std::basic_ostream<charT, traits> & operator <<(
     return stream << OUString( std::move(concat) );
 }
 
+    
 /// @endcond
 #endif
 

Reply via email to