From 4cd5b80e70e5fc50d8bd805cfa3c7b54878a0a35 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 14 Jan 2016 17:25:08 -0800 Subject: Cleanup CJS_PublicMethods::ParseNumber Original patch by tombergan. The old version of this function was basically strtod with a few quirks: 1. It always interpreted ',' as '.' independent of locale. I kept this behavior, to be conservative. 2. It interpreted the first non-number character as a decimal point, unless there was a prior decimal point, in which case all characters up to that point are ignored. This would parse "123z4" as "123.4" and "123xy6" as "6". I did not keep this behavior -- in the new code, these examples all fail to parse. The new ParseNumber was inlined into ConvertStringToNumber, which returns true on success and (false, 0) on failure. BUG=pdfium:361 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1582013002 . --- fpdfsdk/src/javascript/Field.cpp | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'fpdfsdk/src/javascript/Field.cpp') diff --git a/fpdfsdk/src/javascript/Field.cpp b/fpdfsdk/src/javascript/Field.cpp index 959e8dcadd..ebd3d331f5 100644 --- a/fpdfsdk/src/javascript/Field.cpp +++ b/fpdfsdk/src/javascript/Field.cpp @@ -2741,13 +2741,8 @@ FX_BOOL Field::value(IJS_Context* cc, CFX_WideString swValue = pFormField->GetValue(); double dRet; - FX_BOOL bDot; - if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet, - bDot)) { - if (bDot) - vp << dRet; - else - vp << dRet; + if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet)) { + vp << dRet; } else { vp << swValue; } @@ -2769,13 +2764,8 @@ FX_BOOL Field::value(IJS_Context* cc, CFX_WideString swValue = pFormField->GetValue(); double dRet; - FX_BOOL bDot; - if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet, - bDot)) { - if (bDot) - vp << dRet; - else - vp << dRet; + if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet)) { + vp << dRet; } else { vp << swValue; } @@ -2790,9 +2780,7 @@ FX_BOOL Field::value(IJS_Context* cc, CFX_WideString swValue = pFormField->GetControl(i)->GetExportValue(); double dRet; - FX_BOOL bDotDummy; - if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet, - bDotDummy)) { + if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet)) { vp << dRet; } else { vp << swValue; -- cgit v1.2.3