[Libreoffice-commits] core.git: include/rtl sal/qa

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Fri Oct 11 13:17:22 UTC 2019


 include/rtl/stringconcat.hxx                |   53 +++++++++++++++++++---------
 sal/qa/rtl/strings/test_oustring_concat.cxx |    3 +
 2 files changed, 40 insertions(+), 16 deletions(-)

New commits:
commit f1769094af821860dd9e1aa00904ba7123d27d1a
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Fri Oct 11 09:23:41 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Oct 11 15:16:22 2019 +0200

    round out StringConcat helpers with sal_Unicode* overloads
    
    so we can construct efficient expressions when we have pointers to
    unicode data
    
    Also lightly reformat a couple of the older helpers to make it easier to
    compare the different helpers.
    
    Change-Id: Ib8a4227714e9218512b6871d3285e4e2703bec3b
    Reviewed-on: https://gerrit.libreoffice.org/80639
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/rtl/stringconcat.hxx b/include/rtl/stringconcat.hxx
index 10d8489244de..81c48dad7335 100644
--- a/include/rtl/stringconcat.hxx
+++ b/include/rtl/stringconcat.hxx
@@ -119,15 +119,7 @@ struct ToStringHelper< const char* >
     };
 
 template<>
-struct ToStringHelper< char* >
-    {
-    static int length( const char* str ) {
-        return sal::static_int_cast<int>(strlen( str ));
-    }
-    static char* addData( char* buffer, const char* str ) { return addDataCString( buffer, str ); }
-    static const bool allowOStringConcat = true;
-    static const bool allowOUStringConcat = false;
-    };
+    struct ToStringHelper< char* > : public ToStringHelper< const char* > {};
 
 template< int N >
 struct ToStringHelper< char[ N ] >
@@ -151,22 +143,51 @@ struct ToStringHelper< const char[ N ] >
     static const bool allowOUStringConcat = true;
     };
 
-template<std::size_t N> struct ToStringHelper<sal_Unicode const[N]> {
-    static int length(sal_Unicode const[N]) { return N - 1; }
+template<>
+struct ToStringHelper< const sal_Unicode* >
+    {
+    static int length( const sal_Unicode* str ) {
+        return sal::static_int_cast<int>(std::char_traits<char16_t>::length( str ));
+    }
+    static sal_Unicode* addData( sal_Unicode* buffer, const sal_Unicode* str ) { return addDataUString( buffer, str ); }
+    static const bool allowOStringConcat = false;
+    static const bool allowOUStringConcat = true;
+    };
+
+template<>
+    struct ToStringHelper< sal_Unicode* > : public ToStringHelper< const sal_Unicode* > {};
+
+template<int N>
+struct ToStringHelper<sal_Unicode[ N ]>
+    {
+    static int length( const sal_Unicode str[ N ] ) {
+        return sal::static_int_cast<int>(std::char_traits<char16_t>::length( str ));
+    }
+    static sal_Unicode * addData(sal_Unicode * buffer, sal_Unicode const str[N])
+    { return addDataHelper(buffer, str, N - 1); }
+    static bool const allowOStringConcat = false;
+    static bool const allowOUStringConcat = true;
+    };
+
+template<int N>
+struct ToStringHelper<sal_Unicode const[N]>
+    {
+    static int length( const sal_Unicode str[ N ] ) { (void)str; assert( std::char_traits<char16_t>::length( str ) == N - 1 ); return N - 1; }
     static sal_Unicode * addData(sal_Unicode * buffer, sal_Unicode const str[N])
     { return addDataHelper(buffer, str, N - 1); }
     static bool const allowOStringConcat = false;
     static bool const allowOUStringConcat = true;
-};
+    };
 
-template<> struct ToStringHelper<OUStringLiteral1_> {
+template<>
+struct ToStringHelper<OUStringLiteral1_>
+    {
     static int length(OUStringLiteral1_) { return 1; }
-    static sal_Unicode * addData(
-        sal_Unicode * buffer, OUStringLiteral1_ literal)
+    static sal_Unicode * addData(sal_Unicode * buffer, OUStringLiteral1_ literal)
     { return addDataHelper(buffer, &literal.c, 1); }
     static bool const allowOStringConcat = false;
     static bool const allowOUStringConcat = true;
-};
+    };
 
 /**
 @internal
diff --git a/sal/qa/rtl/strings/test_oustring_concat.cxx b/sal/qa/rtl/strings/test_oustring_concat.cxx
index 56b38ec1ee90..6e1b209f7189 100644
--- a/sal/qa/rtl/strings/test_oustring_concat.cxx
+++ b/sal/qa/rtl/strings/test_oustring_concat.cxx
@@ -71,6 +71,9 @@ void test::oustring::StringConcat::checkConcat()
     const char d1[] = "xyz";
     CPPUNIT_ASSERT_EQUAL( OUString( "fooxyz" ), OUString( OUString( "foo" ) + d1 ));
     CPPUNIT_ASSERT_EQUAL(( typeid( OUStringConcat< OUString, const char[ 4 ] > )), typeid( OUString( "foo" ) + d1 ));
+    const sal_Unicode* d2 = u"xyz";
+    CPPUNIT_ASSERT_EQUAL( OUString( "fooxyz" ), OUString( OUString( "foo" ) + d2 ));
+    CPPUNIT_ASSERT_EQUAL(( typeid( OUStringConcat< OUString, const sal_Unicode* > )), typeid( OUString( "foo" ) + d2 ));
 
     CPPUNIT_ASSERT_EQUAL( OUString( "num10" ), OUString( OUString( "num" ) + OUString::number( 10 )));
     CPPUNIT_ASSERT_EQUAL(( typeid( OUStringConcat< OUString, OUStringNumber< int > > )), typeid( OUString( "num" ) + OUString::number( 10 )));


More information about the Libreoffice-commits mailing list