| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 155 |
| 156 CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime, | 156 CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime, |
| 157 CJS_Value val) { | 157 CJS_Value val) { |
| 158 CJS_Array StrArray(pRuntime); | 158 CJS_Array StrArray(pRuntime); |
| 159 if (val.IsArrayObject()) { | 159 if (val.IsArrayObject()) { |
| 160 val.ConvertToArray(StrArray); | 160 val.ConvertToArray(StrArray); |
| 161 return StrArray; | 161 return StrArray; |
| 162 } | 162 } |
| 163 CFX_WideString wsStr = val.ToCFXWideString(); | 163 CFX_WideString wsStr = val.ToCFXWideString(); |
| 164 CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr); | 164 CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr); |
| 165 const char* p = (const char*)t; | 165 const char* p = t.c_str(); |
| 166 | 166 |
| 167 int ch = ','; | 167 int ch = ','; |
| 168 int nIndex = 0; | 168 int nIndex = 0; |
| 169 | 169 |
| 170 while (*p) { | 170 while (*p) { |
| 171 const char* pTemp = strchr(p, ch); | 171 const char* pTemp = strchr(p, ch); |
| 172 if (!pTemp) { | 172 if (!pTemp) { |
| 173 StrArray.SetElement(nIndex, | 173 StrArray.SetElement( |
| 174 CJS_Value(pRuntime, StrTrim(CFX_ByteString(p)))); | 174 nIndex, CJS_Value(pRuntime, StrTrim(CFX_ByteString(p)).c_str())); |
| 175 break; | 175 break; |
| 176 } | 176 } |
| 177 | 177 |
| 178 char* pSub = new char[pTemp - p + 1]; | 178 char* pSub = new char[pTemp - p + 1]; |
| 179 strncpy(pSub, p, pTemp - p); | 179 strncpy(pSub, p, pTemp - p); |
| 180 *(pSub + (pTemp - p)) = '\0'; | 180 *(pSub + (pTemp - p)) = '\0'; |
| 181 | 181 |
| 182 StrArray.SetElement(nIndex, | 182 StrArray.SetElement( |
| 183 CJS_Value(pRuntime, StrTrim(CFX_ByteString(pSub)))); | 183 nIndex, CJS_Value(pRuntime, StrTrim(CFX_ByteString(pSub)).c_str())); |
| 184 delete[] pSub; | 184 delete[] pSub; |
| 185 | 185 |
| 186 nIndex++; | 186 nIndex++; |
| 187 p = ++pTemp; | 187 p = ++pTemp; |
| 188 } | 188 } |
| 189 return StrArray; | 189 return StrArray; |
| 190 } | 190 } |
| 191 | 191 |
| 192 int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& str, | 192 int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& str, |
| 193 int nStart, | 193 int nStart, |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 iDec = -iDec; | 749 iDec = -iDec; |
| 750 | 750 |
| 751 if (iSepStyle < 0 || iSepStyle > 3) | 751 if (iSepStyle < 0 || iSepStyle > 3) |
| 752 iSepStyle = 0; | 752 iSepStyle = 0; |
| 753 | 753 |
| 754 if (iNegStyle < 0 || iNegStyle > 3) | 754 if (iNegStyle < 0 || iNegStyle > 3) |
| 755 iNegStyle = 0; | 755 iNegStyle = 0; |
| 756 | 756 |
| 757 // for processing decimal places | 757 // for processing decimal places |
| 758 strValue.Replace(",", "."); | 758 strValue.Replace(",", "."); |
| 759 double dValue = atof(strValue); | 759 double dValue = atof(strValue.c_str()); |
| 760 if (iDec > 0) | 760 if (iDec > 0) |
| 761 dValue += DOUBLE_CORRECT; | 761 dValue += DOUBLE_CORRECT; |
| 762 | 762 |
| 763 int iDec2; | 763 int iDec2; |
| 764 int iNegative = 0; | 764 int iNegative = 0; |
| 765 | 765 |
| 766 strValue = fcvt(dValue, iDec, &iDec2, &iNegative); | 766 strValue = fcvt(dValue, iDec, &iDec2, &iNegative); |
| 767 if (strValue.IsEmpty()) { | 767 if (strValue.IsEmpty()) { |
| 768 dValue = 0; | 768 dValue = 0; |
| 769 strValue = fcvt(dValue, iDec, &iDec2, &iNegative); | 769 strValue = fcvt(dValue, iDec, &iDec2, &iNegative); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 | 1033 |
| 1034 int iDec = params[0].ToInt(); | 1034 int iDec = params[0].ToInt(); |
| 1035 if (iDec < 0) | 1035 if (iDec < 0) |
| 1036 iDec = -iDec; | 1036 iDec = -iDec; |
| 1037 | 1037 |
| 1038 int iSepStyle = params[1].ToInt(); | 1038 int iSepStyle = params[1].ToInt(); |
| 1039 if (iSepStyle < 0 || iSepStyle > 3) | 1039 if (iSepStyle < 0 || iSepStyle > 3) |
| 1040 iSepStyle = 0; | 1040 iSepStyle = 0; |
| 1041 | 1041 |
| 1042 // for processing decimal places | 1042 // for processing decimal places |
| 1043 double dValue = atof(strValue); | 1043 double dValue = atof(strValue.c_str()); |
| 1044 dValue *= 100; | 1044 dValue *= 100; |
| 1045 if (iDec > 0) | 1045 if (iDec > 0) |
| 1046 dValue += DOUBLE_CORRECT; | 1046 dValue += DOUBLE_CORRECT; |
| 1047 | 1047 |
| 1048 int iDec2; | 1048 int iDec2; |
| 1049 int iNegative = 0; | 1049 int iNegative = 0; |
| 1050 strValue = fcvt(dValue, iDec, &iDec2, &iNegative); | 1050 strValue = fcvt(dValue, iDec, &iDec2, &iNegative); |
| 1051 if (strValue.IsEmpty()) { | 1051 if (strValue.IsEmpty()) { |
| 1052 dValue = 0; | 1052 dValue = 0; |
| 1053 strValue = fcvt(dValue, iDec, &iDec2, &iNegative); | 1053 strValue = fcvt(dValue, iDec, &iDec2, &iNegative); |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1771 | 1771 |
| 1772 if (params.size() != 4) { | 1772 if (params.size() != 4) { |
| 1773 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1773 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1774 return FALSE; | 1774 return FALSE; |
| 1775 } | 1775 } |
| 1776 | 1776 |
| 1777 if (!pEvent->m_pValue) | 1777 if (!pEvent->m_pValue) |
| 1778 return FALSE; | 1778 return FALSE; |
| 1779 if (pEvent->Value().IsEmpty()) | 1779 if (pEvent->Value().IsEmpty()) |
| 1780 return TRUE; | 1780 return TRUE; |
| 1781 double dEentValue = atof(CFX_ByteString::FromUnicode(pEvent->Value())); | 1781 double dEentValue = |
| 1782 atof(CFX_ByteString::FromUnicode(pEvent->Value()).c_str()); |
| 1782 FX_BOOL bGreaterThan = params[0].ToBool(); | 1783 FX_BOOL bGreaterThan = params[0].ToBool(); |
| 1783 double dGreaterThan = params[1].ToDouble(); | 1784 double dGreaterThan = params[1].ToDouble(); |
| 1784 FX_BOOL bLessThan = params[2].ToBool(); | 1785 FX_BOOL bLessThan = params[2].ToBool(); |
| 1785 double dLessThan = params[3].ToDouble(); | 1786 double dLessThan = params[3].ToDouble(); |
| 1786 CFX_WideString swMsg; | 1787 CFX_WideString swMsg; |
| 1787 | 1788 |
| 1788 if (bGreaterThan && bLessThan) { | 1789 if (bGreaterThan && bLessThan) { |
| 1789 if (dEentValue < dGreaterThan || dEentValue > dLessThan) | 1790 if (dEentValue < dGreaterThan || dEentValue > dLessThan) |
| 1790 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1).c_str(), | 1791 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1).c_str(), |
| 1791 params[1].ToCFXWideString().c_str(), | 1792 params[1].ToCFXWideString().c_str(), |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1844 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); | 1845 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); |
| 1845 } | 1846 } |
| 1846 | 1847 |
| 1847 if (nums.GetLength() > 0) | 1848 if (nums.GetLength() > 0) |
| 1848 vRet = nums; | 1849 vRet = nums; |
| 1849 else | 1850 else |
| 1850 vRet.SetNull(); | 1851 vRet.SetNull(); |
| 1851 | 1852 |
| 1852 return TRUE; | 1853 return TRUE; |
| 1853 } | 1854 } |
| OLD | NEW |