summaryrefslogtreecommitdiff
path: root/include/rtl
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2014-12-17 16:37:41 +0100
committerStephan Bergmann <sbergman@redhat.com>2014-12-17 16:39:33 +0100
commitd0ec8c49017b07862f8228c039bebe348eb28b0c (patch)
tree2784cb46d03901cd6c411d2f70f6f243cad6d8a6 /include/rtl
parent0f5e9170248df98ef7c7c6d475ff7d2bb9fa2214 (diff)
rtl::OUStringLiteral to the rescue
...for cases where ? "a" : "bb" does not work, as well as to work around the MSVC bug for cases like ? "a" : "b". Change-Id: Id404716047aca5cc81440f291616d92365379b8f
Diffstat (limited to 'include/rtl')
-rw-r--r--include/rtl/ustring.hxx57
1 files changed, 41 insertions, 16 deletions
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index f14eba808a0a..0d4a7159868e 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -55,6 +55,23 @@ namespace rtl
#if defined RTL_FAST_STRING
/// @cond INTERNAL
+
+/**
+A simple wrapper around string literal. It is usually not necessary to use, can
+be mostly used to force OUString 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 OUStringLiteral
+{
+ template< int N >
+ OUStringLiteral( const char (&str)[ N ] ) : size( N - 1 ), data( str ) { assert( strlen( str ) == N - 1 ); }
+ int size;
+ const char* data;
+};
+
/** A simple wrapper around an ASCII character literal, for use in certain
OUString functions designed for efficient processing of string literals.
@@ -65,6 +82,7 @@ template<char C> struct SAL_WARN_UNUSED OUStringLiteral1 {
static_cast<unsigned char>(C) < 0x80,
"non-ASCII character in OUStringLiteral1");
};
+
/// @endcond
#endif
@@ -232,6 +250,29 @@ public:
}
#endif
+#ifdef RTL_FAST_STRING
+ /// @cond INTERNAL
+ /**
+ New string from an 8-Bit string literal that is expected to contain only
+ characters in the ASCII set (i.e. first 128 characters).
+
+ This constructor is similar to the "direct template" one, but can be
+ useful in cases where the latter does not work, like in
+
+ OUString(flag ? "a" : "bb")
+
+ written as
+
+ OUString(flag ? OUStringLiteral("a") : OUStringLiteral("bb"))
+
+ @since LibreOffice 4.5
+ */
+ OUString(OUStringLiteral literal): pData(0) {
+ rtl_uString_newFromLiteral(&pData, literal.data, literal.size, 0);
+ }
+ /// @endcond
+#endif
+
/**
New string from an 8-Bit character buffer array.
@@ -2402,22 +2443,6 @@ template<char C> bool operator !=(
#ifdef RTL_FAST_STRING
/**
-A simple wrapper around string literal. It is usually not necessary to use, can
-be mostly used to force OUString 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 OUStringLiteral
-{
- template< int N >
- OUStringLiteral( const char (&str)[ N ] ) : size( N - 1 ), data( str ) { assert( strlen( str ) == N - 1 ); }
- int size;
- const char* data;
-};
-
-/**
@internal
*/
template<>