mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-24 18:35:37 +00:00
Implement AFMakeNumber
Also make stringToNumber be stubborn when converting strings to numbers CCBUGS: 418445
This commit is contained in:
parent
9084bfaabe
commit
d3b43b0b1e
|
@ -136,6 +136,16 @@ function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bC
|
|||
return;
|
||||
}
|
||||
|
||||
function AFMakeNumber(string)
|
||||
{
|
||||
var type = typeof string;
|
||||
if ( type == "number" )
|
||||
return string;
|
||||
if ( type != "string" )
|
||||
return 0;
|
||||
return util.stringToNumber( string );
|
||||
}
|
||||
|
||||
/** AFTime_Format
|
||||
*
|
||||
* Formats event.value based on parameters.
|
||||
|
|
|
@ -158,9 +158,10 @@ static KJSObject numberToString ( KJSContext *context, void *,
|
|||
return KJSString( locale.toString( number, format.toLatin1(), precision ) );
|
||||
}
|
||||
|
||||
/** Converts a String to a Number using l10n.
|
||||
/** Converts a String to a Number trying with the current locale first and
|
||||
* if that fails trying with the reverse locale for the decimal separator
|
||||
*
|
||||
* Number stringToNumber( String number, String LocaleName = system ) */
|
||||
* Number stringToNumber( String number ) */
|
||||
static KJSObject stringToNumber ( KJSContext *context, void *,
|
||||
const KJSArguments &arguments )
|
||||
{
|
||||
|
@ -175,18 +176,18 @@ static KJSObject stringToNumber ( KJSContext *context, void *,
|
|||
return KJSNumber( 0 );
|
||||
}
|
||||
|
||||
QLocale locale;
|
||||
if ( arguments.count() == 2 )
|
||||
{
|
||||
locale = QLocale( arguments.at( 1 ).toString( context ) );
|
||||
}
|
||||
|
||||
const QLocale locale;
|
||||
bool ok;
|
||||
const double converted = locale.toDouble( number, &ok );
|
||||
double converted = locale.toDouble( number, &ok );
|
||||
|
||||
if ( !ok )
|
||||
{
|
||||
return KJSNumber( std::nan( "" ) );
|
||||
const QLocale locale2( locale.decimalPoint() == QLatin1Char('.') ? QStringLiteral("de") : QStringLiteral("en") );
|
||||
converted = locale2.toDouble( number, &ok );
|
||||
if ( !ok )
|
||||
{
|
||||
return KJSNumber( std::nan( "" ) );
|
||||
}
|
||||
}
|
||||
|
||||
return KJSNumber( converted );
|
||||
|
|
Loading…
Reference in a new issue