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>
This commit is contained in:
Mike Kaganski
2019-09-27 15:03:41 +02:00
parent 4b995afda3
commit 89bb0b0dcd
11 changed files with 57 additions and 67 deletions
+3 -3
View File
@@ -873,7 +873,7 @@ IMPL_LINK(SvxCharacterMap, CharClickHdl, SvxCharView*, rView, void)
OUString charValue = rView->GetText();
sal_Int32 tmp = 1;
sal_UCS4 cChar = charValue.iterateCodePoints(&tmp, -1);
OUString aHexText = OUString(OUString::number(cChar, 16)).toAsciiUpperCase();
OUString aHexText = OUString::number(cChar, 16).toAsciiUpperCase();
// Get the decimal code
OUString aDecimalText = OUString::number(cChar);
@@ -961,7 +961,7 @@ IMPL_LINK_NOARG(SvxCharacterMap, CharHighlightHdl, SvxShowCharSet*, void)
// using the new UCS4 constructor
aText = OUString( &cChar, 1 );
// Get the hexadecimal code
aHexText = OUString(OUString::number(cChar, 16)).toAsciiUpperCase();
aHexText = OUString::number(cChar, 16).toAsciiUpperCase();
// Get the decimal code
aDecimalText = OUString::number(cChar);
setCharName(cChar);
@@ -1001,7 +1001,7 @@ IMPL_LINK_NOARG(SvxCharacterMap, SearchCharHighlightHdl, SvxShowCharSet*, void)
{
aText = OUString( &cChar, 1 );
// Get the hexadecimal code
aHexText = OUString(OUString::number(cChar, 16)).toAsciiUpperCase();
aHexText = OUString::number(cChar, 16).toAsciiUpperCase();
// Get the decimal code
aDecimalText = OUString::number(cChar);
setCharName(cChar);
+44 -53
View File
@@ -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 >
+1 -1
View File
@@ -3137,7 +3137,7 @@ void writeLabelProperties( const FSHelperPtr& pFS, ChartExport* pChartExport,
{
pFS->startElement(FSNS(XML_a, XML_solidFill));
OString aStr = OString(OString::number(nLabelBorderColor, 16)).toAsciiUpperCase();
OString aStr = OString::number(nLabelBorderColor, 16).toAsciiUpperCase();
pFS->singleElement(FSNS(XML_a, XML_srgbClr), XML_val, aStr);
pFS->endElement(FSNS(XML_a, XML_solidFill));
+1 -1
View File
@@ -437,7 +437,7 @@ void ScInterpreter::ScEncodeURL()
else
{
aUrlBuf.append( '%' );
OString convertedChar = OString( OString::number( static_cast<unsigned char>( c ), 16 )).toAsciiUpperCase();
OString convertedChar = OString::number( static_cast<unsigned char>( c ), 16 ).toAsciiUpperCase();
// RFC 3986 indicates:
// "A percent-encoded octet is encoded as a character triplet,
// consisting of the percent character "%" followed by the two hexadecimal digits
+1 -1
View File
@@ -709,7 +709,7 @@ OUString ConvertFromDec( double fNum, double fMin, double fMax, sal_uInt16 nBase
if( bNeg )
nNum = sal_Int64( pow( double( nBase ), double( nMaxPlaces ) ) ) + nNum;
OUString aRet( OUString( OUString::number( nNum, nBase )).toAsciiUpperCase() );
OUString aRet(OUString::number(nNum, nBase).toAsciiUpperCase());
if( bUsePlaces )
+1 -1
View File
@@ -1584,7 +1584,7 @@ IMPL_LINK_NOARG(SmSymDefineDialog, CharHighlightHdl, SvxShowCharSet*, void)
UpdateButtons();
// display Unicode position as symbol name while iterating over characters
const OUString aHex(OUString(OUString::number(cChar, 16 )).toAsciiUpperCase());
const OUString aHex(OUString::number(cChar, 16).toAsciiUpperCase());
const OUString aPattern( (aHex.getLength() > 4) ? OUString("Ux000000") : OUString("Ux0000") );
OUString aUnicodePos( aPattern.copy( 0, aPattern.getLength() - aHex.getLength() ) );
aUnicodePos += aHex;
+1 -1
View File
@@ -4210,7 +4210,7 @@ OUString NfCurrencyEntry::BuildSymbolString(bool bBank,
if ( !bWithoutExtension && eLanguage != LANGUAGE_DONTKNOW && eLanguage != LANGUAGE_SYSTEM )
{
sal_Int32 nLang = static_cast<sal_uInt16>(eLanguage);
aBuf.append('-').append( OUString( OUString::number(nLang, 16)).toAsciiUpperCase());
aBuf.append('-').append(OUString::number(nLang, 16).toAsciiUpperCase());
}
}
aBuf.append(']');
+2 -2
View File
@@ -1165,7 +1165,7 @@ SvNumberformat::SvNumberformat(OUString& rString,
((eLanguage = MsLangId::getRealLanguage( eLan)) == LANGUAGE_THAI) &&
NumFor[nIndex].GetNatNum().GetLang() == LANGUAGE_DONTKNOW)
{
sStr = "[$-" + OUString(OUString::number( sal_uInt16(eLanguage), 16 )).toAsciiUpperCase() + "]" + sStr;
sStr = "[$-" + OUString::number( sal_uInt16(eLanguage), 16 ).toAsciiUpperCase() + "]" + sStr;
NumFor[nIndex].SetNatNumLang( eLanguage);
}
sBuff.remove(nPosOld, nPos - nPosOld);
@@ -5085,7 +5085,7 @@ static void lcl_insertLCID( OUStringBuffer& rFormatStr, sal_uInt32 nLCID, sal_In
// No format code, no locale.
return;
OUStringBuffer aLCIDString = OUString(OUString::number( nLCID , 16 )).toAsciiUpperCase();
OUStringBuffer aLCIDString = OUString::number( nLCID , 16 ).toAsciiUpperCase();
// Search for only last DBNum which is the last element before insertion position
if ( bDBNumInserted && nPosInsertLCID >= 8
&& aLCIDString.getLength() > 4
+1 -2
View File
@@ -244,8 +244,7 @@ ALNUM {DIGIT}|{ALPHA}
unsigned char c = yytext[0];
yyextra->errorMessage = c >= ' ' && c <= '~'
? OUString("invalid character \"" + OUStringLiteral1(c) + "\"")
: OUString(
"invalid byte x" + OUString(OUString::number(c, 16)).toAsciiUpperCase());
: OUString("invalid byte x" + OUString::number(c, 16).toAsciiUpperCase());
return TOK_ERROR;
}
@@ -170,7 +170,7 @@ STDMETHODIMP CAccTextBase::get_attributes(long offset, long * startOffset, long
unsigned long nColor;
pValue.Value >>= nColor;
strAttrs.append('#');
auto const hex = OUString(OUString::number(nColor, 16)).toAsciiUpperCase();
OUString const hex = OUString::number(nColor, 16).toAsciiUpperCase();
for (sal_Int32 j = hex.getLength(); j < 8; ++j) {
strAttrs.append('0');
}
+1 -1
View File
@@ -1474,7 +1474,7 @@ SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport,
{
aFormatCode.append( "][$-" );
// language code in upper hex:
aFormatCode.append(OUString(OUString::number(static_cast<sal_uInt16>(eLang), 16)).toAsciiUpperCase());
aFormatCode.append(OUString::number(static_cast<sal_uInt16>(eLang), 16).toAsciiUpperCase());
}
aFormatCode.append( ']' );
}