summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-08-06 10:55:58 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-08-13 08:16:03 +0200
commit3457da6abe0fd03efd19442e9790fbd1aa04c160 (patch)
treea7a2d5b51839b200e7cda79af863dce7a04d3a10 /include
parent47196637a41ddfc9a8707771b1b9f482fd72c3b6 (diff)
loplugin:stringstatic also look for local statics
Add some API to O*StringLiteral, to make it easier to use in some places that were using O*String Change-Id: I1fb93bd47ac2065c9220d509aad3f4320326d99e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100270 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include')
-rw-r--r--include/rtl/string.hxx75
-rw-r--r--include/xmloff/xmlimp.hxx4
2 files changed, 58 insertions, 21 deletions
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 809b0a11bcd5..35eccfc073c3 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -68,6 +68,39 @@ namespace rtl
#endif
/// @endcond
+#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
+/**
+A simple wrapper around string literal. It is usually not necessary to use, can
+be mostly used to force OString operator+ working with operands that otherwise would
+not trigger it.
+
+This class is not part of public API and is meant to be used only in LibreOffice code.
+@since LibreOffice 4.0
+*/
+struct SAL_WARN_UNUSED OStringLiteral
+{
+ template< int N >
+ explicit OStringLiteral( const char (&str)[ N ] ) : size( N - 1 ), data( str ) { assert( strlen( str ) == N - 1 ); }
+#if defined __cpp_char8_t
+ template< int N >
+ explicit OStringLiteral( const char8_t (&str)[ N ] ) : size( N - 1 ), data( reinterpret_cast<char const *>(str) ) { assert( strlen( data ) == N - 1 ); }
+#endif
+
+ int size;
+ const char* data;
+
+ /** So we can use this in some places interchangeably with OUString.
+ * @since LibreOffice 7.1
+ */
+ constexpr sal_Int32 getLength() const { return size; }
+
+ /** So we can use this in some places interchangeably with OString.
+ * @since LibreOffice 7.1
+ */
+ constexpr const char* getStr() const { return data; }
+};
+#endif
+
/* ======================================================================= */
/**
@@ -236,6 +269,29 @@ public:
rtl_string_newFromStr_WithLength( &pData, value, length );
}
+#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
+ /// @cond INTERNAL
+ /**
+ New string from an 8-Bit string literal.
+
+ This constructor is similar to the "direct template" one, but can be
+ useful in cases where the latter does not work, like in
+
+ OString(flag ? "a" : "bb")
+
+ written as
+
+ OString(flag ? OStringLiteral("a") : OStringLiteral("bb"))
+
+ @since LibreOffice 7.1
+ */
+ OString(OStringLiteral literal): pData(NULL) {
+ rtl_string_newFromLiteral(&pData, literal.data, literal.size, 0);
+ }
+ /// @endcond
+#endif
+
+
/**
New string from a Unicode character buffer array.
@@ -1849,25 +1905,6 @@ public:
/* ======================================================================= */
#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
-/**
-A simple wrapper around string literal. It is usually not necessary to use, can
-be mostly used to force OString operator+ working with operands that otherwise would
-not trigger it.
-
-This class is not part of public API and is meant to be used only in LibreOffice code.
-@since LibreOffice 4.0
-*/
-struct SAL_WARN_UNUSED OStringLiteral
-{
- template< int N >
- explicit OStringLiteral( const char (&str)[ N ] ) : size( N - 1 ), data( str ) { assert( strlen( str ) == N - 1 ); }
-#if defined __cpp_char8_t
- template< int N >
- explicit OStringLiteral( const char8_t (&str)[ N ] ) : size( N - 1 ), data( reinterpret_cast<char const *>(str) ) { assert( strlen( data ) == N - 1 ); }
-#endif
- int size;
- const char* data;
-};
/**
@internal
diff --git a/include/xmloff/xmlimp.hxx b/include/xmloff/xmlimp.hxx
index 3742c7b79acf..3b4cc7969be9 100644
--- a/include/xmloff/xmlimp.hxx
+++ b/include/xmloff/xmlimp.hxx
@@ -534,8 +534,8 @@ public:
**/
bool getBuildIds( sal_Int32& rUPD, sal_Int32& rBuild ) const;
- static const OUString aDefaultNamespace;
- static const OUString aNamespaceSeparator;
+ static const OUStringLiteral aDefaultNamespace;
+ static const OUStringLiteral aNamespaceSeparator;
static const sal_uInt16 OOo_1x = 10;
static const sal_uInt16 OOo_2x = 20;