diff options
-rw-r--r-- | sal/inc/rtl/ustrbuf.hxx | 18 | ||||
-rw-r--r-- | sal/qa/rtl/strings/test_oustring_stringliterals.cxx | 12 |
2 files changed, 30 insertions, 0 deletions
diff --git a/sal/inc/rtl/ustrbuf.hxx b/sal/inc/rtl/ustrbuf.hxx index af008bf54d4a..adb17616ac7a 100644 --- a/sal/inc/rtl/ustrbuf.hxx +++ b/sal/inc/rtl/ustrbuf.hxx @@ -405,6 +405,24 @@ public: return *this; } + /** + @overload + This function accepts an ASCII string literal as its argument. + @since LibreOffice 3.6 + */ + template< int N > + OUStringBuffer& append( const char (&literal)[ N ] ) + { + rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, getLength(), literal, N - 1 ); + return *this; + } + + /** + It is an error to call this overload. Strings cannot directly use non-const char[]. + @internal + */ + template< int N > + OUStringBuffer& append( char (&literal)[ N ] ); /** Appends the string representation of the <code>sal_Bool</code> diff --git a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx index 59e130071484..9c8c934282eb 100644 --- a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx +++ b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx @@ -37,6 +37,7 @@ extern bool rtl_string_unittest_const_literal; #include <cppunit/extensions/HelperMacros.h> #include "rtl/string.h" #include "rtl/ustring.hxx" +#include "rtl/ustrbuf.hxx" #include "rtl/oustringostreaminserter.hxx" namespace test { namespace oustring { @@ -48,6 +49,7 @@ private: void checkUsage(); void checkExtraIntArgument(); void checkNonconstChar(); + void checkBuffer(); void testcall( const char str[] ); // invalid conversions will trigger templated OUString ctor that creates an empty string @@ -59,6 +61,7 @@ CPPUNIT_TEST(checkCtors); CPPUNIT_TEST(checkUsage); CPPUNIT_TEST(checkExtraIntArgument); CPPUNIT_TEST(checkNonconstChar); +CPPUNIT_TEST(checkBuffer); CPPUNIT_TEST_SUITE_END(); }; @@ -160,6 +163,15 @@ void test::oustring::StringLiterals::checkNonconstChar() CPPUNIT_ASSERT( rtl::OUString( "foobar" ) == rtl::OUString( "footest" ).replaceAll( consttest, constbar )); } +void test::oustring::StringLiterals::checkBuffer() +{ + rtl::OUStringBuffer buf; + buf.append( "foo" ); + CPPUNIT_ASSERT( buf.toString() == "foo" ); + buf.append( "bar" ); + CPPUNIT_ASSERT( buf.toString() == "foobar" ); +} + }} // namespace CPPUNIT_TEST_SUITE_REGISTRATION(test::oustring::StringLiterals); |