| 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/src/javascript/PublicMethods.h" | 7 #include "fpdfsdk/src/javascript/PublicMethods.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> |
| 11 #include <vector> |
| 10 | 12 |
| 11 #include "core/include/fxcrt/fx_ext.h" | 13 #include "core/include/fxcrt/fx_ext.h" |
| 12 #include "fpdfsdk/include/fsdk_mgr.h" // For CPDFDoc_Environment. | 14 #include "fpdfsdk/include/fsdk_mgr.h" // For CPDFDoc_Environment. |
| 13 #include "fpdfsdk/include/javascript/IJavaScript.h" | 15 #include "fpdfsdk/include/javascript/IJavaScript.h" |
| 14 #include "fpdfsdk/src/javascript/Field.h" | 16 #include "fpdfsdk/src/javascript/Field.h" |
| 15 #include "fpdfsdk/src/javascript/JS_Context.h" | 17 #include "fpdfsdk/src/javascript/JS_Context.h" |
| 16 #include "fpdfsdk/src/javascript/JS_Define.h" | 18 #include "fpdfsdk/src/javascript/JS_Define.h" |
| 17 #include "fpdfsdk/src/javascript/JS_EventHandler.h" | 19 #include "fpdfsdk/src/javascript/JS_EventHandler.h" |
| 18 #include "fpdfsdk/src/javascript/JS_Object.h" | 20 #include "fpdfsdk/src/javascript/JS_Object.h" |
| 19 #include "fpdfsdk/src/javascript/JS_Runtime.h" | 21 #include "fpdfsdk/src/javascript/JS_Runtime.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 L"April", | 72 L"April", |
| 71 L"May", | 73 L"May", |
| 72 L"June", | 74 L"June", |
| 73 L"July", | 75 L"July", |
| 74 L"August", | 76 L"August", |
| 75 L"September", | 77 L"September", |
| 76 L"October", | 78 L"October", |
| 77 L"November", | 79 L"November", |
| 78 L"December"}; | 80 L"December"}; |
| 79 | 81 |
| 80 FX_BOOL CJS_PublicMethods::IsNumber(const FX_WCHAR* string) { | 82 FX_BOOL CJS_PublicMethods::IsNumber(const FX_WCHAR* str) { |
| 81 CFX_WideString sTrim = StrTrim(string); | 83 CFX_WideString sTrim = StrTrim(str); |
| 82 const FX_WCHAR* pTrim = sTrim.c_str(); | 84 const FX_WCHAR* pTrim = sTrim.c_str(); |
| 83 const FX_WCHAR* p = pTrim; | 85 const FX_WCHAR* p = pTrim; |
| 84 | 86 |
| 85 FX_BOOL bDot = FALSE; | 87 FX_BOOL bDot = FALSE; |
| 86 FX_BOOL bKXJS = FALSE; | 88 FX_BOOL bKXJS = FALSE; |
| 87 | 89 |
| 88 wchar_t c; | 90 wchar_t c; |
| 89 while ((c = *p)) { | 91 while ((c = *p)) { |
| 90 if (c == '.' || c == ',') { | 92 if (c == '.' || c == ',') { |
| 91 if (bDot) | 93 if (bDot) |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 223 |
| 222 StrArray.SetElement(nIndex, CJS_Value(pRuntime, StrTrim(pSub).c_str())); | 224 StrArray.SetElement(nIndex, CJS_Value(pRuntime, StrTrim(pSub).c_str())); |
| 223 delete[] pSub; | 225 delete[] pSub; |
| 224 | 226 |
| 225 nIndex++; | 227 nIndex++; |
| 226 p = ++pTemp; | 228 p = ++pTemp; |
| 227 } | 229 } |
| 228 return StrArray; | 230 return StrArray; |
| 229 } | 231 } |
| 230 | 232 |
| 231 int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& string, | 233 int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& str, |
| 232 int nStart, | 234 int nStart, |
| 233 int& nSkip, | 235 int& nSkip, |
| 234 int nMaxStep) { | 236 int nMaxStep) { |
| 235 int nRet = 0; | 237 int nRet = 0; |
| 236 nSkip = 0; | 238 nSkip = 0; |
| 237 for (int i = nStart, sz = string.GetLength(); i < sz; i++) { | 239 for (int i = nStart, sz = str.GetLength(); i < sz; i++) { |
| 238 if (i - nStart > 10) | 240 if (i - nStart > 10) |
| 239 break; | 241 break; |
| 240 | 242 |
| 241 FX_WCHAR c = string.GetAt(i); | 243 FX_WCHAR c = str.GetAt(i); |
| 242 if (!FXSYS_iswdigit(c)) | 244 if (!FXSYS_iswdigit(c)) |
| 243 break; | 245 break; |
| 244 | 246 |
| 245 nRet = nRet * 10 + FXSYS_toDecimalDigit(c); | 247 nRet = nRet * 10 + FXSYS_toDecimalDigit(c); |
| 246 nSkip = i - nStart + 1; | 248 nSkip = i - nStart + 1; |
| 247 if (nSkip >= nMaxStep) | 249 if (nSkip >= nMaxStep) |
| 248 break; | 250 break; |
| 249 } | 251 } |
| 250 | 252 |
| 251 return nRet; | 253 return nRet; |
| 252 } | 254 } |
| 253 | 255 |
| 254 CFX_WideString CJS_PublicMethods::ParseStringString( | 256 CFX_WideString CJS_PublicMethods::ParseStringString(const CFX_WideString& str, |
| 255 const CFX_WideString& string, | 257 int nStart, |
| 256 int nStart, | 258 int& nSkip) { |
| 257 int& nSkip) { | |
| 258 CFX_WideString swRet; | 259 CFX_WideString swRet; |
| 259 nSkip = 0; | 260 nSkip = 0; |
| 260 for (int i = nStart, sz = string.GetLength(); i < sz; i++) { | 261 for (int i = nStart, sz = str.GetLength(); i < sz; i++) { |
| 261 FX_WCHAR c = string.GetAt(i); | 262 FX_WCHAR c = str.GetAt(i); |
| 262 if (!FXSYS_iswdigit(c)) | 263 if (!FXSYS_iswdigit(c)) |
| 263 break; | 264 break; |
| 264 | 265 |
| 265 swRet += c; | 266 swRet += c; |
| 266 nSkip = i - nStart + 1; | 267 nSkip = i - nStart + 1; |
| 267 } | 268 } |
| 268 | 269 |
| 269 return swRet; | 270 return swRet; |
| 270 } | 271 } |
| 271 | 272 |
| (...skipping 1634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1906 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); | 1907 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); |
| 1907 } | 1908 } |
| 1908 | 1909 |
| 1909 if (nums.GetLength() > 0) | 1910 if (nums.GetLength() > 0) |
| 1910 vRet = nums; | 1911 vRet = nums; |
| 1911 else | 1912 else |
| 1912 vRet.SetNull(); | 1913 vRet.SetNull(); |
| 1913 | 1914 |
| 1914 return TRUE; | 1915 return TRUE; |
| 1915 } | 1916 } |
| OLD | NEW |