Kaydet (Commit) 92fec304 authored tarafından Luboš Luňák's avatar Luboš Luňák

string literal overloads for OUStringBuffer

üst 0a08973d
......@@ -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>
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment