/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
/** constructs a SvXMLUnitConverter. The core measure unit is the default unit for numerical measures, the XML measure unit is the default unit for textual measures
*/
/** convert string to enum using given enum map, if the enum is not found in the map, this method will return false
*/ bool SvXMLUnitConverter::convertEnumImpl( sal_uInt16& rEnum,
std::u16string_view rValue, const SvXMLEnumStringMapEntry<sal_uInt16> *pMap )
{ while( pMap->GetName() )
{ auto nameLength = pMap->GetNameLength(); if( static_cast<sal_Int32>(rValue.size()) == nameLength &&
rtl_ustr_asciil_reverseEquals_WithLength(
rValue.data(), pMap->GetName(), nameLength ) )
{
rEnum = pMap->GetValue(); returntrue;
}
++pMap;
}
returnfalse;
}
/** convert string to enum using given token map, if the enum is
not found in the map, this method will return false */ bool SvXMLUnitConverter::convertEnumImpl(
sal_uInt16& rEnum,
std::u16string_view rValue, const SvXMLEnumMapEntry<sal_uInt16> *pMap )
{ while( pMap->GetToken() != XML_TOKEN_INVALID )
{ if( IsXMLToken( rValue, pMap->GetToken() ) )
{
rEnum = pMap->GetValue(); returntrue;
}
++pMap;
} returnfalse;
}
/** convert string to enum using given token map, if the enum is
not found in the map, this method will return false */ bool SvXMLUnitConverter::convertEnumImpl(
sal_uInt16& rEnum,
std::string_view rValue, const SvXMLEnumMapEntry<sal_uInt16> *pMap )
{ while( pMap->GetToken() != XML_TOKEN_INVALID )
{ if( IsXMLToken( rValue, pMap->GetToken() ) )
{
rEnum = pMap->GetValue(); returntrue;
}
++pMap;
} returnfalse;
}
/** convert enum to string using given token map with an optional default token. If the enum is not found in the map, this method will either use the given default or return
false if no default is set */ bool SvXMLUnitConverter::convertEnumImpl(
OUStringBuffer& rBuffer,
sal_uInt16 nValue, const SvXMLEnumMapEntry<sal_uInt16> *pMap, enum XMLTokenEnum eDefault)
{ enum XMLTokenEnum eTok = eDefault;
/** get the Null Date of the XModel and set it to the UnitConverter */ bool SvXMLUnitConverter::setNullDate(const css::uno::Reference <css::frame::XModel>& xModel)
{
css::uno::Reference <css::util::XNumberFormatsSupplier> xNumberFormatsSupplier (xModel, css::uno::UNO_QUERY); if (xNumberFormatsSupplier.is())
{ const css::uno::Reference <css::beans::XPropertySet> xPropertySet = xNumberFormatsSupplier->getNumberFormatSettings(); return xPropertySet.is() && (xPropertySet->getPropertyValue(XML_NULLDATE) >>= m_pImpl->m_aNullDate);
} returnfalse;
}
/** convert double to ISO Date Time String */ void SvXMLUnitConverter::convertDateTime(OUStringBuffer& rBuffer, constdouble& fDateTime, boolconst bAddTimeIf0AM)
{
convertDateTime(rBuffer, fDateTime, m_pImpl->m_aNullDate, bAddTimeIf0AM);
}
/** convert ISO Date Time String to double */ bool SvXMLUnitConverter::convertDateTime(double& fDateTime,
std::u16string_view rString) const
{ return convertDateTime(fDateTime, rString, m_pImpl->m_aNullDate);
}
/** convert ISO Date Time String to double */ bool SvXMLUnitConverter::convertDateTime(double& fDateTime,
std::string_view rString) const
{ return convertDateTime(fDateTime, rString, m_pImpl->m_aNullDate);
}
/** convert double to ISO Date Time String */ void SvXMLUnitConverter::convertDateTime( OUStringBuffer& rBuffer, constdouble& fDateTime, const css::util::Date& aTempNullDate, bool bAddTimeIf0AM )
{ double fValue = fDateTime; const sal_Int32 nDays = static_cast <sal_Int32> (::rtl::math::approxFloor (fValue));
Date aDate (aTempNullDate.Day, aTempNullDate.Month, aTempNullDate.Year);
aDate.AddDays( nDays);
fValue -= nDays; constbool bHasTime = (fValue > 0.0);
// Since the beginning from initial source code import this was 11 without // further explanation, effectively limiting fractions in ~current // date+time to 2 decimals (maybe because old class Time code had a // resolution of only 100th seconds). Preserve at least milliseconds, but // strive for more. // NOTE: sax/source/tools/converter.cxx uses 14-5 in a different context // rounding nanoseconds and fractions of seconds.
constexpr int XML_MAXDIGITSCOUNT_TIME = 14;
sal_uInt16 nHour, nMinute, nSecond; double fFractionOfSecond; // Pass the original date+time value for proper scaling and rounding.
tools::Time::GetClock( fDateTime, nHour, nMinute, nSecond, fFractionOfSecond, nFractionDecimals);
rBuffer.append( 'T'); if (nHour < 10)
rBuffer.append( '0');
rBuffer.append( sal_Int32( nHour));
rBuffer.append( ':'); if (nMinute < 10)
rBuffer.append( '0');
rBuffer.append( sal_Int32( nMinute));
rBuffer.append( ':'); if (nSecond < 10)
rBuffer.append( '0');
rBuffer.append( sal_Int32( nSecond)); if (!nFractionDecimals) return;
// nFractionDecimals+1 to not round up what GetClock() carefully // truncated.
OUString aFraction( ::rtl::math::doubleToUString( fFractionOfSecond,
rtl_math_StringFormat_F,
nFractionDecimals + 1, '.', true)); const sal_Int32 nLen = aFraction.getLength(); if ( nLen > 2 )
{ // Truncate nFractionDecimals+1 digit if it was not rounded to zero. const sal_Int32 nCount = nLen - 2 - static_cast<int>(nLen > nFractionDecimals + 2);
rBuffer.append( '.');
rBuffer.append( aFraction.subView(2, nCount)); // strip 0.
}
}
/** convert ISO Date Time String to double */ template<typename V> staticbool lcl_convertDateTime( double& fDateTime,
V rString, const css::util::Date& aTempNullDate)
{
css::util::DateTime aDateTime; bool bSuccess = ::sax::Converter::parseDateTime(aDateTime, rString);
// if the mnNextTokenPos is at the end of the string, we have // to deliver an empty token if( mnNextTokenPos > maTokenString.size() )
mnNextTokenPos = std::u16string_view::npos;
} else
{
rToken = maTokenString.substr( mnNextTokenPos );
mnNextTokenPos = std::u16string_view::npos;
}
void SvXMLUnitConverter::convertNumFormat( OUStringBuffer& rBuffer,
sal_Int16 nType ) const
{ enum XMLTokenEnum eFormat = XML_TOKEN_INVALID; switch( nType )
{ case NumberingType::CHARS_UPPER_LETTER: eFormat = XML_A_UPCASE; break; case NumberingType::CHARS_LOWER_LETTER: eFormat = XML_A; break; case NumberingType::ROMAN_UPPER: eFormat = XML_I_UPCASE; break; case NumberingType::ROMAN_LOWER: eFormat = XML_I; break; case NumberingType::ARABIC: eFormat = XML_1; break; case NumberingType::CHARS_UPPER_LETTER_N: eFormat = XML_A_UPCASE; break; case NumberingType::CHARS_LOWER_LETTER_N: eFormat = XML_A; break; case NumberingType::NUMBER_NONE: eFormat = XML__EMPTY; break;
case NumberingType::CHAR_SPECIAL: case NumberingType::PAGE_DESCRIPTOR: case NumberingType::BITMAP:
SAL_WARN_IF( eFormat == XML_TOKEN_INVALID, "xmloff", "invalid number format" ); break; default: break;
}
void SvXMLUnitConverter::convertNumLetterSync( OUStringBuffer& rBuffer,
sal_Int16 nType )
{ enum XMLTokenEnum eSync = XML_TOKEN_INVALID; switch( nType )
{ case NumberingType::CHARS_UPPER_LETTER: case NumberingType::CHARS_LOWER_LETTER: case NumberingType::ROMAN_UPPER: case NumberingType::ROMAN_LOWER: case NumberingType::ARABIC: case NumberingType::NUMBER_NONE: break;
case NumberingType::CHARS_UPPER_LETTER_N: case NumberingType::CHARS_LOWER_LETTER_N:
eSync = XML_TRUE; break;
case NumberingType::CHAR_SPECIAL: case NumberingType::PAGE_DESCRIPTOR: case NumberingType::BITMAP:
SAL_WARN_IF( eSync == XML_TOKEN_INVALID, "xmloff", "invalid number format" ); break;
} if( eSync != XML_TOKEN_INVALID )
rBuffer.append( GetXMLToken(eSync) );
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.