summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-10-24 15:43:06 +0200
committerStephan Bergmann <sbergman@redhat.com>2019-10-24 17:17:46 +0200
commit6d6fad522a2cd6a2959ea774969a86288f5a3cb7 (patch)
tree392503346dc17a8573f4a33c51155ffdb6f95cfa /include
parentaaff73401318a7fd1b3e936555f933538b2407bc (diff)
Introduce OStringChar
...similar to OUStringChar, to be used in string concatenation expressions. And enable the corresponding loplugin:stringadd check, and fix its findings. Change-Id: I35ebb2253ba82bda6c98ae6ebd2ad4f27cf9abf9 Reviewed-on: https://gerrit.libreoffice.org/81456 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/rtl/string.hxx1
-rw-r--r--include/rtl/stringconcat.hxx10
-rw-r--r--include/rtl/stringutils.hxx12
3 files changed, 23 insertions, 0 deletions
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 1826f42f46ac..a372a3428ca1 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -1971,6 +1971,7 @@ typedef rtlunittest::OString OString;
#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
using ::rtl::OString;
+using ::rtl::OStringChar;
using ::rtl::OStringHash;
using ::rtl::OStringLiteral;
#endif
diff --git a/include/rtl/stringconcat.hxx b/include/rtl/stringconcat.hxx
index 588be8f0073e..f5c9a4d33a52 100644
--- a/include/rtl/stringconcat.hxx
+++ b/include/rtl/stringconcat.hxx
@@ -147,6 +147,16 @@ struct ToStringHelper< const char[ N ] >
};
template<>
+struct ToStringHelper<OStringChar>
+ {
+ static std::size_t length(OStringChar) { return 1; }
+ static char* addData(char* buffer, OStringChar data)
+ { return addDataHelper(buffer, &data.c, 1); }
+ static bool const allowOStringConcat = true;
+ static bool const allowOUStringConcat = false;
+ };
+
+template<>
struct ToStringHelper< const sal_Unicode* >
{
static std::size_t length( const sal_Unicode* str ) {
diff --git a/include/rtl/stringutils.hxx b/include/rtl/stringutils.hxx
index 3ed4bfc8e950..b968845465ce 100644
--- a/include/rtl/stringutils.hxx
+++ b/include/rtl/stringutils.hxx
@@ -36,6 +36,18 @@ namespace rtl
#if defined LIBO_INTERNAL_ONLY
/// @cond INTERNAL
+// A simple wrapper around a single char. Can be useful in string concatenation contexts, like in
+//
+// OString s = ...;
+// char c = ...;
+// s += OStringChar(c);
+//
+struct SAL_WARN_UNUSED OStringChar {
+ constexpr OStringChar(char theC): c(theC) {}
+ template<typename T> OStringChar(T &&) = delete;
+ char const c;
+};
+
/** A simple wrapper around a single sal_Unicode character.
Can be useful to pass a sal_Unicode constant into an OUString-related