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