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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 static const FX_WCHAR* const months[] = {L"Jan", L"Feb", L"Mar", L"Apr", | 56 static const FX_WCHAR* const months[] = {L"Jan", L"Feb", L"Mar", L"Apr", |
57 L"May", L"Jun", L"Jul", L"Aug", | 57 L"May", L"Jun", L"Jul", L"Aug", |
58 L"Sep", L"Oct", L"Nov", L"Dec"}; | 58 L"Sep", L"Oct", L"Nov", L"Dec"}; |
59 | 59 |
60 static const FX_WCHAR* const fullmonths[] = { | 60 static const FX_WCHAR* const fullmonths[] = { |
61 L"January", L"February", L"March", L"April", | 61 L"January", L"February", L"March", L"April", |
62 L"May", L"June", L"July", L"August", | 62 L"May", L"June", L"July", L"August", |
63 L"September", L"October", L"November", L"December"}; | 63 L"September", L"October", L"November", L"December"}; |
64 | 64 |
65 FX_BOOL CJS_PublicMethods::IsNumber(const FX_WCHAR* str) { | 65 bool CJS_PublicMethods::IsNumber(const FX_WCHAR* str) { |
66 CFX_WideString sTrim = StrTrim(str); | 66 CFX_WideString sTrim = StrTrim(str); |
67 const FX_WCHAR* pTrim = sTrim.c_str(); | 67 const FX_WCHAR* pTrim = sTrim.c_str(); |
68 const FX_WCHAR* p = pTrim; | 68 const FX_WCHAR* p = pTrim; |
69 | 69 |
70 FX_BOOL bDot = FALSE; | 70 bool bDot = false; |
71 FX_BOOL bKXJS = FALSE; | 71 bool bKXJS = false; |
72 | 72 |
73 wchar_t c; | 73 wchar_t c; |
74 while ((c = *p)) { | 74 while ((c = *p) != L'\0') { |
75 if (c == '.' || c == ',') { | 75 if (c == L'.' || c == L',') { |
76 if (bDot) | 76 if (bDot) |
77 return FALSE; | 77 return false; |
78 bDot = TRUE; | 78 bDot = true; |
79 } else if (c == '-' || c == '+') { | 79 } else if (c == L'-' || c == L'+') { |
80 if (p != pTrim) | 80 if (p != pTrim) |
81 return FALSE; | 81 return false; |
82 } else if (c == 'e' || c == 'E') { | 82 } else if (c == L'e' || c == L'E') { |
83 if (bKXJS) | 83 if (bKXJS) |
84 return FALSE; | 84 return false; |
85 | 85 |
86 p++; | 86 p++; |
87 c = *p; | 87 c = *p; |
88 if (c == '+' || c == '-') { | 88 if (c == L'+' || c == L'-') { |
89 bKXJS = TRUE; | 89 bKXJS = true; |
90 } else { | 90 } else { |
91 return FALSE; | 91 return false; |
92 } | 92 } |
93 } else if (!FXSYS_iswdigit(c)) { | 93 } else if (!FXSYS_iswdigit(c)) { |
94 return FALSE; | 94 return false; |
95 } | 95 } |
96 p++; | 96 p++; |
97 } | 97 } |
98 | 98 |
99 return TRUE; | 99 return true; |
100 } | 100 } |
101 | 101 |
102 FX_BOOL CJS_PublicMethods::maskSatisfied(wchar_t c_Change, wchar_t c_Mask) { | 102 bool CJS_PublicMethods::maskSatisfied(wchar_t c_Change, wchar_t c_Mask) { |
103 switch (c_Mask) { | 103 switch (c_Mask) { |
104 case L'9': | 104 case L'9': |
105 return FXSYS_iswdigit(c_Change); | 105 return FXSYS_iswdigit(c_Change); |
106 case L'A': | 106 case L'A': |
107 return FXSYS_iswalpha(c_Change); | 107 return FXSYS_iswalpha(c_Change); |
108 case L'O': | 108 case L'O': |
109 return FXSYS_iswalnum(c_Change); | 109 return FXSYS_iswalnum(c_Change); |
110 case L'X': | 110 case L'X': |
111 return TRUE; | 111 return true; |
112 default: | 112 default: |
113 return (c_Change == c_Mask); | 113 return (c_Change == c_Mask); |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 FX_BOOL CJS_PublicMethods::isReservedMaskChar(wchar_t ch) { | 117 bool CJS_PublicMethods::isReservedMaskChar(wchar_t ch) { |
118 return ch == L'9' || ch == L'A' || ch == L'O' || ch == L'X'; | 118 return ch == L'9' || ch == L'A' || ch == L'O' || ch == L'X'; |
119 } | 119 } |
120 | 120 |
121 double CJS_PublicMethods::AF_Simple(const FX_WCHAR* sFuction, | 121 double CJS_PublicMethods::AF_Simple(const FX_WCHAR* sFuction, |
122 double dValue1, | 122 double dValue1, |
123 double dValue2) { | 123 double dValue2) { |
124 if (FXSYS_wcsicmp(sFuction, L"AVG") == 0 || | 124 if (FXSYS_wcsicmp(sFuction, L"AVG") == 0 || |
125 FXSYS_wcsicmp(sFuction, L"SUM") == 0) { | 125 FXSYS_wcsicmp(sFuction, L"SUM") == 0) { |
126 return dValue1 + dValue2; | 126 return dValue1 + dValue2; |
127 } | 127 } |
(...skipping 1762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1890 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); | 1890 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); |
1891 } | 1891 } |
1892 | 1892 |
1893 if (nums.GetLength() > 0) | 1893 if (nums.GetLength() > 0) |
1894 vRet = nums; | 1894 vRet = nums; |
1895 else | 1895 else |
1896 vRet.SetNull(); | 1896 vRet.SetNull(); |
1897 | 1897 |
1898 return TRUE; | 1898 return TRUE; |
1899 } | 1899 } |
OLD | NEW |