/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * 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/.
*/
static std::size_t ParseMathMLUnsignedNumber(std::u16string_view rStr, Fraction& rUN)
{ auto nLen = rStr.length();
std::size_t nDecimalPoint = std::u16string_view::npos;
std::size_t nIdx;
sal_Int64 nom = 0;
sal_Int64 den = 1; bool validNomDen = true; for (nIdx = 0; nIdx < nLen; nIdx++)
{ auto cD = rStr[nIdx]; if (cD == u'.')
{ if (nDecimalPoint != std::u16string_view::npos) return std::u16string_view::npos;
nDecimalPoint = nIdx; continue;
} if (cD < u'0' || u'9' < cD) break; if (validNomDen
&& (o3tl::checked_multiply(nom, sal_Int64(10), nom)
|| o3tl::checked_add(nom, sal_Int64(cD - u'0'), nom)
|| nom >= std::numeric_limits<sal_Int32>::max()
|| (nDecimalPoint != std::u16string_view::npos
&& o3tl::checked_multiply(den, sal_Int64(10), den))))
{
validNomDen = false;
}
} if (nIdx == 0 || (nIdx == 1 && nDecimalPoint == 0)) return std::u16string_view::npos;
// If the input "xx.yyy" can be represented with nom = xx*10^n + yyy and den = 10^n in sal_Int64 // (where n is the length of "yyy"), then use that to create an accurate Fraction (and TODO: we // could even ignore trailing "0" characters in "yyy", for a smaller n and thus a greater chance // of validNomDen); if not, use the less accurate approach of creating a Fraction from double: if (validNomDen)
{
rUN = Fraction(nom, den);
} else
{
rUN = Fraction(
rtl_math_uStringToDouble(rStr.data(), rStr.data() + nIdx, '.', 0, nullptr, nullptr));
}
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.