OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fxfa/parser/xfa_localevalue.h" | 7 #include "xfa/fxfa/parser/xfa_localevalue.h" |
8 | 8 |
9 #include "core/fxcrt/fx_ext.h" | 9 #include "core/fxcrt/fx_ext.h" |
10 #include "xfa/fgas/localization/fgas_localeimp.h" | 10 #include "xfa/fgas/localization/fgas_localeimp.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 0.000000001, | 24 0.000000001, |
25 0.0000000001, | 25 0.0000000001, |
26 0.00000000001, | 26 0.00000000001, |
27 0.000000000001, | 27 0.000000000001, |
28 0.0000000000001, | 28 0.0000000000001, |
29 0.00000000000001, | 29 0.00000000000001, |
30 0.000000000000001, | 30 0.000000000000001, |
31 0.0000000000000001}; | 31 0.0000000000000001}; |
32 CXFA_LocaleValue::CXFA_LocaleValue() { | 32 CXFA_LocaleValue::CXFA_LocaleValue() { |
33 m_dwType = XFA_VT_NULL; | 33 m_dwType = XFA_VT_NULL; |
34 m_bValid = TRUE; | 34 m_bValid = true; |
35 m_pLocaleMgr = nullptr; | 35 m_pLocaleMgr = nullptr; |
36 } | 36 } |
37 CXFA_LocaleValue::CXFA_LocaleValue(const CXFA_LocaleValue& value) { | 37 CXFA_LocaleValue::CXFA_LocaleValue(const CXFA_LocaleValue& value) { |
38 m_dwType = XFA_VT_NULL; | 38 m_dwType = XFA_VT_NULL; |
39 m_bValid = TRUE; | 39 m_bValid = true; |
40 m_pLocaleMgr = nullptr; | 40 m_pLocaleMgr = nullptr; |
41 *this = value; | 41 *this = value; |
42 } | 42 } |
43 CXFA_LocaleValue::CXFA_LocaleValue(uint32_t dwType, | 43 CXFA_LocaleValue::CXFA_LocaleValue(uint32_t dwType, |
44 CXFA_LocaleMgr* pLocaleMgr) { | 44 CXFA_LocaleMgr* pLocaleMgr) { |
45 m_dwType = dwType; | 45 m_dwType = dwType; |
46 m_bValid = (m_dwType != XFA_VT_NULL); | 46 m_bValid = (m_dwType != XFA_VT_NULL); |
47 m_pLocaleMgr = pLocaleMgr; | 47 m_pLocaleMgr = pLocaleMgr; |
48 } | 48 } |
49 CXFA_LocaleValue::CXFA_LocaleValue(uint32_t dwType, | 49 CXFA_LocaleValue::CXFA_LocaleValue(uint32_t dwType, |
50 const CFX_WideString& wsValue, | 50 const CFX_WideString& wsValue, |
51 CXFA_LocaleMgr* pLocaleMgr) { | 51 CXFA_LocaleMgr* pLocaleMgr) { |
52 m_wsValue = wsValue; | 52 m_wsValue = wsValue; |
53 m_dwType = dwType; | 53 m_dwType = dwType; |
54 m_pLocaleMgr = pLocaleMgr; | 54 m_pLocaleMgr = pLocaleMgr; |
55 m_bValid = ValidateCanonicalValue(wsValue, dwType); | 55 m_bValid = ValidateCanonicalValue(wsValue, dwType); |
56 } | 56 } |
57 CXFA_LocaleValue::CXFA_LocaleValue(uint32_t dwType, | 57 CXFA_LocaleValue::CXFA_LocaleValue(uint32_t dwType, |
58 const CFX_WideString& wsValue, | 58 const CFX_WideString& wsValue, |
59 const CFX_WideString& wsFormat, | 59 const CFX_WideString& wsFormat, |
60 IFX_Locale* pLocale, | 60 IFX_Locale* pLocale, |
61 CXFA_LocaleMgr* pLocaleMgr) { | 61 CXFA_LocaleMgr* pLocaleMgr) { |
62 m_pLocaleMgr = pLocaleMgr; | 62 m_pLocaleMgr = pLocaleMgr; |
63 m_bValid = TRUE; | 63 m_bValid = true; |
64 m_dwType = dwType; | 64 m_dwType = dwType; |
65 m_bValid = ParsePatternValue(wsValue, wsFormat, pLocale); | 65 m_bValid = ParsePatternValue(wsValue, wsFormat, pLocale); |
66 } | 66 } |
67 CXFA_LocaleValue& CXFA_LocaleValue::operator=(const CXFA_LocaleValue& value) { | 67 CXFA_LocaleValue& CXFA_LocaleValue::operator=(const CXFA_LocaleValue& value) { |
68 m_wsValue = value.m_wsValue; | 68 m_wsValue = value.m_wsValue; |
69 m_dwType = value.m_dwType; | 69 m_dwType = value.m_dwType; |
70 m_bValid = value.m_bValid; | 70 m_bValid = value.m_bValid; |
71 m_pLocaleMgr = value.m_pLocaleMgr; | 71 m_pLocaleMgr = value.m_pLocaleMgr; |
72 return *this; | 72 return *this; |
73 } | 73 } |
(...skipping 12 matching lines...) Expand all Loading... |
86 case XFA_VT_DATE: | 86 case XFA_VT_DATE: |
87 return FX_LOCALECATEGORY_Date; | 87 return FX_LOCALECATEGORY_Date; |
88 case XFA_VT_TIME: | 88 case XFA_VT_TIME: |
89 return FX_LOCALECATEGORY_Time; | 89 return FX_LOCALECATEGORY_Time; |
90 case XFA_VT_DATETIME: | 90 case XFA_VT_DATETIME: |
91 return FX_LOCALECATEGORY_DateTime; | 91 return FX_LOCALECATEGORY_DateTime; |
92 } | 92 } |
93 } | 93 } |
94 return eCategory; | 94 return eCategory; |
95 } | 95 } |
96 FX_BOOL CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue, | 96 bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue, |
97 const CFX_WideString& wsPattern, | 97 const CFX_WideString& wsPattern, |
98 IFX_Locale* pLocale, | 98 IFX_Locale* pLocale, |
99 CFX_WideString* pMatchFormat) { | 99 CFX_WideString* pMatchFormat) { |
100 CFX_WideString wsOutput; | 100 CFX_WideString wsOutput; |
101 IFX_Locale* locale = m_pLocaleMgr->GetDefLocale(); | 101 IFX_Locale* locale = m_pLocaleMgr->GetDefLocale(); |
102 if (pLocale) { | 102 if (pLocale) { |
103 m_pLocaleMgr->SetDefLocale(pLocale); | 103 m_pLocaleMgr->SetDefLocale(pLocale); |
104 } | 104 } |
105 CFX_FormatString* pFormat = nullptr; | 105 CFX_FormatString* pFormat = nullptr; |
106 if (m_pLocaleMgr) | 106 if (m_pLocaleMgr) |
107 pFormat = new CFX_FormatString(m_pLocaleMgr, FALSE); | 107 pFormat = new CFX_FormatString(m_pLocaleMgr, false); |
108 | 108 |
109 CFX_WideStringArray wsPatterns; | 109 CFX_WideStringArray wsPatterns; |
110 pFormat->SplitFormatString(wsPattern, wsPatterns); | 110 pFormat->SplitFormatString(wsPattern, wsPatterns); |
111 FX_BOOL bRet = FALSE; | 111 bool bRet = false; |
112 int32_t iCount = wsPatterns.GetSize(); | 112 int32_t iCount = wsPatterns.GetSize(); |
113 int32_t i = 0; | 113 int32_t i = 0; |
114 for (; i < iCount && !bRet; i++) { | 114 for (; i < iCount && !bRet; i++) { |
115 CFX_WideString wsFormat = wsPatterns[i]; | 115 CFX_WideString wsFormat = wsPatterns[i]; |
116 FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat); | 116 FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat); |
117 eCategory = XFA_ValugeCategory(eCategory, m_dwType); | 117 eCategory = XFA_ValugeCategory(eCategory, m_dwType); |
118 switch (eCategory) { | 118 switch (eCategory) { |
119 case FX_LOCALECATEGORY_Null: | 119 case FX_LOCALECATEGORY_Null: |
120 bRet = pFormat->ParseNull(wsValue, wsFormat); | 120 bRet = pFormat->ParseNull(wsValue, wsFormat); |
121 if (!bRet) { | 121 if (!bRet) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 CFX_Unitime dt; | 170 CFX_Unitime dt; |
171 bRet = pFormat->ParseDateTime(wsValue, wsFormat, | 171 bRet = pFormat->ParseDateTime(wsValue, wsFormat, |
172 FX_DATETIMETYPE_DateTime, dt); | 172 FX_DATETIMETYPE_DateTime, dt); |
173 if (!bRet) { | 173 if (!bRet) { |
174 bRet = pFormat->FormatDateTime(wsValue, wsFormat, wsOutput, | 174 bRet = pFormat->FormatDateTime(wsValue, wsFormat, wsOutput, |
175 FX_DATETIMETYPE_DateTime); | 175 FX_DATETIMETYPE_DateTime); |
176 } | 176 } |
177 break; | 177 break; |
178 } | 178 } |
179 default: | 179 default: |
180 bRet = FALSE; | 180 bRet = false; |
181 break; | 181 break; |
182 } | 182 } |
183 } | 183 } |
184 if (bRet && pMatchFormat) { | 184 if (bRet && pMatchFormat) { |
185 *pMatchFormat = wsPatterns[i - 1]; | 185 *pMatchFormat = wsPatterns[i - 1]; |
186 } | 186 } |
187 pFormat->Release(); | 187 pFormat->Release(); |
188 if (pLocale) { | 188 if (pLocale) { |
189 m_pLocaleMgr->SetDefLocale(locale); | 189 m_pLocaleMgr->SetDefLocale(locale); |
190 } | 190 } |
(...skipping 16 matching lines...) Expand all Loading... |
207 } | 207 } |
208 return CFX_WideString(); | 208 return CFX_WideString(); |
209 } | 209 } |
210 FX_FLOAT CXFA_LocaleValue::GetNum() const { | 210 FX_FLOAT CXFA_LocaleValue::GetNum() const { |
211 if (m_bValid && (m_dwType == XFA_VT_BOOLEAN || m_dwType == XFA_VT_INTEGER || | 211 if (m_bValid && (m_dwType == XFA_VT_BOOLEAN || m_dwType == XFA_VT_INTEGER || |
212 m_dwType == XFA_VT_DECIMAL || m_dwType == XFA_VT_FLOAT)) { | 212 m_dwType == XFA_VT_DECIMAL || m_dwType == XFA_VT_FLOAT)) { |
213 int64_t nIntegral = 0; | 213 int64_t nIntegral = 0; |
214 uint32_t dwFractional = 0; | 214 uint32_t dwFractional = 0; |
215 int32_t nExponent = 0; | 215 int32_t nExponent = 0; |
216 int cc = 0; | 216 int cc = 0; |
217 FX_BOOL bNegative = FALSE, bExpSign = FALSE; | 217 bool bNegative = false, bExpSign = false; |
218 const FX_WCHAR* str = m_wsValue.c_str(); | 218 const FX_WCHAR* str = m_wsValue.c_str(); |
219 int len = m_wsValue.GetLength(); | 219 int len = m_wsValue.GetLength(); |
220 while (FXSYS_iswspace(str[cc]) && cc < len) { | 220 while (FXSYS_iswspace(str[cc]) && cc < len) { |
221 cc++; | 221 cc++; |
222 } | 222 } |
223 if (cc >= len) { | 223 if (cc >= len) { |
224 return 0; | 224 return 0; |
225 } | 225 } |
226 if (str[0] == '+') { | 226 if (str[0] == '+') { |
227 cc++; | 227 cc++; |
228 } else if (str[0] == '-') { | 228 } else if (str[0] == '-') { |
229 bNegative = TRUE; | 229 bNegative = true; |
230 cc++; | 230 cc++; |
231 } | 231 } |
232 int nIntegralLen = 0; | 232 int nIntegralLen = 0; |
233 while (cc < len) { | 233 while (cc < len) { |
234 if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc]) || | 234 if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc]) || |
235 nIntegralLen > 17) { | 235 nIntegralLen > 17) { |
236 break; | 236 break; |
237 } | 237 } |
238 nIntegral = nIntegral * 10 + str[cc] - '0'; | 238 nIntegral = nIntegral * 10 + str[cc] - '0'; |
239 cc++; | 239 cc++; |
(...skipping 14 matching lines...) Expand all Loading... |
254 } | 254 } |
255 } | 255 } |
256 dwFractional = (uint32_t)(fraction * 4294967296.0); | 256 dwFractional = (uint32_t)(fraction * 4294967296.0); |
257 } | 257 } |
258 if (cc < len && (str[cc] == 'E' || str[cc] == 'e')) { | 258 if (cc < len && (str[cc] == 'E' || str[cc] == 'e')) { |
259 cc++; | 259 cc++; |
260 if (cc < len) { | 260 if (cc < len) { |
261 if (str[cc] == '+') { | 261 if (str[cc] == '+') { |
262 cc++; | 262 cc++; |
263 } else if (str[cc] == '-') { | 263 } else if (str[cc] == '-') { |
264 bExpSign = TRUE; | 264 bExpSign = true; |
265 cc++; | 265 cc++; |
266 } | 266 } |
267 } | 267 } |
268 while (cc < len) { | 268 while (cc < len) { |
269 if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc])) { | 269 if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc])) { |
270 break; | 270 break; |
271 } | 271 } |
272 nExponent = nExponent * 10 + str[cc] - '0'; | 272 nExponent = nExponent * 10 + str[cc] - '0'; |
273 cc++; | 273 cc++; |
274 } | 274 } |
275 nExponent = bExpSign ? -nExponent : nExponent; | 275 nExponent = bExpSign ? -nExponent : nExponent; |
276 } | 276 } |
277 FX_FLOAT fValue = (FX_FLOAT)(dwFractional / 4294967296.0); | 277 FX_FLOAT fValue = (FX_FLOAT)(dwFractional / 4294967296.0); |
278 fValue = nIntegral + (nIntegral >= 0 ? fValue : -fValue); | 278 fValue = nIntegral + (nIntegral >= 0 ? fValue : -fValue); |
279 if (nExponent != 0) { | 279 if (nExponent != 0) { |
280 fValue *= FXSYS_pow(10, (FX_FLOAT)nExponent); | 280 fValue *= FXSYS_pow(10, (FX_FLOAT)nExponent); |
281 } | 281 } |
282 return fValue; | 282 return fValue; |
283 } | 283 } |
284 return 0; | 284 return 0; |
285 } | 285 } |
286 FX_DOUBLE CXFA_LocaleValue::GetDoubleNum() const { | 286 FX_DOUBLE CXFA_LocaleValue::GetDoubleNum() const { |
287 if (m_bValid && (m_dwType == XFA_VT_BOOLEAN || m_dwType == XFA_VT_INTEGER || | 287 if (m_bValid && (m_dwType == XFA_VT_BOOLEAN || m_dwType == XFA_VT_INTEGER || |
288 m_dwType == XFA_VT_DECIMAL || m_dwType == XFA_VT_FLOAT)) { | 288 m_dwType == XFA_VT_DECIMAL || m_dwType == XFA_VT_FLOAT)) { |
289 int64_t nIntegral = 0; | 289 int64_t nIntegral = 0; |
290 uint32_t dwFractional = 0; | 290 uint32_t dwFractional = 0; |
291 int32_t nExponent = 0; | 291 int32_t nExponent = 0; |
292 int32_t cc = 0; | 292 int32_t cc = 0; |
293 FX_BOOL bNegative = FALSE, bExpSign = FALSE; | 293 bool bNegative = false, bExpSign = false; |
294 const FX_WCHAR* str = m_wsValue.c_str(); | 294 const FX_WCHAR* str = m_wsValue.c_str(); |
295 int len = m_wsValue.GetLength(); | 295 int len = m_wsValue.GetLength(); |
296 while (FXSYS_iswspace(str[cc]) && cc < len) { | 296 while (FXSYS_iswspace(str[cc]) && cc < len) { |
297 cc++; | 297 cc++; |
298 } | 298 } |
299 if (cc >= len) { | 299 if (cc >= len) { |
300 return 0; | 300 return 0; |
301 } | 301 } |
302 if (str[0] == '+') { | 302 if (str[0] == '+') { |
303 cc++; | 303 cc++; |
304 } else if (str[0] == '-') { | 304 } else if (str[0] == '-') { |
305 bNegative = TRUE; | 305 bNegative = true; |
306 cc++; | 306 cc++; |
307 } | 307 } |
308 int32_t nIntegralLen = 0; | 308 int32_t nIntegralLen = 0; |
309 while (cc < len) { | 309 while (cc < len) { |
310 if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc]) || | 310 if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc]) || |
311 nIntegralLen > 17) { | 311 nIntegralLen > 17) { |
312 break; | 312 break; |
313 } | 313 } |
314 nIntegral = nIntegral * 10 + str[cc] - '0'; | 314 nIntegral = nIntegral * 10 + str[cc] - '0'; |
315 cc++; | 315 cc++; |
(...skipping 14 matching lines...) Expand all Loading... |
330 } | 330 } |
331 } | 331 } |
332 dwFractional = (uint32_t)(fraction * 4294967296.0); | 332 dwFractional = (uint32_t)(fraction * 4294967296.0); |
333 } | 333 } |
334 if (cc < len && (str[cc] == 'E' || str[cc] == 'e')) { | 334 if (cc < len && (str[cc] == 'E' || str[cc] == 'e')) { |
335 cc++; | 335 cc++; |
336 if (cc < len) { | 336 if (cc < len) { |
337 if (str[cc] == '+') { | 337 if (str[cc] == '+') { |
338 cc++; | 338 cc++; |
339 } else if (str[cc] == '-') { | 339 } else if (str[cc] == '-') { |
340 bExpSign = TRUE; | 340 bExpSign = true; |
341 cc++; | 341 cc++; |
342 } | 342 } |
343 } | 343 } |
344 while (cc < len) { | 344 while (cc < len) { |
345 if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc])) { | 345 if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc])) { |
346 break; | 346 break; |
347 } | 347 } |
348 nExponent = nExponent * 10 + str[cc] - '0'; | 348 nExponent = nExponent * 10 + str[cc] - '0'; |
349 cc++; | 349 cc++; |
350 } | 350 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 CFX_Unitime dt; | 383 CFX_Unitime dt; |
384 FX_DateFromCanonical(m_wsValue.Left(index), dt); | 384 FX_DateFromCanonical(m_wsValue.Left(index), dt); |
385 ASSERT(m_pLocaleMgr); | 385 ASSERT(m_pLocaleMgr); |
386 FX_TimeFromCanonical( | 386 FX_TimeFromCanonical( |
387 m_wsValue.Right(m_wsValue.GetLength() - index - 1).AsStringC(), dt, | 387 m_wsValue.Right(m_wsValue.GetLength() - index - 1).AsStringC(), dt, |
388 m_pLocaleMgr->GetDefLocale()); | 388 m_pLocaleMgr->GetDefLocale()); |
389 return dt; | 389 return dt; |
390 } | 390 } |
391 return CFX_Unitime(); | 391 return CFX_Unitime(); |
392 } | 392 } |
393 FX_BOOL CXFA_LocaleValue::SetText(const CFX_WideString& wsText) { | 393 bool CXFA_LocaleValue::SetText(const CFX_WideString& wsText) { |
394 m_dwType = XFA_VT_TEXT; | 394 m_dwType = XFA_VT_TEXT; |
395 m_wsValue = wsText; | 395 m_wsValue = wsText; |
396 return TRUE; | 396 return true; |
397 } | 397 } |
398 FX_BOOL CXFA_LocaleValue::SetText(const CFX_WideString& wsText, | 398 bool CXFA_LocaleValue::SetText(const CFX_WideString& wsText, |
399 const CFX_WideString& wsFormat, | 399 const CFX_WideString& wsFormat, |
400 IFX_Locale* pLocale) { | 400 IFX_Locale* pLocale) { |
401 m_dwType = XFA_VT_TEXT; | 401 m_dwType = XFA_VT_TEXT; |
402 return m_bValid = ParsePatternValue(wsText, wsFormat, pLocale); | 402 return m_bValid = ParsePatternValue(wsText, wsFormat, pLocale); |
403 } | 403 } |
404 FX_BOOL CXFA_LocaleValue::SetNum(FX_FLOAT fNum) { | 404 bool CXFA_LocaleValue::SetNum(FX_FLOAT fNum) { |
405 m_dwType = XFA_VT_FLOAT; | 405 m_dwType = XFA_VT_FLOAT; |
406 m_wsValue.Format(L"%.8g", (FX_DOUBLE)fNum); | 406 m_wsValue.Format(L"%.8g", (FX_DOUBLE)fNum); |
407 return TRUE; | 407 return true; |
408 } | 408 } |
409 FX_BOOL CXFA_LocaleValue::SetNum(const CFX_WideString& wsNum, | 409 bool CXFA_LocaleValue::SetNum(const CFX_WideString& wsNum, |
410 const CFX_WideString& wsFormat, | 410 const CFX_WideString& wsFormat, |
411 IFX_Locale* pLocale) { | 411 IFX_Locale* pLocale) { |
412 m_dwType = XFA_VT_FLOAT; | 412 m_dwType = XFA_VT_FLOAT; |
413 return m_bValid = ParsePatternValue(wsNum, wsFormat, pLocale); | 413 return m_bValid = ParsePatternValue(wsNum, wsFormat, pLocale); |
414 } | 414 } |
415 FX_BOOL CXFA_LocaleValue::SetDate(const CFX_Unitime& d) { | 415 bool CXFA_LocaleValue::SetDate(const CFX_Unitime& d) { |
416 m_dwType = XFA_VT_DATE; | 416 m_dwType = XFA_VT_DATE; |
417 m_wsValue.Format(L"%04d-%02d-%02d", d.GetYear(), d.GetMonth(), d.GetDay()); | 417 m_wsValue.Format(L"%04d-%02d-%02d", d.GetYear(), d.GetMonth(), d.GetDay()); |
418 return TRUE; | 418 return true; |
419 } | 419 } |
420 FX_BOOL CXFA_LocaleValue::SetDate(const CFX_WideString& wsDate, | 420 bool CXFA_LocaleValue::SetDate(const CFX_WideString& wsDate, |
421 const CFX_WideString& wsFormat, | 421 const CFX_WideString& wsFormat, |
422 IFX_Locale* pLocale) { | 422 IFX_Locale* pLocale) { |
423 m_dwType = XFA_VT_DATE; | 423 m_dwType = XFA_VT_DATE; |
424 return m_bValid = ParsePatternValue(wsDate, wsFormat, pLocale); | 424 return m_bValid = ParsePatternValue(wsDate, wsFormat, pLocale); |
425 } | 425 } |
426 FX_BOOL CXFA_LocaleValue::SetTime(const CFX_Unitime& t) { | 426 bool CXFA_LocaleValue::SetTime(const CFX_Unitime& t) { |
427 m_dwType = XFA_VT_TIME; | 427 m_dwType = XFA_VT_TIME; |
428 m_wsValue.Format(L"%02d:%02d:%02d", t.GetHour(), t.GetMinute(), | 428 m_wsValue.Format(L"%02d:%02d:%02d", t.GetHour(), t.GetMinute(), |
429 t.GetSecond()); | 429 t.GetSecond()); |
430 if (t.GetMillisecond() > 0) { | 430 if (t.GetMillisecond() > 0) { |
431 CFX_WideString wsTemp; | 431 CFX_WideString wsTemp; |
432 wsTemp.Format(L"%:03d", t.GetMillisecond()); | 432 wsTemp.Format(L"%:03d", t.GetMillisecond()); |
433 m_wsValue += wsTemp; | 433 m_wsValue += wsTemp; |
434 } | 434 } |
435 return TRUE; | 435 return true; |
436 } | 436 } |
437 FX_BOOL CXFA_LocaleValue::SetTime(const CFX_WideString& wsTime, | 437 bool CXFA_LocaleValue::SetTime(const CFX_WideString& wsTime, |
438 const CFX_WideString& wsFormat, | 438 const CFX_WideString& wsFormat, |
439 IFX_Locale* pLocale) { | 439 IFX_Locale* pLocale) { |
440 m_dwType = XFA_VT_TIME; | 440 m_dwType = XFA_VT_TIME; |
441 return m_bValid = ParsePatternValue(wsTime, wsFormat, pLocale); | 441 return m_bValid = ParsePatternValue(wsTime, wsFormat, pLocale); |
442 } | 442 } |
443 FX_BOOL CXFA_LocaleValue::SetDateTime(const CFX_Unitime& dt) { | 443 bool CXFA_LocaleValue::SetDateTime(const CFX_Unitime& dt) { |
444 m_dwType = XFA_VT_DATETIME; | 444 m_dwType = XFA_VT_DATETIME; |
445 m_wsValue.Format(L"%04d-%02d-%02dT%02d:%02d:%02d", dt.GetYear(), | 445 m_wsValue.Format(L"%04d-%02d-%02dT%02d:%02d:%02d", dt.GetYear(), |
446 dt.GetMonth(), dt.GetDay(), dt.GetHour(), dt.GetMinute(), | 446 dt.GetMonth(), dt.GetDay(), dt.GetHour(), dt.GetMinute(), |
447 dt.GetSecond()); | 447 dt.GetSecond()); |
448 if (dt.GetMillisecond() > 0) { | 448 if (dt.GetMillisecond() > 0) { |
449 CFX_WideString wsTemp; | 449 CFX_WideString wsTemp; |
450 wsTemp.Format(L"%:03d", dt.GetMillisecond()); | 450 wsTemp.Format(L"%:03d", dt.GetMillisecond()); |
451 m_wsValue += wsTemp; | 451 m_wsValue += wsTemp; |
452 } | 452 } |
453 return TRUE; | 453 return true; |
454 } | 454 } |
455 FX_BOOL CXFA_LocaleValue::SetDateTime(const CFX_WideString& wsDateTime, | 455 bool CXFA_LocaleValue::SetDateTime(const CFX_WideString& wsDateTime, |
456 const CFX_WideString& wsFormat, | 456 const CFX_WideString& wsFormat, |
457 IFX_Locale* pLocale) { | 457 IFX_Locale* pLocale) { |
458 m_dwType = XFA_VT_DATETIME; | 458 m_dwType = XFA_VT_DATETIME; |
459 return m_bValid = ParsePatternValue(wsDateTime, wsFormat, pLocale); | 459 return m_bValid = ParsePatternValue(wsDateTime, wsFormat, pLocale); |
460 } | 460 } |
461 FX_BOOL CXFA_LocaleValue::FormatPatterns(CFX_WideString& wsResult, | 461 bool CXFA_LocaleValue::FormatPatterns(CFX_WideString& wsResult, |
462 const CFX_WideString& wsFormat, | 462 const CFX_WideString& wsFormat, |
463 IFX_Locale* pLocale, | 463 IFX_Locale* pLocale, |
464 XFA_VALUEPICTURE eValueType) const { | 464 XFA_VALUEPICTURE eValueType) const { |
465 wsResult.clear(); | 465 wsResult.clear(); |
466 FX_BOOL bRet = FALSE; | 466 bool bRet = false; |
467 | 467 |
468 CFX_FormatString* pFormat = nullptr; | 468 CFX_FormatString* pFormat = nullptr; |
469 if (m_pLocaleMgr) | 469 if (m_pLocaleMgr) |
470 pFormat = new CFX_FormatString(m_pLocaleMgr, FALSE); | 470 pFormat = new CFX_FormatString(m_pLocaleMgr, false); |
471 | 471 |
472 CFX_WideStringArray wsPatterns; | 472 CFX_WideStringArray wsPatterns; |
473 pFormat->SplitFormatString(wsFormat, wsPatterns); | 473 pFormat->SplitFormatString(wsFormat, wsPatterns); |
474 int32_t iCount = wsPatterns.GetSize(); | 474 int32_t iCount = wsPatterns.GetSize(); |
475 for (int32_t i = 0; i < iCount; i++) { | 475 for (int32_t i = 0; i < iCount; i++) { |
476 bRet = FormatSinglePattern(wsResult, wsPatterns[i], pLocale, eValueType); | 476 bRet = FormatSinglePattern(wsResult, wsPatterns[i], pLocale, eValueType); |
477 if (bRet) { | 477 if (bRet) { |
478 break; | 478 break; |
479 } | 479 } |
480 } | 480 } |
481 pFormat->Release(); | 481 pFormat->Release(); |
482 return bRet; | 482 return bRet; |
483 } | 483 } |
484 FX_BOOL CXFA_LocaleValue::FormatSinglePattern( | 484 bool CXFA_LocaleValue::FormatSinglePattern(CFX_WideString& wsResult, |
485 CFX_WideString& wsResult, | 485 const CFX_WideString& wsFormat, |
486 const CFX_WideString& wsFormat, | 486 IFX_Locale* pLocale, |
487 IFX_Locale* pLocale, | 487 XFA_VALUEPICTURE eValueType) const { |
488 XFA_VALUEPICTURE eValueType) const { | |
489 IFX_Locale* locale = m_pLocaleMgr->GetDefLocale(); | 488 IFX_Locale* locale = m_pLocaleMgr->GetDefLocale(); |
490 if (pLocale) { | 489 if (pLocale) { |
491 m_pLocaleMgr->SetDefLocale(pLocale); | 490 m_pLocaleMgr->SetDefLocale(pLocale); |
492 } | 491 } |
493 wsResult.clear(); | 492 wsResult.clear(); |
494 FX_BOOL bRet = FALSE; | 493 bool bRet = false; |
495 | 494 |
496 CFX_FormatString* pFormat = nullptr; | 495 CFX_FormatString* pFormat = nullptr; |
497 if (m_pLocaleMgr) | 496 if (m_pLocaleMgr) |
498 pFormat = new CFX_FormatString(m_pLocaleMgr, FALSE); | 497 pFormat = new CFX_FormatString(m_pLocaleMgr, false); |
499 | 498 |
500 FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat); | 499 FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat); |
501 eCategory = XFA_ValugeCategory(eCategory, m_dwType); | 500 eCategory = XFA_ValugeCategory(eCategory, m_dwType); |
502 switch (eCategory) { | 501 switch (eCategory) { |
503 case FX_LOCALECATEGORY_Null: | 502 case FX_LOCALECATEGORY_Null: |
504 if (m_wsValue.IsEmpty()) { | 503 if (m_wsValue.IsEmpty()) { |
505 bRet = pFormat->FormatNull(wsFormat, wsResult); | 504 bRet = pFormat->FormatNull(wsFormat, wsResult); |
506 } | 505 } |
507 break; | 506 break; |
508 case FX_LOCALECATEGORY_Zero: | 507 case FX_LOCALECATEGORY_Zero: |
(...skipping 14 matching lines...) Expand all Loading... |
523 case FX_LOCALECATEGORY_Time: | 522 case FX_LOCALECATEGORY_Time: |
524 bRet = pFormat->FormatDateTime(m_wsValue, wsFormat, wsResult, | 523 bRet = pFormat->FormatDateTime(m_wsValue, wsFormat, wsResult, |
525 FX_DATETIMETYPE_Time); | 524 FX_DATETIMETYPE_Time); |
526 break; | 525 break; |
527 case FX_LOCALECATEGORY_DateTime: | 526 case FX_LOCALECATEGORY_DateTime: |
528 bRet = pFormat->FormatDateTime(m_wsValue, wsFormat, wsResult, | 527 bRet = pFormat->FormatDateTime(m_wsValue, wsFormat, wsResult, |
529 FX_DATETIMETYPE_DateTime); | 528 FX_DATETIMETYPE_DateTime); |
530 break; | 529 break; |
531 default: | 530 default: |
532 wsResult = m_wsValue; | 531 wsResult = m_wsValue; |
533 bRet = TRUE; | 532 bRet = true; |
534 } | 533 } |
535 pFormat->Release(); | 534 pFormat->Release(); |
536 if (!bRet && (eCategory != FX_LOCALECATEGORY_Num || | 535 if (!bRet && (eCategory != FX_LOCALECATEGORY_Num || |
537 eValueType != XFA_VALUEPICTURE_Display)) { | 536 eValueType != XFA_VALUEPICTURE_Display)) { |
538 wsResult = m_wsValue; | 537 wsResult = m_wsValue; |
539 } | 538 } |
540 if (pLocale) { | 539 if (pLocale) { |
541 m_pLocaleMgr->SetDefLocale(locale); | 540 m_pLocaleMgr->SetDefLocale(locale); |
542 } | 541 } |
543 return bRet; | 542 return bRet; |
544 } | 543 } |
545 static FX_BOOL XFA_ValueSplitDateTime(const CFX_WideString& wsDateTime, | 544 static bool XFA_ValueSplitDateTime(const CFX_WideString& wsDateTime, |
546 CFX_WideString& wsDate, | 545 CFX_WideString& wsDate, |
547 CFX_WideString& wsTime) { | 546 CFX_WideString& wsTime) { |
548 wsDate = L""; | 547 wsDate = L""; |
549 wsTime = L""; | 548 wsTime = L""; |
550 if (wsDateTime.IsEmpty()) { | 549 if (wsDateTime.IsEmpty()) { |
551 return FALSE; | 550 return false; |
552 } | 551 } |
553 int nSplitIndex = -1; | 552 int nSplitIndex = -1; |
554 nSplitIndex = wsDateTime.Find('T'); | 553 nSplitIndex = wsDateTime.Find('T'); |
555 if (nSplitIndex < 0) { | 554 if (nSplitIndex < 0) { |
556 nSplitIndex = wsDateTime.Find(' '); | 555 nSplitIndex = wsDateTime.Find(' '); |
557 } | 556 } |
558 if (nSplitIndex < 0) { | 557 if (nSplitIndex < 0) { |
559 return FALSE; | 558 return false; |
560 } | 559 } |
561 wsDate = wsDateTime.Left(nSplitIndex); | 560 wsDate = wsDateTime.Left(nSplitIndex); |
562 wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex - 1); | 561 wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex - 1); |
563 return TRUE; | 562 return true; |
564 } | 563 } |
565 FX_BOOL CXFA_LocaleValue::ValidateCanonicalValue(const CFX_WideString& wsValue, | 564 bool CXFA_LocaleValue::ValidateCanonicalValue(const CFX_WideString& wsValue, |
566 uint32_t dwVType) { | 565 uint32_t dwVType) { |
567 if (wsValue.IsEmpty()) { | 566 if (wsValue.IsEmpty()) { |
568 return TRUE; | 567 return true; |
569 } | 568 } |
570 CFX_Unitime dt; | 569 CFX_Unitime dt; |
571 switch (dwVType) { | 570 switch (dwVType) { |
572 case XFA_VT_DATE: { | 571 case XFA_VT_DATE: { |
573 if (ValidateCanonicalDate(wsValue, dt)) { | 572 if (ValidateCanonicalDate(wsValue, dt)) { |
574 return TRUE; | 573 return true; |
575 } | 574 } |
576 CFX_WideString wsDate, wsTime; | 575 CFX_WideString wsDate, wsTime; |
577 if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) && | 576 if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) && |
578 ValidateCanonicalDate(wsDate, dt)) { | 577 ValidateCanonicalDate(wsDate, dt)) { |
579 return TRUE; | 578 return true; |
580 } | 579 } |
581 return FALSE; | 580 return false; |
582 } | 581 } |
583 case XFA_VT_TIME: { | 582 case XFA_VT_TIME: { |
584 if (ValidateCanonicalTime(wsValue)) { | 583 if (ValidateCanonicalTime(wsValue)) { |
585 return TRUE; | 584 return true; |
586 } | 585 } |
587 CFX_WideString wsDate, wsTime; | 586 CFX_WideString wsDate, wsTime; |
588 if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) && | 587 if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) && |
589 ValidateCanonicalTime(wsTime)) { | 588 ValidateCanonicalTime(wsTime)) { |
590 return TRUE; | 589 return true; |
591 } | 590 } |
592 return FALSE; | 591 return false; |
593 } | 592 } |
594 case XFA_VT_DATETIME: { | 593 case XFA_VT_DATETIME: { |
595 CFX_WideString wsDate, wsTime; | 594 CFX_WideString wsDate, wsTime; |
596 if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) && | 595 if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) && |
597 ValidateCanonicalDate(wsDate, dt) && ValidateCanonicalTime(wsTime)) { | 596 ValidateCanonicalDate(wsDate, dt) && ValidateCanonicalTime(wsTime)) { |
598 return TRUE; | 597 return true; |
599 } | 598 } |
600 } break; | 599 } break; |
601 } | 600 } |
602 return TRUE; | 601 return true; |
603 } | 602 } |
604 FX_BOOL CXFA_LocaleValue::ValidateCanonicalDate(const CFX_WideString& wsDate, | 603 bool CXFA_LocaleValue::ValidateCanonicalDate(const CFX_WideString& wsDate, |
605 CFX_Unitime& unDate) { | 604 CFX_Unitime& unDate) { |
606 const uint16_t LastDay[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; | 605 const uint16_t LastDay[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; |
607 const uint16_t wCountY = 4, wCountM = 2, wCountD = 2; | 606 const uint16_t wCountY = 4, wCountM = 2, wCountD = 2; |
608 int nLen = wsDate.GetLength(); | 607 int nLen = wsDate.GetLength(); |
609 if (nLen < wCountY || nLen > wCountY + wCountM + wCountD + 2) { | 608 if (nLen < wCountY || nLen > wCountY + wCountM + wCountD + 2) { |
610 return FALSE; | 609 return false; |
611 } | 610 } |
612 const bool bSymbol = wsDate.Find(0x2D) != -1; | 611 const bool bSymbol = wsDate.Find(0x2D) != -1; |
613 uint16_t wYear = 0; | 612 uint16_t wYear = 0; |
614 uint16_t wMonth = 0; | 613 uint16_t wMonth = 0; |
615 uint16_t wDay = 0; | 614 uint16_t wDay = 0; |
616 const FX_WCHAR* pDate = wsDate.c_str(); | 615 const FX_WCHAR* pDate = wsDate.c_str(); |
617 int nIndex = 0, nStart = 0; | 616 int nIndex = 0, nStart = 0; |
618 while (pDate[nIndex] != '\0' && nIndex < wCountY) { | 617 while (pDate[nIndex] != '\0' && nIndex < wCountY) { |
619 if (!FXSYS_isDecimalDigit(pDate[nIndex])) { | 618 if (!FXSYS_isDecimalDigit(pDate[nIndex])) { |
620 return FALSE; | 619 return false; |
621 } | 620 } |
622 wYear = (pDate[nIndex] - '0') + wYear * 10; | 621 wYear = (pDate[nIndex] - '0') + wYear * 10; |
623 nIndex++; | 622 nIndex++; |
624 } | 623 } |
625 if (bSymbol) { | 624 if (bSymbol) { |
626 if (pDate[nIndex] != 0x2D) { | 625 if (pDate[nIndex] != 0x2D) { |
627 return FALSE; | 626 return false; |
628 } | 627 } |
629 nIndex++; | 628 nIndex++; |
630 } | 629 } |
631 nStart = nIndex; | 630 nStart = nIndex; |
632 while (pDate[nIndex] != '\0' && nIndex - nStart < wCountM && nIndex < nLen) { | 631 while (pDate[nIndex] != '\0' && nIndex - nStart < wCountM && nIndex < nLen) { |
633 if (!FXSYS_isDecimalDigit(pDate[nIndex])) { | 632 if (!FXSYS_isDecimalDigit(pDate[nIndex])) { |
634 return FALSE; | 633 return false; |
635 } | 634 } |
636 wMonth = (pDate[nIndex] - '0') + wMonth * 10; | 635 wMonth = (pDate[nIndex] - '0') + wMonth * 10; |
637 nIndex++; | 636 nIndex++; |
638 } | 637 } |
639 if (bSymbol) { | 638 if (bSymbol) { |
640 if (pDate[nIndex] != 0x2D) { | 639 if (pDate[nIndex] != 0x2D) { |
641 return FALSE; | 640 return false; |
642 } | 641 } |
643 nIndex++; | 642 nIndex++; |
644 } | 643 } |
645 nStart = nIndex; | 644 nStart = nIndex; |
646 while (pDate[nIndex] != '\0' && nIndex - nStart < wCountD && nIndex < nLen) { | 645 while (pDate[nIndex] != '\0' && nIndex - nStart < wCountD && nIndex < nLen) { |
647 if (!FXSYS_isDecimalDigit(pDate[nIndex])) { | 646 if (!FXSYS_isDecimalDigit(pDate[nIndex])) { |
648 return FALSE; | 647 return false; |
649 } | 648 } |
650 wDay = (pDate[nIndex] - '0') + wDay * 10; | 649 wDay = (pDate[nIndex] - '0') + wDay * 10; |
651 nIndex++; | 650 nIndex++; |
652 } | 651 } |
653 if (nIndex != nLen) { | 652 if (nIndex != nLen) { |
654 return FALSE; | 653 return false; |
655 } | 654 } |
656 if (wYear < 1900 || wYear > 2029) { | 655 if (wYear < 1900 || wYear > 2029) { |
657 return FALSE; | 656 return false; |
658 } | 657 } |
659 if (wMonth < 1 || wMonth > 12) { | 658 if (wMonth < 1 || wMonth > 12) { |
660 if (wMonth == 0 && nLen == wCountY) { | 659 if (wMonth == 0 && nLen == wCountY) { |
661 return TRUE; | 660 return true; |
662 } | 661 } |
663 return FALSE; | 662 return false; |
664 } | 663 } |
665 if (wDay < 1) { | 664 if (wDay < 1) { |
666 if (wDay == 0 && (nLen == wCountY + wCountM)) { | 665 if (wDay == 0 && (nLen == wCountY + wCountM)) { |
667 return TRUE; | 666 return true; |
668 } | 667 } |
669 return FALSE; | 668 return false; |
670 } | 669 } |
671 if (wMonth == 2) { | 670 if (wMonth == 2) { |
672 if (wYear % 400 == 0 || (wYear % 100 != 0 && wYear % 4 == 0)) { | 671 if (wYear % 400 == 0 || (wYear % 100 != 0 && wYear % 4 == 0)) { |
673 if (wDay > 29) { | 672 if (wDay > 29) { |
674 return FALSE; | 673 return false; |
675 } | 674 } |
676 } else { | 675 } else { |
677 if (wDay > 28) { | 676 if (wDay > 28) { |
678 return FALSE; | 677 return false; |
679 } | 678 } |
680 } | 679 } |
681 } else if (wDay > LastDay[wMonth - 1]) { | 680 } else if (wDay > LastDay[wMonth - 1]) { |
682 return FALSE; | 681 return false; |
683 } | 682 } |
684 CFX_Unitime ut; | 683 CFX_Unitime ut; |
685 ut.Set(wYear, static_cast<uint8_t>(wMonth), static_cast<uint8_t>(wDay)); | 684 ut.Set(wYear, static_cast<uint8_t>(wMonth), static_cast<uint8_t>(wDay)); |
686 unDate = unDate + ut; | 685 unDate = unDate + ut; |
687 return TRUE; | 686 return true; |
688 } | 687 } |
689 FX_BOOL CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) { | 688 bool CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) { |
690 int nLen = wsTime.GetLength(); | 689 int nLen = wsTime.GetLength(); |
691 if (nLen < 2) | 690 if (nLen < 2) |
692 return FALSE; | 691 return false; |
693 const uint16_t wCountH = 2; | 692 const uint16_t wCountH = 2; |
694 const uint16_t wCountM = 2; | 693 const uint16_t wCountM = 2; |
695 const uint16_t wCountS = 2; | 694 const uint16_t wCountS = 2; |
696 const uint16_t wCountF = 3; | 695 const uint16_t wCountF = 3; |
697 const bool bSymbol = wsTime.Find(':') != -1; | 696 const bool bSymbol = wsTime.Find(':') != -1; |
698 uint16_t wHour = 0; | 697 uint16_t wHour = 0; |
699 uint16_t wMinute = 0; | 698 uint16_t wMinute = 0; |
700 uint16_t wSecond = 0; | 699 uint16_t wSecond = 0; |
701 uint16_t wFraction = 0; | 700 uint16_t wFraction = 0; |
702 const FX_WCHAR* pTime = wsTime.c_str(); | 701 const FX_WCHAR* pTime = wsTime.c_str(); |
703 int nIndex = 0; | 702 int nIndex = 0; |
704 int nStart = 0; | 703 int nStart = 0; |
705 while (nIndex - nStart < wCountH && pTime[nIndex]) { | 704 while (nIndex - nStart < wCountH && pTime[nIndex]) { |
706 if (!FXSYS_isDecimalDigit(pTime[nIndex])) | 705 if (!FXSYS_isDecimalDigit(pTime[nIndex])) |
707 return FALSE; | 706 return false; |
708 wHour = pTime[nIndex] - '0' + wHour * 10; | 707 wHour = pTime[nIndex] - '0' + wHour * 10; |
709 nIndex++; | 708 nIndex++; |
710 } | 709 } |
711 if (bSymbol) { | 710 if (bSymbol) { |
712 if (nIndex < nLen && pTime[nIndex] != ':') | 711 if (nIndex < nLen && pTime[nIndex] != ':') |
713 return FALSE; | 712 return false; |
714 nIndex++; | 713 nIndex++; |
715 } | 714 } |
716 nStart = nIndex; | 715 nStart = nIndex; |
717 while (nIndex - nStart < wCountM && nIndex < nLen && pTime[nIndex]) { | 716 while (nIndex - nStart < wCountM && nIndex < nLen && pTime[nIndex]) { |
718 if (!FXSYS_isDecimalDigit(pTime[nIndex])) | 717 if (!FXSYS_isDecimalDigit(pTime[nIndex])) |
719 return FALSE; | 718 return false; |
720 wMinute = pTime[nIndex] - '0' + wMinute * 10; | 719 wMinute = pTime[nIndex] - '0' + wMinute * 10; |
721 nIndex++; | 720 nIndex++; |
722 } | 721 } |
723 if (bSymbol) { | 722 if (bSymbol) { |
724 if (nIndex < nLen && pTime[nIndex] != ':') | 723 if (nIndex < nLen && pTime[nIndex] != ':') |
725 return FALSE; | 724 return false; |
726 nIndex++; | 725 nIndex++; |
727 } | 726 } |
728 nStart = nIndex; | 727 nStart = nIndex; |
729 while (nIndex - nStart < wCountS && nIndex < nLen && pTime[nIndex]) { | 728 while (nIndex - nStart < wCountS && nIndex < nLen && pTime[nIndex]) { |
730 if (!FXSYS_isDecimalDigit(pTime[nIndex])) | 729 if (!FXSYS_isDecimalDigit(pTime[nIndex])) |
731 return FALSE; | 730 return false; |
732 wSecond = pTime[nIndex] - '0' + wSecond * 10; | 731 wSecond = pTime[nIndex] - '0' + wSecond * 10; |
733 nIndex++; | 732 nIndex++; |
734 } | 733 } |
735 if (wsTime.Find('.') > 0) { | 734 if (wsTime.Find('.') > 0) { |
736 if (pTime[nIndex] != '.') | 735 if (pTime[nIndex] != '.') |
737 return FALSE; | 736 return false; |
738 nIndex++; | 737 nIndex++; |
739 nStart = nIndex; | 738 nStart = nIndex; |
740 while (nIndex - nStart < wCountF && nIndex < nLen && pTime[nIndex]) { | 739 while (nIndex - nStart < wCountF && nIndex < nLen && pTime[nIndex]) { |
741 if (!FXSYS_isDecimalDigit(pTime[nIndex])) | 740 if (!FXSYS_isDecimalDigit(pTime[nIndex])) |
742 return FALSE; | 741 return false; |
743 wFraction = pTime[nIndex] - '0' + wFraction * 10; | 742 wFraction = pTime[nIndex] - '0' + wFraction * 10; |
744 nIndex++; | 743 nIndex++; |
745 } | 744 } |
746 } | 745 } |
747 if (nIndex < nLen) { | 746 if (nIndex < nLen) { |
748 if (pTime[nIndex] == 'Z') { | 747 if (pTime[nIndex] == 'Z') { |
749 nIndex++; | 748 nIndex++; |
750 } else if (pTime[nIndex] == '-' || pTime[nIndex] == '+') { | 749 } else if (pTime[nIndex] == '-' || pTime[nIndex] == '+') { |
751 int16_t nOffsetH = 0; | 750 int16_t nOffsetH = 0; |
752 int16_t nOffsetM = 0; | 751 int16_t nOffsetM = 0; |
753 nIndex++; | 752 nIndex++; |
754 nStart = nIndex; | 753 nStart = nIndex; |
755 while (nIndex - nStart < wCountH && nIndex < nLen && pTime[nIndex]) { | 754 while (nIndex - nStart < wCountH && nIndex < nLen && pTime[nIndex]) { |
756 if (!FXSYS_isDecimalDigit(pTime[nIndex])) | 755 if (!FXSYS_isDecimalDigit(pTime[nIndex])) |
757 return FALSE; | 756 return false; |
758 nOffsetH = pTime[nIndex] - '0' + nOffsetH * 10; | 757 nOffsetH = pTime[nIndex] - '0' + nOffsetH * 10; |
759 nIndex++; | 758 nIndex++; |
760 } | 759 } |
761 if (bSymbol) { | 760 if (bSymbol) { |
762 if (nIndex < nLen && pTime[nIndex] != ':') | 761 if (nIndex < nLen && pTime[nIndex] != ':') |
763 return FALSE; | 762 return false; |
764 nIndex++; | 763 nIndex++; |
765 } | 764 } |
766 nStart = nIndex; | 765 nStart = nIndex; |
767 while (nIndex - nStart < wCountM && nIndex < nLen && pTime[nIndex]) { | 766 while (nIndex - nStart < wCountM && nIndex < nLen && pTime[nIndex]) { |
768 if (!FXSYS_isDecimalDigit(pTime[nIndex])) | 767 if (!FXSYS_isDecimalDigit(pTime[nIndex])) |
769 return FALSE; | 768 return false; |
770 nOffsetM = pTime[nIndex] - '0' + nOffsetM * 10; | 769 nOffsetM = pTime[nIndex] - '0' + nOffsetM * 10; |
771 nIndex++; | 770 nIndex++; |
772 } | 771 } |
773 if (nOffsetH > 12 || nOffsetM >= 60) | 772 if (nOffsetH > 12 || nOffsetM >= 60) |
774 return FALSE; | 773 return false; |
775 } | 774 } |
776 } | 775 } |
777 return nIndex == nLen && wHour < 24 && wMinute < 60 && wSecond < 60 && | 776 return nIndex == nLen && wHour < 24 && wMinute < 60 && wSecond < 60 && |
778 wFraction <= 999; | 777 wFraction <= 999; |
779 } | 778 } |
780 FX_BOOL CXFA_LocaleValue::ValidateCanonicalDateTime( | 779 bool CXFA_LocaleValue::ValidateCanonicalDateTime( |
781 const CFX_WideString& wsDateTime) { | 780 const CFX_WideString& wsDateTime) { |
782 CFX_WideString wsDate, wsTime; | 781 CFX_WideString wsDate, wsTime; |
783 if (wsDateTime.IsEmpty()) { | 782 if (wsDateTime.IsEmpty()) { |
784 return FALSE; | 783 return false; |
785 } | 784 } |
786 int nSplitIndex = -1; | 785 int nSplitIndex = -1; |
787 nSplitIndex = wsDateTime.Find('T'); | 786 nSplitIndex = wsDateTime.Find('T'); |
788 if (nSplitIndex < 0) { | 787 if (nSplitIndex < 0) { |
789 nSplitIndex = wsDateTime.Find(' '); | 788 nSplitIndex = wsDateTime.Find(' '); |
790 } | 789 } |
791 if (nSplitIndex < 0) { | 790 if (nSplitIndex < 0) { |
792 return FALSE; | 791 return false; |
793 } | 792 } |
794 wsDate = wsDateTime.Left(nSplitIndex); | 793 wsDate = wsDateTime.Left(nSplitIndex); |
795 wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex - 1); | 794 wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex - 1); |
796 CFX_Unitime dt; | 795 CFX_Unitime dt; |
797 return ValidateCanonicalDate(wsDate, dt) && ValidateCanonicalTime(wsTime); | 796 return ValidateCanonicalDate(wsDate, dt) && ValidateCanonicalTime(wsTime); |
798 } | 797 } |
799 FX_BOOL CXFA_LocaleValue::ParsePatternValue(const CFX_WideString& wsValue, | 798 bool CXFA_LocaleValue::ParsePatternValue(const CFX_WideString& wsValue, |
800 const CFX_WideString& wsPattern, | 799 const CFX_WideString& wsPattern, |
801 IFX_Locale* pLocale) { | 800 IFX_Locale* pLocale) { |
802 IFX_Locale* locale = m_pLocaleMgr->GetDefLocale(); | 801 IFX_Locale* locale = m_pLocaleMgr->GetDefLocale(); |
803 if (pLocale) { | 802 if (pLocale) { |
804 m_pLocaleMgr->SetDefLocale(pLocale); | 803 m_pLocaleMgr->SetDefLocale(pLocale); |
805 } | 804 } |
806 | 805 |
807 CFX_FormatString* pFormat = nullptr; | 806 CFX_FormatString* pFormat = nullptr; |
808 if (m_pLocaleMgr) | 807 if (m_pLocaleMgr) |
809 pFormat = new CFX_FormatString(m_pLocaleMgr, FALSE); | 808 pFormat = new CFX_FormatString(m_pLocaleMgr, false); |
810 | 809 |
811 CFX_WideStringArray wsPatterns; | 810 CFX_WideStringArray wsPatterns; |
812 pFormat->SplitFormatString(wsPattern, wsPatterns); | 811 pFormat->SplitFormatString(wsPattern, wsPatterns); |
813 FX_BOOL bRet = FALSE; | 812 bool bRet = false; |
814 int32_t iCount = wsPatterns.GetSize(); | 813 int32_t iCount = wsPatterns.GetSize(); |
815 for (int32_t i = 0; i < iCount && !bRet; i++) { | 814 for (int32_t i = 0; i < iCount && !bRet; i++) { |
816 CFX_WideString wsFormat = wsPatterns[i]; | 815 CFX_WideString wsFormat = wsPatterns[i]; |
817 FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat); | 816 FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat); |
818 eCategory = XFA_ValugeCategory(eCategory, m_dwType); | 817 eCategory = XFA_ValugeCategory(eCategory, m_dwType); |
819 switch (eCategory) { | 818 switch (eCategory) { |
820 case FX_LOCALECATEGORY_Null: | 819 case FX_LOCALECATEGORY_Null: |
821 bRet = pFormat->ParseNull(wsValue, wsFormat); | 820 bRet = pFormat->ParseNull(wsValue, wsFormat); |
822 if (bRet) { | 821 if (bRet) { |
823 m_wsValue.clear(); | 822 m_wsValue.clear(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 CFX_Unitime dt; | 864 CFX_Unitime dt; |
866 bRet = pFormat->ParseDateTime(wsValue, wsFormat, | 865 bRet = pFormat->ParseDateTime(wsValue, wsFormat, |
867 FX_DATETIMETYPE_DateTime, dt); | 866 FX_DATETIMETYPE_DateTime, dt); |
868 if (bRet) { | 867 if (bRet) { |
869 SetDateTime(dt); | 868 SetDateTime(dt); |
870 } | 869 } |
871 break; | 870 break; |
872 } | 871 } |
873 default: | 872 default: |
874 m_wsValue = wsValue; | 873 m_wsValue = wsValue; |
875 bRet = TRUE; | 874 bRet = true; |
876 break; | 875 break; |
877 } | 876 } |
878 } | 877 } |
879 if (!bRet) { | 878 if (!bRet) { |
880 m_wsValue = wsValue; | 879 m_wsValue = wsValue; |
881 } | 880 } |
882 pFormat->Release(); | 881 pFormat->Release(); |
883 if (pLocale) { | 882 if (pLocale) { |
884 m_pLocaleMgr->SetDefLocale(locale); | 883 m_pLocaleMgr->SetDefLocale(locale); |
885 } | 884 } |
886 return bRet; | 885 return bRet; |
887 } | 886 } |
888 void CXFA_LocaleValue::GetNumbericFormat(CFX_WideString& wsFormat, | 887 void CXFA_LocaleValue::GetNumbericFormat(CFX_WideString& wsFormat, |
889 int32_t nIntLen, | 888 int32_t nIntLen, |
890 int32_t nDecLen, | 889 int32_t nDecLen, |
891 FX_BOOL bSign) { | 890 bool bSign) { |
892 ASSERT(wsFormat.IsEmpty()); | 891 ASSERT(wsFormat.IsEmpty()); |
893 ASSERT(nIntLen >= -1 && nDecLen >= -1); | 892 ASSERT(nIntLen >= -1 && nDecLen >= -1); |
894 int32_t nTotalLen = (nIntLen >= 0 ? nIntLen : 2) + (bSign ? 1 : 0) + | 893 int32_t nTotalLen = (nIntLen >= 0 ? nIntLen : 2) + (bSign ? 1 : 0) + |
895 (nDecLen >= 0 ? nDecLen : 2) + (nDecLen == 0 ? 0 : 1); | 894 (nDecLen >= 0 ? nDecLen : 2) + (nDecLen == 0 ? 0 : 1); |
896 FX_WCHAR* lpBuf = wsFormat.GetBuffer(nTotalLen); | 895 FX_WCHAR* lpBuf = wsFormat.GetBuffer(nTotalLen); |
897 int32_t nPos = 0; | 896 int32_t nPos = 0; |
898 if (bSign) { | 897 if (bSign) { |
899 lpBuf[nPos++] = L's'; | 898 lpBuf[nPos++] = L's'; |
900 } | 899 } |
901 if (nIntLen == -1) { | 900 if (nIntLen == -1) { |
(...skipping 12 matching lines...) Expand all Loading... |
914 lpBuf[nPos++] = L'z'; | 913 lpBuf[nPos++] = L'z'; |
915 lpBuf[nPos++] = L'*'; | 914 lpBuf[nPos++] = L'*'; |
916 } else { | 915 } else { |
917 while (nDecLen) { | 916 while (nDecLen) { |
918 lpBuf[nPos++] = L'z'; | 917 lpBuf[nPos++] = L'z'; |
919 nDecLen--; | 918 nDecLen--; |
920 } | 919 } |
921 } | 920 } |
922 wsFormat.ReleaseBuffer(nTotalLen); | 921 wsFormat.ReleaseBuffer(nTotalLen); |
923 } | 922 } |
924 FX_BOOL CXFA_LocaleValue::ValidateNumericTemp(CFX_WideString& wsNumeric, | 923 bool CXFA_LocaleValue::ValidateNumericTemp(CFX_WideString& wsNumeric, |
925 CFX_WideString& wsFormat, | 924 CFX_WideString& wsFormat, |
926 IFX_Locale* pLocale, | 925 IFX_Locale* pLocale, |
927 int32_t* pos) { | 926 int32_t* pos) { |
928 if (wsFormat.IsEmpty() || wsNumeric.IsEmpty()) { | 927 if (wsFormat.IsEmpty() || wsNumeric.IsEmpty()) { |
929 return TRUE; | 928 return true; |
930 } | 929 } |
931 const FX_WCHAR* pNum = wsNumeric.c_str(); | 930 const FX_WCHAR* pNum = wsNumeric.c_str(); |
932 const FX_WCHAR* pFmt = wsFormat.c_str(); | 931 const FX_WCHAR* pFmt = wsFormat.c_str(); |
933 int32_t n = 0, nf = 0; | 932 int32_t n = 0, nf = 0; |
934 FX_WCHAR c = pNum[n]; | 933 FX_WCHAR c = pNum[n]; |
935 FX_WCHAR cf = pFmt[nf]; | 934 FX_WCHAR cf = pFmt[nf]; |
936 if (cf == L's') { | 935 if (cf == L's') { |
937 if (c == L'-' || c == L'+') { | 936 if (c == L'-' || c == L'+') { |
938 ++n; | 937 ++n; |
939 } | 938 } |
940 ++nf; | 939 ++nf; |
941 } | 940 } |
942 FX_BOOL bLimit = TRUE; | 941 bool bLimit = true; |
943 int32_t nCount = wsNumeric.GetLength(); | 942 int32_t nCount = wsNumeric.GetLength(); |
944 int32_t nCountFmt = wsFormat.GetLength(); | 943 int32_t nCountFmt = wsFormat.GetLength(); |
945 while (n < nCount && (bLimit ? nf < nCountFmt : TRUE) && | 944 while (n < nCount && (bLimit ? nf < nCountFmt : true) && |
946 FXSYS_isDecimalDigit(c = pNum[n])) { | 945 FXSYS_isDecimalDigit(c = pNum[n])) { |
947 if (bLimit == TRUE) { | 946 if (bLimit == true) { |
948 if ((cf = pFmt[nf]) == L'*') { | 947 if ((cf = pFmt[nf]) == L'*') { |
949 bLimit = FALSE; | 948 bLimit = false; |
950 } else if (cf == L'z') { | 949 } else if (cf == L'z') { |
951 nf++; | 950 nf++; |
952 } else { | 951 } else { |
953 return FALSE; | 952 return false; |
954 } | 953 } |
955 } | 954 } |
956 n++; | 955 n++; |
957 } | 956 } |
958 if (n == nCount) { | 957 if (n == nCount) { |
959 return TRUE; | 958 return true; |
960 } | 959 } |
961 if (nf == nCountFmt) { | 960 if (nf == nCountFmt) { |
962 return FALSE; | 961 return false; |
963 } | 962 } |
964 while (nf < nCountFmt && (cf = pFmt[nf]) != L'.') { | 963 while (nf < nCountFmt && (cf = pFmt[nf]) != L'.') { |
965 ASSERT(cf == L'z' || cf == L'*'); | 964 ASSERT(cf == L'z' || cf == L'*'); |
966 ++nf; | 965 ++nf; |
967 } | 966 } |
968 CFX_WideString wsDecimalSymbol; | 967 CFX_WideString wsDecimalSymbol; |
969 if (pLocale) { | 968 if (pLocale) { |
970 pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal, wsDecimalSymbol); | 969 pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal, wsDecimalSymbol); |
971 } else { | 970 } else { |
972 wsDecimalSymbol = CFX_WideString(L'.'); | 971 wsDecimalSymbol = CFX_WideString(L'.'); |
973 } | 972 } |
974 if (pFmt[nf] != L'.') { | 973 if (pFmt[nf] != L'.') { |
975 return FALSE; | 974 return false; |
976 } | 975 } |
977 if (wsDecimalSymbol != CFX_WideStringC(c) && c != L'.') { | 976 if (wsDecimalSymbol != CFX_WideStringC(c) && c != L'.') { |
978 return FALSE; | 977 return false; |
979 } | 978 } |
980 ++nf; | 979 ++nf; |
981 ++n; | 980 ++n; |
982 bLimit = TRUE; | 981 bLimit = true; |
983 while (n < nCount && (bLimit ? nf < nCountFmt : TRUE) && | 982 while (n < nCount && (bLimit ? nf < nCountFmt : true) && |
984 FXSYS_isDecimalDigit(c = pNum[n])) { | 983 FXSYS_isDecimalDigit(c = pNum[n])) { |
985 if (bLimit == TRUE) { | 984 if (bLimit == true) { |
986 if ((cf = pFmt[nf]) == L'*') { | 985 if ((cf = pFmt[nf]) == L'*') { |
987 bLimit = FALSE; | 986 bLimit = false; |
988 } else if (cf == L'z') { | 987 } else if (cf == L'z') { |
989 nf++; | 988 nf++; |
990 } else { | 989 } else { |
991 return FALSE; | 990 return false; |
992 } | 991 } |
993 } | 992 } |
994 n++; | 993 n++; |
995 } | 994 } |
996 return n == nCount; | 995 return n == nCount; |
997 } | 996 } |
OLD | NEW |