diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-11 09:23:41 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-11 15:16:22 +0200 |
commit | f1769094af821860dd9e1aa00904ba7123d27d1a (patch) | |
tree | 22f50261b71068bb2011301c9e1ef19ba30a873f /include/rtl | |
parent | f5d02bdc6831588c0442fa24c5913971a224c4fa (diff) |
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@collabora.co.uk>
Diffstat (limited to 'include/rtl')
-rw-r--r-- | include/rtl/stringconcat.hxx | 53 |
1 files changed, 37 insertions, 16 deletions
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 |