summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r--xfa/fxfa/parser/xfa_localevalue.cpp62
-rw-r--r--xfa/fxfa/parser/xfa_utils.cpp33
-rw-r--r--xfa/fxfa/parser/xfa_utils.h3
3 files changed, 53 insertions, 45 deletions
diff --git a/xfa/fxfa/parser/xfa_localevalue.cpp b/xfa/fxfa/parser/xfa_localevalue.cpp
index b86ab90f19..0e7b8c9c2f 100644
--- a/xfa/fxfa/parser/xfa_localevalue.cpp
+++ b/xfa/fxfa/parser/xfa_localevalue.cpp
@@ -17,22 +17,6 @@
#include "xfa/fxfa/parser/xfa_object.h"
#include "xfa/fxfa/parser/xfa_utils.h"
-static const double fraction_scales[] = {0.1,
- 0.01,
- 0.001,
- 0.0001,
- 0.00001,
- 0.000001,
- 0.0000001,
- 0.00000001,
- 0.000000001,
- 0.0000000001,
- 0.00000000001,
- 0.000000000001,
- 0.0000000000001,
- 0.00000000000001,
- 0.000000000000001,
- 0.0000000000000001};
CXFA_LocaleValue::CXFA_LocaleValue() {
m_dwType = XFA_VT_NULL;
m_bValid = true;
@@ -248,10 +232,10 @@ float CXFA_LocaleValue::GetNum() const {
if (cc < len && str[cc] == '.') {
cc++;
while (cc < len) {
- fraction += fraction_scales[scale] * (str[cc] - '0');
+ fraction += XFA_GetFractionalScale(scale) * (str[cc] - '0');
scale++;
cc++;
- if (scale == sizeof fraction_scales / sizeof(double) ||
+ if (scale == XFA_GetMaxFractionalScale() ||
!FXSYS_isDecimalDigit(str[cc])) {
break;
}
@@ -296,18 +280,18 @@ double CXFA_LocaleValue::GetDoubleNum() const {
bool bNegative = false, bExpSign = false;
const wchar_t* str = m_wsValue.c_str();
int len = m_wsValue.GetLength();
- while (FXSYS_iswspace(str[cc]) && cc < len) {
+ while (FXSYS_iswspace(str[cc]) && cc < len)
cc++;
- }
- if (cc >= len) {
+
+ if (cc >= len)
return 0;
- }
if (str[0] == '+') {
cc++;
} else if (str[0] == '-') {
bNegative = true;
cc++;
}
+
int32_t nIntegralLen = 0;
while (cc < len) {
if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc]) ||
@@ -324,15 +308,15 @@ double CXFA_LocaleValue::GetDoubleNum() const {
if (cc < len && str[cc] == '.') {
cc++;
while (cc < len) {
- fraction += fraction_scales[scale] * (str[cc] - '0');
+ fraction += XFA_GetFractionalScale(scale) * (str[cc] - '0');
scale++;
cc++;
- if (scale == sizeof fraction_scales / sizeof(double) ||
+ if (scale == XFA_GetMaxFractionalScale() ||
!FXSYS_isDecimalDigit(str[cc])) {
break;
}
}
- dwFractional = (uint32_t)(fraction * 4294967296.0);
+ dwFractional = static_cast<uint32_t>(fraction * 4294967296.0);
}
if (cc < len && (str[cc] == 'E' || str[cc] == 'e')) {
cc++;
@@ -345,23 +329,25 @@ double CXFA_LocaleValue::GetDoubleNum() const {
}
}
while (cc < len) {
- if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc])) {
+ if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc]))
break;
- }
+
nExponent = nExponent * 10 + str[cc] - '0';
cc++;
}
nExponent = bExpSign ? -nExponent : nExponent;
}
- double dValue = (dwFractional / 4294967296.0);
+
+ double dValue = dwFractional / 4294967296.0;
dValue = nIntegral + (nIntegral >= 0 ? dValue : -dValue);
- if (nExponent != 0) {
- dValue *= FXSYS_pow(10, (float)nExponent);
- }
+ if (nExponent != 0)
+ dValue *= FXSYS_pow(10, static_cast<float>(nExponent));
+
return dValue;
}
return 0;
}
+
CFX_Unitime CXFA_LocaleValue::GetDate() const {
if (m_bValid && m_dwType == XFA_VT_DATE) {
CFX_Unitime dt;
@@ -370,6 +356,7 @@ CFX_Unitime CXFA_LocaleValue::GetDate() const {
}
return CFX_Unitime();
}
+
CFX_Unitime CXFA_LocaleValue::GetTime() const {
if (m_bValid && m_dwType == XFA_VT_TIME) {
CFX_Unitime dt(0);
@@ -380,6 +367,7 @@ CFX_Unitime CXFA_LocaleValue::GetTime() const {
}
return CFX_Unitime();
}
+
CFX_Unitime CXFA_LocaleValue::GetDateTime() const {
if (m_bValid && m_dwType == XFA_VT_DATETIME) {
int32_t index = m_wsValue.Find('T');
@@ -393,39 +381,46 @@ CFX_Unitime CXFA_LocaleValue::GetDateTime() const {
}
return CFX_Unitime();
}
+
bool CXFA_LocaleValue::SetText(const CFX_WideString& wsText) {
m_dwType = XFA_VT_TEXT;
m_wsValue = wsText;
return true;
}
+
bool CXFA_LocaleValue::SetText(const CFX_WideString& wsText,
const CFX_WideString& wsFormat,
IFX_Locale* pLocale) {
m_dwType = XFA_VT_TEXT;
return m_bValid = ParsePatternValue(wsText, wsFormat, pLocale);
}
+
bool CXFA_LocaleValue::SetNum(float fNum) {
m_dwType = XFA_VT_FLOAT;
- m_wsValue.Format(L"%.8g", (double)fNum);
+ m_wsValue.Format(L"%.8g", static_cast<double>(fNum));
return true;
}
+
bool CXFA_LocaleValue::SetNum(const CFX_WideString& wsNum,
const CFX_WideString& wsFormat,
IFX_Locale* pLocale) {
m_dwType = XFA_VT_FLOAT;
return m_bValid = ParsePatternValue(wsNum, wsFormat, pLocale);
}
+
bool CXFA_LocaleValue::SetDate(const CFX_Unitime& d) {
m_dwType = XFA_VT_DATE;
m_wsValue.Format(L"%04d-%02d-%02d", d.GetYear(), d.GetMonth(), d.GetDay());
return true;
}
+
bool CXFA_LocaleValue::SetDate(const CFX_WideString& wsDate,
const CFX_WideString& wsFormat,
IFX_Locale* pLocale) {
m_dwType = XFA_VT_DATE;
return m_bValid = ParsePatternValue(wsDate, wsFormat, pLocale);
}
+
bool CXFA_LocaleValue::SetTime(const CFX_Unitime& t) {
m_dwType = XFA_VT_TIME;
m_wsValue.Format(L"%02d:%02d:%02d", t.GetHour(), t.GetMinute(),
@@ -437,12 +432,14 @@ bool CXFA_LocaleValue::SetTime(const CFX_Unitime& t) {
}
return true;
}
+
bool CXFA_LocaleValue::SetTime(const CFX_WideString& wsTime,
const CFX_WideString& wsFormat,
IFX_Locale* pLocale) {
m_dwType = XFA_VT_TIME;
return m_bValid = ParsePatternValue(wsTime, wsFormat, pLocale);
}
+
bool CXFA_LocaleValue::SetDateTime(const CFX_Unitime& dt) {
m_dwType = XFA_VT_DATETIME;
m_wsValue.Format(L"%04d-%02d-%02dT%02d:%02d:%02d", dt.GetYear(),
@@ -455,6 +452,7 @@ bool CXFA_LocaleValue::SetDateTime(const CFX_Unitime& dt) {
}
return true;
}
+
bool CXFA_LocaleValue::SetDateTime(const CFX_WideString& wsDateTime,
const CFX_WideString& wsFormat,
IFX_Locale* pLocale) {
diff --git a/xfa/fxfa/parser/xfa_utils.cpp b/xfa/fxfa/parser/xfa_utils.cpp
index 101a6cf90e..5216d0cdd5 100644
--- a/xfa/fxfa/parser/xfa_utils.cpp
+++ b/xfa/fxfa/parser/xfa_utils.cpp
@@ -71,21 +71,19 @@ double WideStringToDouble(const CFX_WideString& wsStringVal) {
if (cc < len && str[cc] == '.') {
cc++;
while (cc < len) {
- fraction += fraction_scales[scale] * (str[cc] - '0');
+ fraction += XFA_GetFractionalScale(scale) * (str[cc] - '0');
scale++;
cc++;
- if (cc == len) {
+ if (cc == len)
break;
- }
- if (scale == sizeof(fraction_scales) / sizeof(double) || str[cc] == 'E' ||
+ if (scale == XFA_GetMaxFractionalScale() || str[cc] == 'E' ||
str[cc] == 'e') {
break;
}
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return 0;
- }
}
- dwFractional = (uint32_t)(fraction * 4294967296.0);
+ dwFractional = static_cast<uint32_t>(fraction * 4294967296.0);
}
if (cc < len && (str[cc] == 'E' || str[cc] == 'e')) {
cc++;
@@ -98,24 +96,33 @@ double WideStringToDouble(const CFX_WideString& wsStringVal) {
}
}
while (cc < len) {
- if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc])) {
+ if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc]))
return 0;
- }
+
nExponent = nExponent * 10 + str[cc] - '0';
cc++;
}
nExponent = bExpSign ? -nExponent : nExponent;
}
- double dValue = (dwFractional / 4294967296.0);
+
+ double dValue = dwFractional / 4294967296.0;
dValue = nIntegral + (nIntegral >= 0 ? dValue : -dValue);
- if (nExponent != 0) {
- dValue *= FXSYS_pow(10, (float)nExponent);
- }
+ if (nExponent != 0)
+ dValue *= FXSYS_pow(10, static_cast<float>(nExponent));
+
return dValue;
}
} // namespace
+double XFA_GetFractionalScale(uint32_t idx) {
+ return fraction_scales[idx];
+}
+
+int XFA_GetMaxFractionalScale() {
+ return FX_ArraySize(fraction_scales);
+}
+
CXFA_LocaleValue XFA_GetLocaleValue(CXFA_WidgetData* pWidgetData) {
CXFA_Node* pNodeValue =
pWidgetData->GetNode()->GetChild(0, XFA_Element::Value);
diff --git a/xfa/fxfa/parser/xfa_utils.h b/xfa/fxfa/parser/xfa_utils.h
index 73f6101f3e..c40fdf1b18 100644
--- a/xfa/fxfa/parser/xfa_utils.h
+++ b/xfa/fxfa/parser/xfa_utils.h
@@ -17,6 +17,9 @@ class CXFA_LocaleValue;
class CXFA_Node;
class CXFA_WidgetData;
+double XFA_GetFractionalScale(uint32_t idx);
+int XFA_GetMaxFractionalScale();
+
bool XFA_FDEExtension_ResolveNamespaceQualifier(
CFDE_XMLElement* pNode,
const CFX_WideStringC& wsQualifier,