From 89bb0b0dcd8dc4656d0047cd10702d1c471c0fa1 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Thu, 26 Sep 2019 12:46:41 +0300 Subject: Deduplicate O(U)StringNumber definitions; add toAsciiUpperCase Change-Id: I00e7ce62940907b5f4efc2b7f23f355c3e43ed6b Reviewed-on: https://gerrit.libreoffice.org/79686 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- include/rtl/stringconcat.hxx | 97 ++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 53 deletions(-) (limited to 'include/rtl') diff --git a/include/rtl/stringconcat.hxx b/include/rtl/stringconcat.hxx index 50522636ea3d..eea2e7afcd47 100644 --- a/include/rtl/stringconcat.hxx +++ b/include/rtl/stringconcat.hxx @@ -321,62 +321,55 @@ OString::number() to OString. template< typename T > struct OStringNumber; -template<> -struct OStringNumber< int > +template struct OStringNumberBase { - OStringNumber( int i, sal_Int16 radix ) - : length( rtl_str_valueOfInt32( buf, i, radix )) - {} // OString::number(value).getStr() is very common (writing xml code, ...), // so implement that one also here, to avoid having to explicitly to convert // to OString in all such places const char * getStr() const SAL_RETURNS_NONNULL { return buf; } - char buf[RTL_STR_MAX_VALUEOFINT32]; - const sal_Int32 length; + Derived&& toAsciiUpperCase() + { + rtl_str_toAsciiUpperCase_WithLength(buf, length); + return std::move(*static_cast(this)); + } + char buf[nBufSize]; + sal_Int32 length; +}; + +template<> +struct OStringNumber< int > + : public OStringNumberBase, RTL_STR_MAX_VALUEOFINT32> +{ + OStringNumber(int i, sal_Int16 radix) { length = rtl_str_valueOfInt32(buf, i, radix); } }; template<> struct OStringNumber< long long > + : public OStringNumberBase, RTL_STR_MAX_VALUEOFINT64> { - OStringNumber( long long ll, sal_Int16 radix ) - : length( rtl_str_valueOfInt64( buf, ll, radix )) - {} - const char * getStr() const SAL_RETURNS_NONNULL { return buf; } - char buf[RTL_STR_MAX_VALUEOFINT64]; - const sal_Int32 length; + OStringNumber(long long ll, sal_Int16 radix) { length = rtl_str_valueOfInt64(buf, ll, radix); } }; template<> struct OStringNumber< unsigned long long > + : public OStringNumberBase, RTL_STR_MAX_VALUEOFUINT64> { OStringNumber( unsigned long long ll, sal_Int16 radix ) - : length( rtl_str_valueOfUInt64( buf, ll, radix )) - {} - const char * getStr() const SAL_RETURNS_NONNULL { return buf; } - char buf[RTL_STR_MAX_VALUEOFUINT64]; - const sal_Int32 length; + { length = rtl_str_valueOfUInt64(buf, ll, radix); } }; template<> struct OStringNumber< float > + : public OStringNumberBase, RTL_STR_MAX_VALUEOFFLOAT> { - OStringNumber( float f ) - : length( rtl_str_valueOfFloat( buf, f )) - {} - const char * getStr() const SAL_RETURNS_NONNULL { return buf; } - char buf[RTL_STR_MAX_VALUEOFFLOAT]; - const sal_Int32 length; + OStringNumber(float f) { length = rtl_str_valueOfFloat(buf, f); } }; template<> struct OStringNumber< double > + : public OStringNumberBase, RTL_STR_MAX_VALUEOFDOUBLE> { - OStringNumber( double d ) - : length( rtl_str_valueOfDouble( buf, d )) - {} - const char * getStr() const SAL_RETURNS_NONNULL { return buf; } - char buf[RTL_STR_MAX_VALUEOFDOUBLE]; - const sal_Int32 length; + OStringNumber(double d) { length = rtl_str_valueOfDouble(buf, d); } }; template< typename T > @@ -400,54 +393,52 @@ OUString::number() to OUString. template< typename T > struct OUStringNumber; +template struct OUStringNumberBase +{ + Derived&& toAsciiUpperCase() + { + rtl_ustr_toAsciiUpperCase_WithLength(buf, length); + return std::move(*static_cast(this)); + } + sal_Unicode buf[nBufSize]; + sal_Int32 length; +}; + template<> struct OUStringNumber< int > + : public OUStringNumberBase, RTL_USTR_MAX_VALUEOFINT32> { - OUStringNumber( int i, sal_Int16 radix ) - : length( rtl_ustr_valueOfInt32( buf, i, radix )) - {} - sal_Unicode buf[RTL_USTR_MAX_VALUEOFINT32]; - const sal_Int32 length; + OUStringNumber(int i, sal_Int16 radix) { length = rtl_ustr_valueOfInt32(buf, i, radix); } }; template<> struct OUStringNumber< long long > + : public OUStringNumberBase, RTL_USTR_MAX_VALUEOFINT64> { OUStringNumber( long long ll, sal_Int16 radix ) - : length( rtl_ustr_valueOfInt64( buf, ll, radix )) - {} - sal_Unicode buf[RTL_USTR_MAX_VALUEOFINT64]; - const sal_Int32 length; + { length = rtl_ustr_valueOfInt64(buf, ll, radix); } }; template<> struct OUStringNumber< unsigned long long > + : public OUStringNumberBase, RTL_USTR_MAX_VALUEOFUINT64> { OUStringNumber( unsigned long long ll, sal_Int16 radix ) - : length( rtl_ustr_valueOfUInt64( buf, ll, radix )) - {} - sal_Unicode buf[RTL_USTR_MAX_VALUEOFUINT64]; - const sal_Int32 length; + { length = rtl_ustr_valueOfUInt64(buf, ll, radix); } }; template<> struct OUStringNumber< float > + : public OUStringNumberBase, RTL_USTR_MAX_VALUEOFFLOAT> { - OUStringNumber( float f ) - : length( rtl_ustr_valueOfFloat( buf, f )) - {} - sal_Unicode buf[RTL_USTR_MAX_VALUEOFFLOAT]; - const sal_Int32 length; + OUStringNumber(float f) { length = rtl_ustr_valueOfFloat(buf, f); } }; template<> struct OUStringNumber< double > + : public OUStringNumberBase, RTL_USTR_MAX_VALUEOFDOUBLE> { - OUStringNumber( double d ) - : length( rtl_ustr_valueOfDouble( buf, d )) - {} - sal_Unicode buf[RTL_USTR_MAX_VALUEOFDOUBLE]; - const sal_Int32 length; + OUStringNumber(double d) { length = rtl_ustr_valueOfDouble(buf, d); } }; template< typename T > -- cgit v1.2.3