From f1769094af821860dd9e1aa00904ba7123d27d1a Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 11 Oct 2019 09:23:41 +0200 Subject: 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 --- include/rtl/stringconcat.hxx | 53 +++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 16 deletions(-) (limited to 'include') 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(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 struct ToStringHelper { - 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(std::char_traits::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 +struct ToStringHelper + { + static int length( const sal_Unicode str[ N ] ) { + return sal::static_int_cast(std::char_traits::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 +struct ToStringHelper + { + static int length( const sal_Unicode str[ N ] ) { (void)str; assert( std::char_traits::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 { +template<> +struct ToStringHelper + { 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 -- cgit