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 "../../include/javascript/JavaScript.h" | 7 #include "../../include/javascript/JavaScript.h" |
8 #include "../../include/javascript/IJavaScript.h" | 8 #include "../../include/javascript/IJavaScript.h" |
9 #include "../../include/javascript/JS_Define.h" | 9 #include "../../include/javascript/JS_Define.h" |
10 #include "../../include/javascript/JS_Object.h" | 10 #include "../../include/javascript/JS_Object.h" |
(...skipping 1480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1491 L"d-mmm-yy", | 1491 L"d-mmm-yy", |
1492 L"dd-mmm-yy", | 1492 L"dd-mmm-yy", |
1493 L"yy-mm-dd", | 1493 L"yy-mm-dd", |
1494 L"mmm-yy", | 1494 L"mmm-yy", |
1495 L"mmmm-yy", | 1495 L"mmmm-yy", |
1496 L"mmm d, yyyy", | 1496 L"mmm d, yyyy", |
1497 L"mmmm d, yyyy", | 1497 L"mmmm d, yyyy", |
1498 L"m/d/yy h:MM tt", | 1498 L"m/d/yy h:MM tt", |
1499 L"m/d/yy HH:MM"}; | 1499 L"m/d/yy HH:MM"}; |
1500 | 1500 |
1501 ASSERT(iIndex < FX_ArraySize(cFormats)); | 1501 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
| 1502 iIndex = 0; |
1502 | 1503 |
1503 if (iIndex < 0) | |
1504 iIndex = 0; | |
1505 if (iIndex >= FX_ArraySize(cFormats)) | |
1506 iIndex = 0; | |
1507 CJS_Parameters newParams; | 1504 CJS_Parameters newParams; |
1508 CJS_Value val(isolate, cFormats[iIndex]); | 1505 CJS_Value val(isolate, cFormats[iIndex]); |
1509 newParams.push_back(val); | 1506 newParams.push_back(val); |
1510 return AFDate_FormatEx(cc, newParams, vRet, sError); | 1507 return AFDate_FormatEx(cc, newParams, vRet, sError); |
1511 } | 1508 } |
1512 | 1509 |
1513 // AFDate_KeystrokeEx(cFormat) | 1510 // AFDate_KeystrokeEx(cFormat) |
1514 FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IFXJS_Context* cc, | 1511 FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IFXJS_Context* cc, |
1515 const CJS_Parameters& params, | 1512 const CJS_Parameters& params, |
1516 CJS_Value& vRet, | 1513 CJS_Value& vRet, |
(...skipping 17 matching lines...) Expand all Loading... |
1534 L"d-mmm-yy", | 1531 L"d-mmm-yy", |
1535 L"dd-mmm-yy", | 1532 L"dd-mmm-yy", |
1536 L"yy-mm-dd", | 1533 L"yy-mm-dd", |
1537 L"mmm-yy", | 1534 L"mmm-yy", |
1538 L"mmmm-yy", | 1535 L"mmmm-yy", |
1539 L"mmm d, yyyy", | 1536 L"mmm d, yyyy", |
1540 L"mmmm d, yyyy", | 1537 L"mmmm d, yyyy", |
1541 L"m/d/yy h:MM tt", | 1538 L"m/d/yy h:MM tt", |
1542 L"m/d/yy HH:MM"}; | 1539 L"m/d/yy HH:MM"}; |
1543 | 1540 |
1544 ASSERT(iIndex < FX_ArraySize(cFormats)); | 1541 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
| 1542 iIndex = 0; |
1545 | 1543 |
1546 if (iIndex < 0) | |
1547 iIndex = 0; | |
1548 if (iIndex >= FX_ArraySize(cFormats)) | |
1549 iIndex = 0; | |
1550 CJS_Parameters newParams; | 1544 CJS_Parameters newParams; |
1551 CJS_Value val(isolate, cFormats[iIndex]); | 1545 CJS_Value val(isolate, cFormats[iIndex]); |
1552 newParams.push_back(val); | 1546 newParams.push_back(val); |
1553 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); | 1547 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); |
1554 } | 1548 } |
1555 | 1549 |
1556 // function AFTime_Format(ptf) | 1550 // function AFTime_Format(ptf) |
1557 FX_BOOL CJS_PublicMethods::AFTime_Format(IFXJS_Context* cc, | 1551 FX_BOOL CJS_PublicMethods::AFTime_Format(IFXJS_Context* cc, |
1558 const CJS_Parameters& params, | 1552 const CJS_Parameters& params, |
1559 CJS_Value& vRet, | 1553 CJS_Value& vRet, |
1560 CFX_WideString& sError) { | 1554 CFX_WideString& sError) { |
1561 v8::Isolate* isolate = ::GetIsolate(cc); | 1555 v8::Isolate* isolate = ::GetIsolate(cc); |
1562 | 1556 |
1563 if (params.size() != 1) { | 1557 if (params.size() != 1) { |
1564 CJS_Context* pContext = (CJS_Context*)cc; | 1558 CJS_Context* pContext = (CJS_Context*)cc; |
1565 ASSERT(pContext != NULL); | 1559 ASSERT(pContext != NULL); |
1566 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1560 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1567 return FALSE; | 1561 return FALSE; |
1568 } | 1562 } |
1569 | 1563 |
1570 int iIndex = params[0].ToInt(); | 1564 int iIndex = params[0].ToInt(); |
1571 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", | 1565 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", |
1572 L"h:MM:ss tt"}; | 1566 L"h:MM:ss tt"}; |
1573 | 1567 |
1574 ASSERT(iIndex < FX_ArraySize(cFormats)); | 1568 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
| 1569 iIndex = 0; |
1575 | 1570 |
1576 if (iIndex < 0) | |
1577 iIndex = 0; | |
1578 if (iIndex >= FX_ArraySize(cFormats)) | |
1579 iIndex = 0; | |
1580 CJS_Parameters newParams; | 1571 CJS_Parameters newParams; |
1581 CJS_Value val(isolate, cFormats[iIndex]); | 1572 CJS_Value val(isolate, cFormats[iIndex]); |
1582 newParams.push_back(val); | 1573 newParams.push_back(val); |
1583 return AFDate_FormatEx(cc, newParams, vRet, sError); | 1574 return AFDate_FormatEx(cc, newParams, vRet, sError); |
1584 } | 1575 } |
1585 | 1576 |
1586 FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IFXJS_Context* cc, | 1577 FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IFXJS_Context* cc, |
1587 const CJS_Parameters& params, | 1578 const CJS_Parameters& params, |
1588 CJS_Value& vRet, | 1579 CJS_Value& vRet, |
1589 CFX_WideString& sError) { | 1580 CFX_WideString& sError) { |
1590 v8::Isolate* isolate = ::GetIsolate(cc); | 1581 v8::Isolate* isolate = ::GetIsolate(cc); |
1591 if (params.size() != 1) { | 1582 if (params.size() != 1) { |
1592 CJS_Context* pContext = (CJS_Context*)cc; | 1583 CJS_Context* pContext = (CJS_Context*)cc; |
1593 ASSERT(pContext != NULL); | 1584 ASSERT(pContext != NULL); |
1594 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1585 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1595 return FALSE; | 1586 return FALSE; |
1596 } | 1587 } |
1597 | 1588 |
1598 int iIndex = params[0].ToInt(); | 1589 int iIndex = params[0].ToInt(); |
1599 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", | 1590 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", |
1600 L"h:MM:ss tt"}; | 1591 L"h:MM:ss tt"}; |
1601 | 1592 |
1602 ASSERT(iIndex < FX_ArraySize(cFormats)); | 1593 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
| 1594 iIndex = 0; |
1603 | 1595 |
1604 if (iIndex < 0) | |
1605 iIndex = 0; | |
1606 if (iIndex >= FX_ArraySize(cFormats)) | |
1607 iIndex = 0; | |
1608 CJS_Parameters newParams; | 1596 CJS_Parameters newParams; |
1609 CJS_Value val(isolate, cFormats[iIndex]); | 1597 CJS_Value val(isolate, cFormats[iIndex]); |
1610 newParams.push_back(val); | 1598 newParams.push_back(val); |
1611 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); | 1599 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); |
1612 } | 1600 } |
1613 | 1601 |
1614 FX_BOOL CJS_PublicMethods::AFTime_FormatEx(IFXJS_Context* cc, | 1602 FX_BOOL CJS_PublicMethods::AFTime_FormatEx(IFXJS_Context* cc, |
1615 const CJS_Parameters& params, | 1603 const CJS_Parameters& params, |
1616 CJS_Value& vRet, | 1604 CJS_Value& vRet, |
1617 CFX_WideString& sError) { | 1605 CFX_WideString& sError) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1693 } | 1681 } |
1694 | 1682 |
1695 if (!pEvent->m_pValue) | 1683 if (!pEvent->m_pValue) |
1696 return FALSE; | 1684 return FALSE; |
1697 CFX_WideString& valEvent = pEvent->Value(); | 1685 CFX_WideString& valEvent = pEvent->Value(); |
1698 | 1686 |
1699 CFX_WideString wstrMask = params[0].ToCFXWideString(); | 1687 CFX_WideString wstrMask = params[0].ToCFXWideString(); |
1700 if (wstrMask.IsEmpty()) | 1688 if (wstrMask.IsEmpty()) |
1701 return TRUE; | 1689 return TRUE; |
1702 | 1690 |
1703 std::wstring wstrValue = valEvent.c_str(); | 1691 const size_t wstrMaskLen = wstrMask.GetLength(); |
| 1692 const std::wstring wstrValue = valEvent.c_str(); |
1704 | 1693 |
1705 if (pEvent->WillCommit()) { | 1694 if (pEvent->WillCommit()) { |
1706 if (wstrValue.empty()) | 1695 if (wstrValue.empty()) |
1707 return TRUE; | 1696 return TRUE; |
1708 int iIndexMask = 0; | 1697 size_t iIndexMask = 0; |
1709 for (std::wstring::iterator it = wstrValue.begin(); it != wstrValue.end(); | 1698 for (const auto& w_Value : wstrValue) { |
1710 it++) { | |
1711 wchar_t w_Value = *it; | |
1712 if (!maskSatisfied(w_Value, wstrMask[iIndexMask])) | 1699 if (!maskSatisfied(w_Value, wstrMask[iIndexMask])) |
1713 break; | 1700 break; |
1714 iIndexMask++; | 1701 iIndexMask++; |
1715 } | 1702 } |
1716 | 1703 |
1717 if (iIndexMask != wstrMask.GetLength() || | 1704 if (iIndexMask != wstrMaskLen || |
1718 (iIndexMask != wstrValue.size() && wstrMask.GetLength() != 0)) { | 1705 (iIndexMask != wstrValue.size() && wstrMaskLen != 0)) { |
1719 Alert( | 1706 Alert( |
1720 pContext, | 1707 pContext, |
1721 JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE).c_str()); | 1708 JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE).c_str()); |
1722 pEvent->Rc() = FALSE; | 1709 pEvent->Rc() = FALSE; |
1723 } | 1710 } |
1724 return TRUE; | 1711 return TRUE; |
1725 } | 1712 } |
1726 | 1713 |
1727 CFX_WideString& wideChange = pEvent->Change(); | 1714 CFX_WideString& wideChange = pEvent->Change(); |
1728 std::wstring wChange = wideChange.c_str(); | 1715 std::wstring wChange = wideChange.c_str(); |
1729 if (wChange.empty()) | 1716 if (wChange.empty()) |
1730 return TRUE; | 1717 return TRUE; |
1731 | 1718 |
1732 int iIndexMask = pEvent->SelStart(); | 1719 int iIndexMask = pEvent->SelStart(); |
1733 | 1720 |
1734 if (wstrValue.length() - (pEvent->SelEnd() - pEvent->SelStart()) + | 1721 size_t combined_len = wstrValue.length() + wChange.length() - |
1735 wChange.length() > | 1722 (pEvent->SelEnd() - pEvent->SelStart()); |
1736 (FX_DWORD)wstrMask.GetLength()) { | 1723 if (combined_len > wstrMaskLen) { |
1737 Alert(pContext, | 1724 Alert(pContext, |
1738 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); | 1725 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); |
1739 pEvent->Rc() = FALSE; | 1726 pEvent->Rc() = FALSE; |
1740 return TRUE; | 1727 return TRUE; |
1741 } | 1728 } |
1742 | 1729 |
1743 if (iIndexMask >= wstrMask.GetLength() && (!wChange.empty())) { | 1730 if (iIndexMask >= wstrMaskLen && (!wChange.empty())) { |
1744 Alert(pContext, | 1731 Alert(pContext, |
1745 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); | 1732 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); |
1746 pEvent->Rc() = FALSE; | 1733 pEvent->Rc() = FALSE; |
1747 return TRUE; | 1734 return TRUE; |
1748 } | 1735 } |
1749 | 1736 |
1750 for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++) { | 1737 for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++) { |
1751 if (iIndexMask >= wstrMask.GetLength()) { | 1738 if (iIndexMask >= wstrMaskLen) { |
1752 Alert(pContext, | 1739 Alert(pContext, |
1753 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); | 1740 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); |
1754 pEvent->Rc() = FALSE; | 1741 pEvent->Rc() = FALSE; |
1755 return TRUE; | 1742 return TRUE; |
1756 } | 1743 } |
1757 wchar_t w_Mask = wstrMask[iIndexMask]; | 1744 wchar_t w_Mask = wstrMask[iIndexMask]; |
1758 if (!isReservedMaskChar(w_Mask)) { | 1745 if (!isReservedMaskChar(w_Mask)) { |
1759 *it = w_Mask; | 1746 *it = w_Mask; |
1760 } | 1747 } |
1761 wchar_t w_Change = *it; | 1748 wchar_t w_Change = *it; |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2134 nums.SetElement(nIndex, CJS_Value(isolate, sPart.c_str())); | 2121 nums.SetElement(nIndex, CJS_Value(isolate, sPart.c_str())); |
2135 } | 2122 } |
2136 | 2123 |
2137 if (nums.GetLength() > 0) | 2124 if (nums.GetLength() > 0) |
2138 vRet = nums; | 2125 vRet = nums; |
2139 else | 2126 else |
2140 vRet.SetNull(); | 2127 vRet.SetNull(); |
2141 | 2128 |
2142 return TRUE; | 2129 return TRUE; |
2143 } | 2130 } |
OLD | NEW |