| 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 "xfa/fxfa/fm2js/xfa_fm2jsapi.h" | 9 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" |
| 10 #include "xfa/fxfa/parser/xfa_docdata.h" | 10 #include "xfa/fxfa/parser/xfa_docdata.h" |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) && | 584 if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) && |
| 585 ValidateCanonicalDate(wsDate, dt) && ValidateCanonicalTime(wsTime)) { | 585 ValidateCanonicalDate(wsDate, dt) && ValidateCanonicalTime(wsTime)) { |
| 586 return TRUE; | 586 return TRUE; |
| 587 } | 587 } |
| 588 } break; | 588 } break; |
| 589 } | 589 } |
| 590 return TRUE; | 590 return TRUE; |
| 591 } | 591 } |
| 592 FX_BOOL CXFA_LocaleValue::ValidateCanonicalDate(const CFX_WideString& wsDate, | 592 FX_BOOL CXFA_LocaleValue::ValidateCanonicalDate(const CFX_WideString& wsDate, |
| 593 CFX_Unitime& unDate) { | 593 CFX_Unitime& unDate) { |
| 594 const FX_WORD LastDay[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; | 594 const uint16_t LastDay[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; |
| 595 const FX_WORD wCountY = 4, wCountM = 2, wCountD = 2; | 595 const uint16_t wCountY = 4, wCountM = 2, wCountD = 2; |
| 596 int nLen = wsDate.GetLength(); | 596 int nLen = wsDate.GetLength(); |
| 597 if (nLen < wCountY || nLen > wCountY + wCountM + wCountD + 2) { | 597 if (nLen < wCountY || nLen > wCountY + wCountM + wCountD + 2) { |
| 598 return FALSE; | 598 return FALSE; |
| 599 } | 599 } |
| 600 const bool bSymbol = wsDate.Find(0x2D) != -1; | 600 const bool bSymbol = wsDate.Find(0x2D) != -1; |
| 601 FX_WORD wYear = 0; | 601 uint16_t wYear = 0; |
| 602 FX_WORD wMonth = 0; | 602 uint16_t wMonth = 0; |
| 603 FX_WORD wDay = 0; | 603 uint16_t wDay = 0; |
| 604 const FX_WCHAR* pDate = (const FX_WCHAR*)wsDate; | 604 const FX_WCHAR* pDate = (const FX_WCHAR*)wsDate; |
| 605 int nIndex = 0, nStart = 0; | 605 int nIndex = 0, nStart = 0; |
| 606 while (pDate[nIndex] != '\0' && nIndex < wCountY) { | 606 while (pDate[nIndex] != '\0' && nIndex < wCountY) { |
| 607 if (!XFA_IsDigit(pDate[nIndex])) { | 607 if (!XFA_IsDigit(pDate[nIndex])) { |
| 608 return FALSE; | 608 return FALSE; |
| 609 } | 609 } |
| 610 wYear = (pDate[nIndex] - '0') + wYear * 10; | 610 wYear = (pDate[nIndex] - '0') + wYear * 10; |
| 611 nIndex++; | 611 nIndex++; |
| 612 } | 612 } |
| 613 if (bSymbol) { | 613 if (bSymbol) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 } | 671 } |
| 672 CFX_Unitime ut; | 672 CFX_Unitime ut; |
| 673 ut.Set(wYear, static_cast<uint8_t>(wMonth), static_cast<uint8_t>(wDay)); | 673 ut.Set(wYear, static_cast<uint8_t>(wMonth), static_cast<uint8_t>(wDay)); |
| 674 unDate = unDate + ut; | 674 unDate = unDate + ut; |
| 675 return TRUE; | 675 return TRUE; |
| 676 } | 676 } |
| 677 FX_BOOL CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) { | 677 FX_BOOL CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) { |
| 678 int nLen = wsTime.GetLength(); | 678 int nLen = wsTime.GetLength(); |
| 679 if (nLen < 2) | 679 if (nLen < 2) |
| 680 return FALSE; | 680 return FALSE; |
| 681 const FX_WORD wCountH = 2; | 681 const uint16_t wCountH = 2; |
| 682 const FX_WORD wCountM = 2; | 682 const uint16_t wCountM = 2; |
| 683 const FX_WORD wCountS = 2; | 683 const uint16_t wCountS = 2; |
| 684 const FX_WORD wCountF = 3; | 684 const uint16_t wCountF = 3; |
| 685 const bool bSymbol = wsTime.Find(':') != -1; | 685 const bool bSymbol = wsTime.Find(':') != -1; |
| 686 FX_WORD wHour = 0; | 686 uint16_t wHour = 0; |
| 687 FX_WORD wMinute = 0; | 687 uint16_t wMinute = 0; |
| 688 FX_WORD wSecond = 0; | 688 uint16_t wSecond = 0; |
| 689 FX_WORD wFraction = 0; | 689 uint16_t wFraction = 0; |
| 690 const FX_WCHAR* pTime = (const FX_WCHAR*)wsTime; | 690 const FX_WCHAR* pTime = (const FX_WCHAR*)wsTime; |
| 691 int nIndex = 0; | 691 int nIndex = 0; |
| 692 int nStart = 0; | 692 int nStart = 0; |
| 693 while (nIndex - nStart < wCountH && pTime[nIndex]) { | 693 while (nIndex - nStart < wCountH && pTime[nIndex]) { |
| 694 if (!XFA_IsDigit(pTime[nIndex])) | 694 if (!XFA_IsDigit(pTime[nIndex])) |
| 695 return FALSE; | 695 return FALSE; |
| 696 wHour = pTime[nIndex] - '0' + wHour * 10; | 696 wHour = pTime[nIndex] - '0' + wHour * 10; |
| 697 nIndex++; | 697 nIndex++; |
| 698 } | 698 } |
| 699 if (bSymbol) { | 699 if (bSymbol) { |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 } else if (cf == L'z') { | 972 } else if (cf == L'z') { |
| 973 nf++; | 973 nf++; |
| 974 } else { | 974 } else { |
| 975 return FALSE; | 975 return FALSE; |
| 976 } | 976 } |
| 977 } | 977 } |
| 978 n++; | 978 n++; |
| 979 } | 979 } |
| 980 return n == nCount; | 980 return n == nCount; |
| 981 } | 981 } |
| OLD | NEW |