summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/rtl/ustring.hxx57
-rw-r--r--sal/qa/rtl/strings/test_oustring_stringliterals.cxx18
-rw-r--r--writerfilter/source/rtftok/rtfdocumentimpl.cxx4
3 files changed, 61 insertions, 18 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<>
diff --git a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx
index 0693fc2a3e08..0848db19011a 100644
--- a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx
+++ b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx
@@ -31,6 +31,7 @@ private:
void checkExtraIntArgument();
void checkNonconstChar();
void checkBuffer();
+ void checkOUStringLiteral();
void checkOUStringLiteral1();
void testcall( const char str[] );
@@ -41,6 +42,7 @@ CPPUNIT_TEST(checkUsage);
CPPUNIT_TEST(checkExtraIntArgument);
CPPUNIT_TEST(checkNonconstChar);
CPPUNIT_TEST(checkBuffer);
+CPPUNIT_TEST(checkOUStringLiteral);
CPPUNIT_TEST(checkOUStringLiteral1);
CPPUNIT_TEST_SUITE_END();
};
@@ -172,6 +174,22 @@ void test::oustring::StringLiterals::checkBuffer()
CPPUNIT_ASSERT( !VALID_CONVERSION( buf.append( rtl::OUStringBuffer( d ))));
}
+namespace {
+
+rtl::OUString conditional(bool flag) {
+ return flag
+ ? rtlunittest::OUStringLiteral("a")
+ : rtlunittest::OUStringLiteral("bb");
+}
+
+}
+
+void test::oustring::StringLiterals::checkOUStringLiteral()
+{
+ CPPUNIT_ASSERT(conditional(true) == "a");
+ CPPUNIT_ASSERT(conditional(false) == "bb");
+}
+
void test::oustring::StringLiterals::checkOUStringLiteral1()
{
rtl::OUString s1;
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 151daa8f9a17..babc26612cb1 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -5202,8 +5202,8 @@ int RTFDocumentImpl::popState()
break; // not for nested group
OUString str(m_aStates.top().pDestinationText->makeStringAndClear());
// dmapper expects this as a field, so let's fake something...
- OUString const field = OUString::createFromAscii(
- (DESTINATION_INDEXENTRY == aState.nDestinationState) ? "XE" : "TC");
+ OUString const field(
+ (DESTINATION_INDEXENTRY == aState.nDestinationState) ? OUStringLiteral("XE") : OUStringLiteral("TC"));
str = field + " \"" + str.replaceAll("\"", "\\\"") + "\"";
singleChar(0x13);
Mapper().utext(reinterpret_cast<sal_uInt8 const*>(str.getStr()), str.getLength());