diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2019-09-26 12:46:41 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-09-27 15:03:41 +0200 |
commit | 89bb0b0dcd8dc4656d0047cd10702d1c471c0fa1 (patch) | |
tree | 890d97eaf2bbcab24cb777f8a65bd6fb47f4218d /include/rtl | |
parent | 4b995afda324fb4e85991c723b63a2703f33669e (diff) |
Deduplicate O(U)StringNumber definitions; add toAsciiUpperCase
Change-Id: I00e7ce62940907b5f4efc2b7f23f355c3e43ed6b
Reviewed-on: https://gerrit.libreoffice.org/79686
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'include/rtl')
-rw-r--r-- | include/rtl/stringconcat.hxx | 97 |
1 files changed, 44 insertions, 53 deletions
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 <class Derived, int nBufSize> 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<Derived*>(this)); + } + char buf[nBufSize]; + sal_Int32 length; +}; + +template<> +struct OStringNumber< int > + : public OStringNumberBase<OStringNumber<int>, RTL_STR_MAX_VALUEOFINT32> +{ + OStringNumber(int i, sal_Int16 radix) { length = rtl_str_valueOfInt32(buf, i, radix); } }; template<> struct OStringNumber< long long > + : public OStringNumberBase<OStringNumber<long long>, 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<OStringNumber<unsigned long long>, 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<OStringNumber<float>, 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<OStringNumber<double>, 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 <class Derived, int nBufSize> struct OUStringNumberBase +{ + Derived&& toAsciiUpperCase() + { + rtl_ustr_toAsciiUpperCase_WithLength(buf, length); + return std::move(*static_cast<Derived*>(this)); + } + sal_Unicode buf[nBufSize]; + sal_Int32 length; +}; + template<> struct OUStringNumber< int > + : public OUStringNumberBase<OUStringNumber<int>, 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<OUStringNumber<long long>, 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<OUStringNumber<unsigned long long>, 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<OUStringNumber<float>, 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<OUStringNumber<double>, 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 > |