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 "fpdfsdk/javascript/PublicMethods.h" | 7 #include "fpdfsdk/javascript/PublicMethods.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <string> | 10 #include <string> |
(...skipping 1406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1417 const std::vector<CJS_Value>& params, | 1417 const std::vector<CJS_Value>& params, |
1418 CJS_Value& vRet, | 1418 CJS_Value& vRet, |
1419 CFX_WideString& sError) { | 1419 CFX_WideString& sError) { |
1420 CJS_Context* pContext = (CJS_Context*)cc; | 1420 CJS_Context* pContext = (CJS_Context*)cc; |
1421 | 1421 |
1422 if (params.size() != 1) { | 1422 if (params.size() != 1) { |
1423 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1423 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1424 return FALSE; | 1424 return FALSE; |
1425 } | 1425 } |
1426 | 1426 |
1427 std::string cFormat; | |
1428 int iIndex = params[0].ToInt(); | |
1429 | |
1430 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1427 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
1431 if (!pEvent->m_pValue) | 1428 if (!pEvent->m_pValue) |
1432 return FALSE; | 1429 return FALSE; |
1433 CFX_WideString& Value = pEvent->Value(); | |
1434 std::string strSrc = CFX_ByteString::FromUnicode(Value).c_str(); | |
1435 | 1430 |
1436 switch (iIndex) { | 1431 CFX_WideString wsSource = pEvent->Value(); |
| 1432 CFX_WideString wsFormat; |
| 1433 switch (params[0].ToInt()) { |
1437 case 0: | 1434 case 0: |
1438 cFormat = "99999"; | 1435 wsFormat = L"99999"; |
1439 break; | 1436 break; |
1440 case 1: | 1437 case 1: |
1441 cFormat = "99999-9999"; | 1438 wsFormat = L"99999-9999"; |
1442 break; | 1439 break; |
1443 case 2: { | 1440 case 2: |
1444 std::string NumberStr; | 1441 if (util::printx(L"9999999999", wsSource).GetLength() >= 10) |
1445 util::printx("9999999999", strSrc, NumberStr); | 1442 wsFormat = L"(999) 999-9999"; |
1446 if (NumberStr.length() >= 10) | |
1447 cFormat = "(999) 999-9999"; | |
1448 else | 1443 else |
1449 cFormat = "999-9999"; | 1444 wsFormat = L"999-9999"; |
1450 break; | 1445 break; |
1451 } | |
1452 case 3: | 1446 case 3: |
1453 cFormat = "999-99-9999"; | 1447 wsFormat = L"999-99-9999"; |
1454 break; | 1448 break; |
1455 } | 1449 } |
1456 | 1450 |
1457 std::string strDes; | 1451 pEvent->Value() = util::printx(wsFormat, wsSource); |
1458 util::printx(cFormat, strSrc, strDes); | |
1459 Value = CFX_WideString::FromLocal(strDes.c_str()); | |
1460 return TRUE; | 1452 return TRUE; |
1461 } | 1453 } |
1462 | 1454 |
1463 // function AFSpecial_KeystrokeEx(mask) | 1455 // function AFSpecial_KeystrokeEx(mask) |
1464 FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx( | 1456 FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx( |
1465 IJS_Context* cc, | 1457 IJS_Context* cc, |
1466 const std::vector<CJS_Value>& params, | 1458 const std::vector<CJS_Value>& params, |
1467 CJS_Value& vRet, | 1459 CJS_Value& vRet, |
1468 CFX_WideString& sError) { | 1460 CFX_WideString& sError) { |
1469 CJS_Context* pContext = (CJS_Context*)cc; | 1461 CJS_Context* pContext = (CJS_Context*)cc; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1571 int iIndex = params[0].ToInt(); | 1563 int iIndex = params[0].ToInt(); |
1572 CFX_WideString& val = pEvent->Value(); | 1564 CFX_WideString& val = pEvent->Value(); |
1573 std::string strSrc = CFX_ByteString::FromUnicode(val).c_str(); | 1565 std::string strSrc = CFX_ByteString::FromUnicode(val).c_str(); |
1574 std::wstring wstrChange = pEvent->Change().c_str(); | 1566 std::wstring wstrChange = pEvent->Change().c_str(); |
1575 | 1567 |
1576 switch (iIndex) { | 1568 switch (iIndex) { |
1577 case 0: | 1569 case 0: |
1578 cFormat = "99999"; | 1570 cFormat = "99999"; |
1579 break; | 1571 break; |
1580 case 1: | 1572 case 1: |
1581 // cFormat = "99999-9999"; | |
1582 cFormat = "999999999"; | 1573 cFormat = "999999999"; |
1583 break; | 1574 break; |
1584 case 2: { | 1575 case 2: |
1585 std::string NumberStr; | |
1586 util::printx("9999999999", strSrc, NumberStr); | |
1587 if (strSrc.length() + wstrChange.length() > 7) | 1576 if (strSrc.length() + wstrChange.length() > 7) |
1588 // cFormat = "(999) 999-9999"; | |
1589 cFormat = "9999999999"; | 1577 cFormat = "9999999999"; |
1590 else | 1578 else |
1591 // cFormat = "999-9999"; | |
1592 cFormat = "9999999"; | 1579 cFormat = "9999999"; |
1593 break; | 1580 break; |
1594 } | |
1595 case 3: | 1581 case 3: |
1596 // cFormat = "999-99-9999"; | |
1597 cFormat = "999999999"; | 1582 cFormat = "999999999"; |
1598 break; | 1583 break; |
1599 } | 1584 } |
1600 | 1585 |
1601 std::vector<CJS_Value> params2; | 1586 std::vector<CJS_Value> params2; |
1602 params2.push_back(CJS_Value(CJS_Runtime::FromContext(cc), cFormat.c_str())); | 1587 params2.push_back(CJS_Value(CJS_Runtime::FromContext(cc), cFormat.c_str())); |
1603 return AFSpecial_KeystrokeEx(cc, params2, vRet, sError); | 1588 return AFSpecial_KeystrokeEx(cc, params2, vRet, sError); |
1604 } | 1589 } |
1605 | 1590 |
1606 FX_BOOL CJS_PublicMethods::AFMergeChange(IJS_Context* cc, | 1591 FX_BOOL CJS_PublicMethods::AFMergeChange(IJS_Context* cc, |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1890 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); | 1875 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); |
1891 } | 1876 } |
1892 | 1877 |
1893 if (nums.GetLength() > 0) | 1878 if (nums.GetLength() > 0) |
1894 vRet = nums; | 1879 vRet = nums; |
1895 else | 1880 else |
1896 vRet.SetNull(); | 1881 vRet.SetNull(); |
1897 | 1882 |
1898 return TRUE; | 1883 return TRUE; |
1899 } | 1884 } |
OLD | NEW |