| 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 "../../include/javascript/JavaScript.h" | 7 #include "../../include/javascript/JavaScript.h" |
| 8 #include "../../include/javascript/IJavaScript.h" | 8 #include "../../include/javascript/IJavaScript.h" |
| 9 #include "../../include/javascript/JS_Define.h" | 9 #include "../../include/javascript/JS_Define.h" |
| 10 #include "../../include/javascript/JS_Object.h" | 10 #include "../../include/javascript/JS_Object.h" |
| 11 #include "../../include/javascript/JS_Value.h" | 11 #include "../../include/javascript/JS_Value.h" |
| 12 #include "../../include/javascript/util.h" | 12 #include "../../include/javascript/util.h" |
| 13 #include "../../include/javascript/PublicMethods.h" | 13 #include "../../include/javascript/PublicMethods.h" |
| 14 #include "../../include/javascript/resource.h" | 14 #include "../../include/javascript/resource.h" |
| 15 #include "../../include/javascript/JS_Context.h" | 15 #include "../../include/javascript/JS_Context.h" |
| 16 #include "../../include/javascript/JS_EventHandler.h" | 16 #include "../../include/javascript/JS_EventHandler.h" |
| 17 #include "../../include/javascript/JS_Runtime.h" | 17 #include "../../include/javascript/JS_Runtime.h" |
| 18 | 18 |
| 19 #if _FX_OS_ == _FX_ANDROID_ | 19 #if _FX_OS_ == _FX_ANDROID_ |
| 20 #include <ctype.h> | 20 #include <ctype.h> |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 static v8::Isolate* GetIsolate(IFXJS_Context* cc) | 23 static v8::Isolate* GetIsolate(IFXJS_Context* cc) |
| 24 { | 24 { |
| 25 » CJS_Context* pContext = (CJS_Context *)cc; | 25 CJS_Context* pContext = (CJS_Context *)cc; |
| 26 » ASSERT(pContext != NULL); | 26 ASSERT(pContext != NULL); |
| 27 | 27 |
| 28 » CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 28 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 29 » ASSERT(pRuntime != NULL); | 29 ASSERT(pRuntime != NULL); |
| 30 | 30 |
| 31 » return pRuntime->GetIsolate(); | 31 return pRuntime->GetIsolate(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 BEGIN_JS_STATIC_CONST(CJS_Util) | 34 BEGIN_JS_STATIC_CONST(CJS_Util) |
| 35 END_JS_STATIC_CONST() | 35 END_JS_STATIC_CONST() |
| 36 | 36 |
| 37 BEGIN_JS_STATIC_PROP(CJS_Util) | 37 BEGIN_JS_STATIC_PROP(CJS_Util) |
| 38 END_JS_STATIC_PROP() | 38 END_JS_STATIC_PROP() |
| 39 | 39 |
| 40 BEGIN_JS_STATIC_METHOD(CJS_Util) | 40 BEGIN_JS_STATIC_METHOD(CJS_Util) |
| 41 » JS_STATIC_METHOD_ENTRY(printd) | 41 JS_STATIC_METHOD_ENTRY(printd) |
| 42 » JS_STATIC_METHOD_ENTRY(printf) | 42 JS_STATIC_METHOD_ENTRY(printf) |
| 43 » JS_STATIC_METHOD_ENTRY(printx) | 43 JS_STATIC_METHOD_ENTRY(printx) |
| 44 » JS_STATIC_METHOD_ENTRY(scand) | 44 JS_STATIC_METHOD_ENTRY(scand) |
| 45 » JS_STATIC_METHOD_ENTRY(byteToChar) | 45 JS_STATIC_METHOD_ENTRY(byteToChar) |
| 46 END_JS_STATIC_METHOD() | 46 END_JS_STATIC_METHOD() |
| 47 | 47 |
| 48 IMPLEMENT_JS_CLASS(CJS_Util,util) | 48 IMPLEMENT_JS_CLASS(CJS_Util,util) |
| 49 | 49 |
| 50 util::util(CJS_Object *pJSObject) : CJS_EmbedObj(pJSObject) | 50 util::util(CJS_Object *pJSObject) : CJS_EmbedObj(pJSObject) |
| 51 { | 51 { |
| 52 } | 52 } |
| 53 | 53 |
| 54 util::~util(void) | 54 util::~util(void) |
| 55 { | 55 { |
| 56 } | 56 } |
| 57 | 57 |
| 58 | 58 |
| 59 struct stru_TbConvert | 59 struct stru_TbConvert |
| 60 { | 60 { |
| 61 » const FX_WCHAR* lpszJSMark; | 61 const FX_WCHAR* lpszJSMark; |
| 62 » const FX_WCHAR* lpszCppMark; | 62 const FX_WCHAR* lpszCppMark; |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 const stru_TbConvert fcTable[] = { | 65 const stru_TbConvert fcTable[] = { |
| 66 » { L"mmmm", L"%B" }, | 66 { L"mmmm", L"%B" }, |
| 67 » { L"mmm", L"%b" }, | 67 { L"mmm", L"%b" }, |
| 68 » { L"mm", L"%m" }, | 68 { L"mm", L"%m" }, |
| 69 » //"m" | 69 //"m" |
| 70 » { L"dddd", L"%A" }, | 70 { L"dddd", L"%A" }, |
| 71 » { L"ddd", L"%a" }, | 71 { L"ddd", L"%a" }, |
| 72 » { L"dd", L"%d" }, | 72 { L"dd", L"%d" }, |
| 73 » //"d", "%w", | 73 //"d", "%w", |
| 74 » { L"yyyy", L"%Y" }, | 74 { L"yyyy", L"%Y" }, |
| 75 » { L"yy", L"%y" }, | 75 { L"yy", L"%y" }, |
| 76 » { L"HH", L"%H" }, | 76 { L"HH", L"%H" }, |
| 77 » //"H" | 77 //"H" |
| 78 » { L"hh", L"%I" }, | 78 { L"hh", L"%I" }, |
| 79 » //"h" | 79 //"h" |
| 80 » { L"MM", L"%M" }, | 80 { L"MM", L"%M" }, |
| 81 » //"M" | 81 //"M" |
| 82 » { L"ss", L"%S" }, | 82 { L"ss", L"%S" }, |
| 83 » //"s | 83 //"s |
| 84 » { L"TT", L"%p" }, | 84 { L"TT", L"%p" }, |
| 85 » //"t" | 85 //"t" |
| 86 #if defined(_WIN32) | 86 #if defined(_WIN32) |
| 87 » { L"tt", L"%p" }, | 87 { L"tt", L"%p" }, |
| 88 » { L"h", L"%#I" }, | 88 { L"h", L"%#I" }, |
| 89 #else | 89 #else |
| 90 » { L"tt", L"%P" }, | 90 { L"tt", L"%P" }, |
| 91 » { L"h", L"%l" }, | 91 { L"h", L"%l" }, |
| 92 #endif | 92 #endif |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 #define UTIL_INT» » » 0 | 95 #define UTIL_INT 0 |
| 96 #define UTIL_DOUBLE» » » 1 | 96 #define UTIL_DOUBLE 1 |
| 97 #define UTIL_STRING» » » 2 | 97 #define UTIL_STRING 2 |
| 98 | 98 |
| 99 int util::ParstDataType(std::wstring* sFormat) | 99 int util::ParstDataType(std::wstring* sFormat) |
| 100 { | 100 { |
| 101 size_t i = 0; | 101 bool bPercent = FALSE; |
| 102 » bool bPercent = FALSE; | 102 for (size_t i = 0; i < sFormat->length(); ++i) |
| 103 » for (i=0; i<sFormat->length(); ++i) | 103 { |
| 104 » { | 104 wchar_t c = (*sFormat)[i]; |
| 105 » » wchar_t c = (*sFormat)[i]; | 105 if (c == L'%') |
| 106 » » if (c == L'%') | 106 { |
| 107 » » { | 107 bPercent = true; |
| 108 » » » bPercent = true; | 108 continue; |
| 109 » » » continue; | 109 } |
| 110 » » } | 110 |
| 111 | 111 if (bPercent) |
| 112 » » if (bPercent) | 112 { |
| 113 » » { | 113 if (c == L'c' || c == L'C' || c == L'd' || c == L'i' || c == L'o' ||
c == L'u' || c == L'x' || c == L'X') |
| 114 » » » if (c == L'c' || c == L'C' || c == L'd' || c == L'i' ||
c == L'o' || c == L'u' || c == L'x' || c == L'X') | 114 { |
| 115 » » » { | 115 return UTIL_INT; |
| 116 » » » » return UTIL_INT; | 116 } |
| 117 » » » } | 117 if (c == L'e' || c == L'E' || c == L'f' || c == L'g' || c == L'G') |
| 118 » » » else if (c == L'e' || c == L'E' || c == L'f' || c == L'g
' || c == L'G') | 118 { |
| 119 » » » { | 119 return UTIL_DOUBLE; |
| 120 » » » » return UTIL_DOUBLE; | 120 } |
| 121 » » » } | 121 if (c == L's' || c == L'S') |
| 122 » » » else if (c == L's' || c == L'S') | 122 { |
| 123 » » » { | 123 // Map s to S since we always deal internally |
| 124 » » » » // Map s to S since we always deal internally | 124 // with wchar_t strings. |
| 125 » » » » // with wchar_t strings. | 125 (*sFormat)[i] = L'S'; |
| 126 » » » » (*sFormat)[i] = L'S'; | 126 return UTIL_STRING; |
| 127 » » » » return UTIL_STRING; | 127 } |
| 128 » » » } | 128 if (c == L'.' || c == L'+' || c == L'-' || c == L'#' || c == L' ' ||
CJS_PublicMethods::IsDigit(c)) |
| 129 » » » else if (c == L'.' || c == L'+' || c == L'-' || c == L'#
' || c == L' ' || CJS_PublicMethods::IsDigit(c)) | 129 { |
| 130 » » » { | 130 continue; |
| 131 » » » » continue; | 131 } |
| 132 » » » } | 132 break; |
| 133 » » » else break; | 133 } |
| 134 » » } | 134 } |
| 135 » } | 135 |
| 136 | 136 return -1; |
| 137 » return -1; | |
| 138 } | 137 } |
| 139 | 138 |
| 140 FX_BOOL util::printf(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) | 139 FX_BOOL util::printf(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) |
| 141 { | 140 { |
| 142 » int iSize = params.size(); | 141 int iSize = params.size(); |
| 143 » if (iSize < 1) | 142 if (iSize < 1) |
| 144 » » return FALSE; | 143 return FALSE; |
| 145 » std::wstring c_ConvChar(params[0].ToCFXWideString().c_str()); | 144 std::wstring c_ConvChar(params[0].ToCFXWideString().c_str()); |
| 146 » std::vector<std::wstring> c_strConvers; | 145 std::vector<std::wstring> c_strConvers; |
| 147 » int iOffset = 0; | 146 int iOffset = 0; |
| 148 » int iOffend = 0; | 147 int iOffend = 0; |
| 149 » c_ConvChar.insert(c_ConvChar.begin(),L'S'); | 148 c_ConvChar.insert(c_ConvChar.begin(),L'S'); |
| 150 » while(iOffset != -1) | 149 while(iOffset != -1) |
| 151 » { | 150 { |
| 152 » » iOffend = c_ConvChar.find(L"%",iOffset+1); | 151 iOffend = c_ConvChar.find(L"%",iOffset+1); |
| 153 » » std::wstring strSub; | 152 std::wstring strSub; |
| 154 » » if (iOffend == -1) | 153 if (iOffend == -1) |
| 155 » » » strSub = c_ConvChar.substr(iOffset); | 154 strSub = c_ConvChar.substr(iOffset); |
| 156 » » else | 155 else |
| 157 » » » strSub = c_ConvChar.substr(iOffset ,iOffend - iOffset); | 156 strSub = c_ConvChar.substr(iOffset ,iOffend - iOffset); |
| 158 » » c_strConvers.push_back(strSub); | 157 c_strConvers.push_back(strSub); |
| 159 » » iOffset = iOffend ; | 158 iOffset = iOffend ; |
| 160 » } | 159 } |
| 161 | 160 |
| 162 » std::wstring c_strResult; | 161 std::wstring c_strResult; |
| 163 | 162 |
| 164 » //for(int iIndex = 1;iIndex < params.size();iIndex++) | 163 //for(int iIndex = 1;iIndex < params.size();iIndex++) |
| 165 » std::wstring c_strFormat; | 164 std::wstring c_strFormat; |
| 166 » for(int iIndex = 0;iIndex < (int)c_strConvers.size();iIndex++) | 165 for(int iIndex = 0;iIndex < (int)c_strConvers.size();iIndex++) |
| 167 » { | 166 { |
| 168 » » c_strFormat = c_strConvers[iIndex]; | 167 c_strFormat = c_strConvers[iIndex]; |
| 169 » » if (iIndex == 0) | 168 if (iIndex == 0) |
| 170 » » { | 169 { |
| 171 » » » c_strResult = c_strFormat; | 170 c_strResult = c_strFormat; |
| 172 » » » continue; | 171 continue; |
| 173 » » } | 172 } |
| 174 | 173 |
| 175 | 174 |
| 176 » » CFX_WideString strSegment; | 175 CFX_WideString strSegment; |
| 177 » » if (iIndex >= iSize) { | 176 if (iIndex >= iSize) { |
| 178 » » » c_strResult += c_strFormat; | 177 c_strResult += c_strFormat; |
| 179 » » » continue; | 178 continue; |
| 180 » » } | 179 } |
| 181 | 180 |
| 182 » » switch (ParstDataType(&c_strFormat)) | 181 switch (ParstDataType(&c_strFormat)) |
| 183 » » { | 182 { |
| 184 » » » case UTIL_INT: | 183 case UTIL_INT: |
| 185 » » » » strSegment.Format(c_strFormat.c_str(), params[iI
ndex].ToInt()); | 184 strSegment.Format(c_strFormat.c_str(), params[iIndex].ToInt()); |
| 186 » » » » break; | 185 break; |
| 187 » » » case UTIL_DOUBLE: | 186 case UTIL_DOUBLE: |
| 188 » » » » strSegment.Format(c_strFormat.c_str(), params[iI
ndex].ToDouble()); | 187 strSegment.Format(c_strFormat.c_str(), params[iIndex].ToDouble()
); |
| 189 » » » » break; | 188 break; |
| 190 » » » case UTIL_STRING: | 189 case UTIL_STRING: |
| 191 » » » » strSegment.Format(c_strFormat.c_str(), params[iI
ndex].ToCFXWideString().c_str()); | 190 strSegment.Format(c_strFormat.c_str(), params[iIndex].ToCFXWideS
tring().c_str()); |
| 192 » » » » break; | 191 break; |
| 193 » » » default: | 192 default: |
| 194 » » » » strSegment.Format(L"%S", c_strFormat.c_str()); | 193 strSegment.Format(L"%S", c_strFormat.c_str()); |
| 195 » » » » break; | 194 break; |
| 196 » » } | 195 } |
| 197 » » c_strResult += strSegment.GetBuffer(strSegment.GetLength()+1); | 196 c_strResult += strSegment.GetBuffer(strSegment.GetLength()+1); |
| 198 » } | 197 } |
| 199 | 198 |
| 200 » c_strResult.erase(c_strResult.begin()); | 199 c_strResult.erase(c_strResult.begin()); |
| 201 » vRet = c_strResult.c_str(); | 200 vRet = c_strResult.c_str(); |
| 202 » return TRUE; | 201 return TRUE; |
| 203 } | 202 } |
| 204 | 203 |
| 205 FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) | 204 FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) |
| 206 { | 205 { |
| 207 » v8::Isolate* isolate = GetIsolate(cc); | 206 v8::Isolate* isolate = GetIsolate(cc); |
| 208 | 207 |
| 209 » int iSize = params.size(); | 208 int iSize = params.size(); |
| 210 » if (iSize < 2) | 209 if (iSize < 2) |
| 211 » » return FALSE; | 210 return FALSE; |
| 212 | 211 |
| 213 » CJS_Value p1(isolate); | 212 CJS_Value p1(isolate); |
| 214 » p1 = params[0]; | 213 p1 = params[0]; |
| 215 | 214 |
| 216 » CJS_Value p2 = params[1]; | 215 CJS_Value p2 = params[1]; |
| 217 » CJS_Date jsDate(isolate); | 216 CJS_Date jsDate(isolate); |
| 218 » if (!p2.ConvertToDate(jsDate)) | 217 if (!p2.ConvertToDate(jsDate)) |
| 219 » { | 218 { |
| 220 » » sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT1
); | 219 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT1); |
| 221 » » return FALSE; | 220 return FALSE; |
| 222 » } | 221 } |
| 223 | 222 |
| 224 » if (!jsDate.IsValidDate()) | 223 if (!jsDate.IsValidDate()) |
| 225 » { | 224 { |
| 226 » » sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2
); | 225 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2); |
| 227 » » return FALSE; | 226 return FALSE; |
| 228 » } | 227 } |
| 229 | 228 |
| 230 » if (p1.GetType() == VT_number) | 229 if (p1.GetType() == VT_number) |
| 231 » { | 230 { |
| 232 » » int nFormat = p1.ToInt(); | 231 int nFormat = p1.ToInt(); |
| 233 » » CFX_WideString swResult; | 232 CFX_WideString swResult; |
| 234 | 233 |
| 235 » » switch (nFormat) | 234 switch (nFormat) |
| 236 » » { | 235 { |
| 237 » » case 0: | 236 case 0: |
| 238 » » » swResult.Format(L"D:%04d%02d%02d%02d%02d%02d", | 237 swResult.Format(L"D:%04d%02d%02d%02d%02d%02d", |
| 239 » » » » jsDate.GetYear(), | 238 jsDate.GetYear(), |
| 240 » » » » jsDate.GetMonth() + 1, | 239 jsDate.GetMonth() + 1, |
| 241 » » » » jsDate.GetDay(), | 240 jsDate.GetDay(), |
| 242 » » » » jsDate.GetHours(), | 241 jsDate.GetHours(), |
| 243 » » » » jsDate.GetMinutes(), | 242 jsDate.GetMinutes(), |
| 244 » » » » jsDate.GetSeconds()); | 243 jsDate.GetSeconds()); |
| 245 » » » break; | 244 break; |
| 246 » » case 1: | 245 case 1: |
| 247 » » » swResult.Format(L"%04d.%02d.%02d %02d:%02d:%02d", | 246 swResult.Format(L"%04d.%02d.%02d %02d:%02d:%02d", |
| 248 » » » » jsDate.GetYear(), | 247 jsDate.GetYear(), |
| 249 » » » » jsDate.GetMonth() + 1, | 248 jsDate.GetMonth() + 1, |
| 250 » » » » jsDate.GetDay(), | 249 jsDate.GetDay(), |
| 251 » » » » jsDate.GetHours(), | 250 jsDate.GetHours(), |
| 252 » » » » jsDate.GetMinutes(), | 251 jsDate.GetMinutes(), |
| 253 » » » » jsDate.GetSeconds()); | 252 jsDate.GetSeconds()); |
| 254 » » » break; | 253 break; |
| 255 » » case 2: | 254 case 2: |
| 256 » » » swResult.Format(L"%04d/%02d/%02d %02d:%02d:%02d", | 255 swResult.Format(L"%04d/%02d/%02d %02d:%02d:%02d", |
| 257 » » » » jsDate.GetYear(), | 256 jsDate.GetYear(), |
| 258 » » » » jsDate.GetMonth() + 1, | 257 jsDate.GetMonth() + 1, |
| 259 » » » » jsDate.GetDay(), | 258 jsDate.GetDay(), |
| 260 » » » » jsDate.GetHours(), | 259 jsDate.GetHours(), |
| 261 » » » » jsDate.GetMinutes(), | 260 jsDate.GetMinutes(), |
| 262 » » » » jsDate.GetSeconds()); | 261 jsDate.GetSeconds()); |
| 263 » » » break; | 262 break; |
| 264 » » default: | 263 default: |
| 265 » » » return FALSE; | 264 return FALSE; |
| 266 » » } | 265 } |
| 267 | 266 |
| 268 » » vRet = swResult.c_str(); | 267 vRet = swResult.c_str(); |
| 269 » » return TRUE; | 268 return TRUE; |
| 270 » } | 269 } |
| 271 » else if (p1.GetType() == VT_string) | 270 if (p1.GetType() == VT_string) |
| 272 » { | 271 { |
| 273 » » std::basic_string<wchar_t> cFormat = p1.ToCFXWideString().c_str(
); | 272 std::basic_string<wchar_t> cFormat = p1.ToCFXWideString().c_str(); |
| 274 | 273 |
| 275 » » bool bXFAPicture = false; | 274 bool bXFAPicture = false; |
| 276 » » if (iSize > 2) | 275 if (iSize > 2) |
| 277 » » { | 276 { |
| 278 » » » bXFAPicture = params[2].ToBool(); | 277 bXFAPicture = params[2].ToBool(); |
| 279 » » } | 278 } |
| 280 | 279 |
| 281 » » if (bXFAPicture) | 280 if (bXFAPicture) |
| 282 » » { | 281 { |
| 283 » » » return FALSE; //currently, it doesn't support XFAPicture
. | 282 return FALSE; //currently, it doesn't support XFAPicture. |
| 284 » » } | 283 } |
| 285 | 284 |
| 286 int iIndex; | 285 int iIndex; |
| 287 » » for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIn
dex++) | 286 for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIndex++) |
| 288 » » { | 287 { |
| 289 » » » int iStart = 0; | 288 int iStart = 0; |
| 290 » » » int iEnd; | 289 int iEnd; |
| 291 » » » while((iEnd = cFormat.find(fcTable[iIndex].lpszJSMark, i
Start)) != -1) | 290 while((iEnd = cFormat.find(fcTable[iIndex].lpszJSMark, iStart)) != -
1) |
| 292 » » » { | 291 { |
| 293 » » » » cFormat.replace(iEnd, FXSYS_wcslen(fcTable[iInde
x].lpszJSMark), fcTable[iIndex].lpszCppMark); | 292 cFormat.replace(iEnd, FXSYS_wcslen(fcTable[iIndex].lpszJSMark),
fcTable[iIndex].lpszCppMark); |
| 294 » » » » iStart = iEnd; | 293 iStart = iEnd; |
| 295 » » » } | 294 } |
| 296 » » } | 295 } |
| 297 | 296 |
| 298 » » int iYear,iMonth,iDay,iHour,iMin,iSec; | 297 int iYear,iMonth,iDay,iHour,iMin,iSec; |
| 299 » » iYear = jsDate.GetYear(); | 298 iYear = jsDate.GetYear(); |
| 300 » » iMonth = jsDate.GetMonth(); | 299 iMonth = jsDate.GetMonth(); |
| 301 » » iDay = jsDate.GetDay(); | 300 iDay = jsDate.GetDay(); |
| 302 » » iHour = jsDate.GetHours(); | 301 iHour = jsDate.GetHours(); |
| 303 » » iMin = jsDate.GetMinutes(); | 302 iMin = jsDate.GetMinutes(); |
| 304 » » iSec = jsDate.GetSeconds(); | 303 iSec = jsDate.GetSeconds(); |
| 305 | 304 |
| 306 » » struct tm time = {}; | 305 struct tm time = {}; |
| 307 » » time.tm_year = iYear-1900; | 306 time.tm_year = iYear-1900; |
| 308 » » time.tm_mon = iMonth; | 307 time.tm_mon = iMonth; |
| 309 » » time.tm_mday = iDay; | 308 time.tm_mday = iDay; |
| 310 » » time.tm_hour = iHour; | 309 time.tm_hour = iHour; |
| 311 » » time.tm_min = iMin; | 310 time.tm_min = iMin; |
| 312 » » time.tm_sec = iSec; | 311 time.tm_sec = iSec; |
| 313 » » //COleDateTime cppTm(iYear,iMonth+1,iDay,iHour,iMin,iSec); | 312 |
| 314 » » //CString strFormat = cppTm.Format(cFormat.c_str()); | 313 struct stru_TbConvertAd |
| 315 | 314 { |
| 316 » » struct stru_TbConvertAd | 315 const FX_WCHAR* lpszJSMark; |
| 317 » » { | 316 int iValue; |
| 318 » » » const FX_WCHAR* lpszJSMark; | 317 }; |
| 319 » » » int iValue; | 318 |
| 320 » » }; | 319 stru_TbConvertAd cTableAd[] ={ |
| 321 | 320 { L"m", iMonth+1 }, |
| 322 » » stru_TbConvertAd cTableAd[] ={ | 321 { L"d", iDay }, |
| 323 » » » { L"m", iMonth+1 }, | 322 { L"H", iHour }, |
| 324 » » » { L"d", iDay }, | 323 { L"h", iHour>12?iHour-12:iHour }, |
| 325 » » » { L"H", iHour }, | 324 { L"M", iMin }, |
| 326 » » » { L"h", iHour>12?iHour-12:iHour }, | 325 { L"s", iSec }, |
| 327 » » » { L"M", iMin }, | 326 }; |
| 328 » » » { L"s", iSec }, | 327 |
| 329 » » }; | 328 for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd);iIndex++
) |
| 330 | 329 { |
| 331 » » //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1); | 330 wchar_t tszValue[10]; |
| 332 » » for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd);
iIndex++) | 331 CFX_WideString sValue; |
| 333 » » { | 332 sValue.Format(L"%d",cTableAd[iIndex].iValue); |
| 334 » » » wchar_t tszValue[10]; | 333 memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+1), |
| 335 » » » //_itot(cTableAd[iIndex].iValue,tszValue,10); | |
| 336 » » » CFX_WideString sValue; | |
| 337 » » » sValue.Format(L"%d",cTableAd[iIndex].iValue); | |
| 338 » » » memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetL
ength()+1), | |
| 339 (sValue.GetLength()+1)*sizeof(wchar_t)); | 334 (sValue.GetLength()+1)*sizeof(wchar_t)); |
| 340 | 335 |
| 341 » » » //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d"); | 336 int iStart = 0; |
| 342 » » » //strFormat.Format(strFormat,cTableAd[iIndex].iValue); | 337 int iEnd; |
| 343 » » » int iStart = 0; | 338 while((iEnd = cFormat.find(cTableAd[iIndex].lpszJSMark, iStart)) !=
-1) |
| 344 » » » int iEnd; | 339 { |
| 345 » » » while((iEnd = cFormat.find(cTableAd[iIndex].lpszJSMark,
iStart)) != -1) | 340 if (iEnd > 0) |
| 346 » » » { | 341 { |
| 347 » » » » if (iEnd > 0) | 342 if (cFormat[iEnd-1] == L'%') |
| 348 » » » » { | 343 { |
| 349 » » » » » if (cFormat[iEnd-1] == L'%') | 344 iStart = iEnd+1; |
| 350 » » » » » { | 345 continue; |
| 351 » » » » » » iStart = iEnd+1; | 346 } |
| 352 » » » » » » continue; | 347 } |
| 353 » » » » » } | 348 cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[iIndex].lpszJSMark),
tszValue); |
| 354 » » » » } | 349 iStart = iEnd; |
| 355 » » » » cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[iInd
ex].lpszJSMark), tszValue); | 350 } |
| 356 » » » » iStart = iEnd; | 351 } |
| 357 » » » } | 352 |
| 358 » » } | 353 CFX_WideString strFormat; |
| 359 | 354 wchar_t buf[64] = {}; |
| 360 » » CFX_WideString strFormat; | 355 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); |
| 361 //» » strFormat.Format(L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour
, iMin, iSec); | 356 cFormat = buf; |
| 362 //» » CString strFormat = cppTm.Format(cFormat.c_str()); | 357 vRet = cFormat.c_str(); |
| 363 » » wchar_t buf[64] = {}; | 358 return TRUE; |
| 364 » » strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); | 359 } |
| 365 » » cFormat = buf; | 360 return FALSE; |
| 366 » » vRet = cFormat.c_str(); | |
| 367 » » //rtRet = strFormat.GetBuffer(strFormat.GetLength()+1); | |
| 368 » » return TRUE; | |
| 369 » } | |
| 370 » return FALSE; | |
| 371 } | 361 } |
| 372 | 362 |
| 373 void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPictur
e, std::wstring &cPurpose) | 363 void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPictur
e, std::wstring &cPurpose) |
| 374 { | 364 { |
| 375 » std::wstring cFormat = cFormat2; | 365 std::wstring cFormat = cFormat2; |
| 376 | 366 |
| 377 » if (bXFAPicture) | 367 if (bXFAPicture) |
| 378 » { | 368 { |
| 379 » » return ; //currently, it doesn't support XFAPicture. | 369 return ; //currently, it doesn't support XFAPicture. |
| 380 » } | 370 } |
| 381 | 371 |
| 382 int iIndex; | 372 int iIndex; |
| 383 » for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIndex++) | 373 for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIndex++) |
| 384 » { | 374 { |
| 385 » » int iStart = 0; | 375 int iStart = 0; |
| 386 » » int iEnd; | 376 int iEnd; |
| 387 » » while((iEnd = cFormat.find(fcTable[iIndex].lpszJSMark, iStart))
!= -1) | 377 while((iEnd = cFormat.find(fcTable[iIndex].lpszJSMark, iStart)) != -1) |
| 388 » » { | 378 { |
| 389 » » » cFormat.replace(iEnd,FXSYS_wcslen(fcTable[iIndex].lpszJS
Mark), fcTable[iIndex].lpszCppMark); | 379 cFormat.replace(iEnd,FXSYS_wcslen(fcTable[iIndex].lpszJSMark), fcTab
le[iIndex].lpszCppMark); |
| 390 » » » iStart = iEnd; | 380 iStart = iEnd; |
| 391 » » } | 381 } |
| 392 » } | 382 } |
| 393 | 383 |
| 394 » int iYear,iMonth,iDay,iHour,iMin,iSec; | 384 int iYear,iMonth,iDay,iHour,iMin,iSec; |
| 395 » iYear = jsDate.GetYear(); | 385 iYear = jsDate.GetYear(); |
| 396 » iMonth = jsDate.GetMonth(); | 386 iMonth = jsDate.GetMonth(); |
| 397 » iDay = jsDate.GetDay(); | 387 iDay = jsDate.GetDay(); |
| 398 » iHour = jsDate.GetHours(); | 388 iHour = jsDate.GetHours(); |
| 399 » iMin = jsDate.GetMinutes(); | 389 iMin = jsDate.GetMinutes(); |
| 400 » iSec = jsDate.GetSeconds(); | 390 iSec = jsDate.GetSeconds(); |
| 401 | 391 |
| 402 » struct tm time = {}; | 392 struct tm time = {}; |
| 403 » time.tm_year = iYear-1900; | 393 time.tm_year = iYear-1900; |
| 404 » time.tm_mon = iMonth; | 394 time.tm_mon = iMonth; |
| 405 » time.tm_mday = iDay; | 395 time.tm_mday = iDay; |
| 406 » time.tm_hour = iHour; | 396 time.tm_hour = iHour; |
| 407 » time.tm_min = iMin; | 397 time.tm_min = iMin; |
| 408 » time.tm_sec = iSec; | 398 time.tm_sec = iSec; |
| 409 //» COleDateTime cppTm(iYear,iMonth+1,iDay,iHour,iMin,iSec); | 399 // COleDateTime cppTm(iYear,iMonth+1,iDay,iHour,iMin,iSec); |
| 410 » //CString strFormat = cppTm.Format(cFormat.c_str()); | 400 //CString strFormat = cppTm.Format(cFormat.c_str()); |
| 411 | 401 |
| 412 » struct stru_TbConvertAd | 402 struct stru_TbConvertAd |
| 413 » { | 403 { |
| 414 » » const FX_WCHAR* lpszJSMark; | 404 const FX_WCHAR* lpszJSMark; |
| 415 » » int iValue; | 405 int iValue; |
| 416 » }; | 406 }; |
| 417 | 407 |
| 418 » stru_TbConvertAd cTableAd[] ={ | 408 stru_TbConvertAd cTableAd[] ={ |
| 419 » » { L"m", iMonth+1 }, | 409 { L"m", iMonth+1 }, |
| 420 » » { L"d", iDay }, | 410 { L"d", iDay }, |
| 421 » » { L"H", iHour }, | 411 { L"H", iHour }, |
| 422 » » { L"h", iHour>12?iHour-12:iHour }, | 412 { L"h", iHour>12?iHour-12:iHour }, |
| 423 » » { L"M", iMin }, | 413 { L"M", iMin }, |
| 424 » » { L"s", iSec }, | 414 { L"s", iSec }, |
| 425 » }; | 415 }; |
| 426 | 416 |
| 427 » //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1); | 417 //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1); |
| 428 » for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd);iIndex++
) | 418 for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd);iIndex++) |
| 429 » { | 419 { |
| 430 » » wchar_t tszValue[10]; | 420 wchar_t tszValue[10]; |
| 431 » » //_itot(cTableAd[iIndex].iValue,tszValue,10); | 421 //_itot(cTableAd[iIndex].iValue,tszValue,10); |
| 432 » » CFX_WideString sValue; | 422 CFX_WideString sValue; |
| 433 » » sValue.Format(L"%d",cTableAd[iIndex].iValue); | 423 sValue.Format(L"%d",cTableAd[iIndex].iValue); |
| 434 » » memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+
1),sValue.GetLength()*sizeof(wchar_t)); | 424 memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+1),sValu
e.GetLength()*sizeof(wchar_t)); |
| 435 | 425 |
| 436 | 426 |
| 437 » » //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d"); | 427 //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d"); |
| 438 » » //strFormat.Format(strFormat,cTableAd[iIndex].iValue); | 428 //strFormat.Format(strFormat,cTableAd[iIndex].iValue); |
| 439 » » int iStart = 0; | 429 int iStart = 0; |
| 440 » » int iEnd; | 430 int iEnd; |
| 441 » » while((iEnd = cFormat.find(cTableAd[iIndex].lpszJSMark, iStart))
!= -1) | 431 while((iEnd = cFormat.find(cTableAd[iIndex].lpszJSMark, iStart)) != -1) |
| 442 » » { | 432 { |
| 443 » » » if (iEnd > 0) | 433 if (iEnd > 0) |
| 444 » » » { | 434 { |
| 445 » » » » if (cFormat[iEnd-1] == L'%') | 435 if (cFormat[iEnd-1] == L'%') |
| 446 » » » » { | 436 { |
| 447 » » » » » iStart = iEnd+1; | 437 iStart = iEnd+1; |
| 448 » » » » » continue; | 438 continue; |
| 449 » » » » } | 439 } |
| 450 » » » } | 440 } |
| 451 » » » cFormat.replace(iEnd,FXSYS_wcslen(cTableAd[iIndex].lpszJ
SMark),tszValue); | 441 cFormat.replace(iEnd,FXSYS_wcslen(cTableAd[iIndex].lpszJSMark),tszVa
lue); |
| 452 » » » iStart = iEnd; | 442 iStart = iEnd; |
| 453 » » } | 443 } |
| 454 » } | 444 } |
| 455 | 445 |
| 456 » CFX_WideString strFormat; | 446 CFX_WideString strFormat; |
| 457 » wchar_t buf[64] = {}; | 447 wchar_t buf[64] = {}; |
| 458 » strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); | 448 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); |
| 459 » cFormat = buf; | 449 cFormat = buf; |
| 460 » cPurpose = cFormat; | 450 cPurpose = cFormat; |
| 461 } | 451 } |
| 462 | 452 |
| 463 FX_BOOL util::printx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) | 453 FX_BOOL util::printx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) |
| 464 { | 454 { |
| 465 » int iSize = params.size(); | 455 int iSize = params.size(); |
| 466 » if (iSize<2) | 456 if (iSize<2) |
| 467 » » return FALSE; | 457 return FALSE; |
| 468 » CFX_WideString sFormat = params[0].ToCFXWideString(); | 458 CFX_WideString sFormat = params[0].ToCFXWideString(); |
| 469 » CFX_WideString sSource = params[1].ToCFXWideString(); | 459 CFX_WideString sSource = params[1].ToCFXWideString(); |
| 470 » std::string cFormat = CFX_ByteString::FromUnicode(sFormat).c_str(); | 460 std::string cFormat = CFX_ByteString::FromUnicode(sFormat).c_str(); |
| 471 » std::string cSource = CFX_ByteString::FromUnicode(sSource).c_str(); | 461 std::string cSource = CFX_ByteString::FromUnicode(sSource).c_str(); |
| 472 » std::string cDest; | 462 std::string cDest; |
| 473 » printx(cFormat,cSource,cDest); | 463 printx(cFormat,cSource,cDest); |
| 474 » vRet = cDest.c_str(); | 464 vRet = cDest.c_str(); |
| 475 » return TRUE; | 465 return TRUE; |
| 476 } | 466 } |
| 477 | 467 |
| 478 void util::printx(const std::string &cFormat,const std::string &cSource2,std::st
ring &cPurpose) | 468 void util::printx(const std::string &cFormat,const std::string &cSource2,std::st
ring &cPurpose) |
| 479 { | 469 { |
| 480 » std::string cSource(cSource2); | 470 std::string cSource(cSource2); |
| 481 » if (!cPurpose.empty()) | 471 if (!cPurpose.empty()) |
| 482 » » //cPurpose.clear(); | 472 //cPurpose.clear(); |
| 483 » » cPurpose.erase(); | 473 cPurpose.erase(); |
| 484 » int itSource = 0; | 474 int itSource = 0; |
| 485 » int iSize = cSource.size(); | 475 int iSize = cSource.size(); |
| 486 » for(int iIndex = 0; iIndex < (int)cFormat.size() && itSource<iSize; iInd
ex++) | 476 for(int iIndex = 0; iIndex < (int)cFormat.size() && itSource<iSize; iIndex++
) |
| 487 » { | 477 { |
| 488 » » char letter = cFormat[iIndex]; | 478 char letter = cFormat[iIndex]; |
| 489 » » switch(letter) | 479 switch(letter) |
| 490 » » { | 480 { |
| 491 » » case '?': | 481 case '?': |
| 492 » » » //cPurpose.push_back(cSource[itSource]); | 482 //cPurpose.push_back(cSource[itSource]); |
| 493 » » » cPurpose += cSource[itSource]; | 483 cPurpose += cSource[itSource]; |
| 494 » » » itSource++; | 484 itSource++; |
| 495 » » » break; | 485 break; |
| 496 » » case 'X': | 486 case 'X': |
| 497 » » » { | 487 { |
| 498 » » » » while(itSource < iSize) | 488 while(itSource < iSize) |
| 499 » » » » { | 489 { |
| 500 » » » » » if ((cSource[itSource]>='0'&&cSource[itS
ource]<='9') || (cSource[itSource]>='a' && cSource[itSource]<='z') || (cSource[i
tSource]>='A' && cSource[itSource]<='Z')) | 490 if ((cSource[itSource]>='0'&&cSource[itSource]<='9') || (cSo
urce[itSource]>='a' && cSource[itSource]<='z') || (cSource[itSource]>='A' && cSo
urce[itSource]<='Z')) |
| 501 » » » » » { | 491 { |
| 502 » » » » » » //cPurpose.push_back(cSource[itS
ource]); | 492 //cPurpose.push_back(cSource[itSource]); |
| 503 » » » » » » cPurpose += cSource[itSource]; | 493 cPurpose += cSource[itSource]; |
| 504 » » » » » » itSource++; | 494 itSource++; |
| 505 » » » » » » break; | 495 break; |
| 506 » » » » » } | 496 } |
| 507 » » » » » itSource++; | 497 itSource++; |
| 508 » » » » } | 498 } |
| 509 » » » » break; | 499 break; |
| 510 » » » } | 500 } |
| 511 » » » break; | 501 break; |
| 512 » » case 'A': | 502 case 'A': |
| 513 » » » { | 503 { |
| 514 » » » » while(itSource < iSize) | 504 while(itSource < iSize) |
| 515 » » » » { | 505 { |
| 516 » » » » » if ((cSource[itSource]>='a' && cSource[i
tSource]<='z') || (cSource[itSource]>='A' && cSource[itSource]<='Z')) | 506 if ((cSource[itSource]>='a' && cSource[itSource]<='z') || (c
Source[itSource]>='A' && cSource[itSource]<='Z')) |
| 517 » » » » » { | 507 { |
| 518 » » » » » » //cPurpose.push_back(cSource[itS
ource]); | 508 //cPurpose.push_back(cSource[itSource]); |
| 519 » » » » » » cPurpose += cSource[itSource]; | 509 cPurpose += cSource[itSource]; |
| 520 » » » » » » itSource++; | 510 itSource++; |
| 521 » » » » » » break; | 511 break; |
| 522 » » » » » } | 512 } |
| 523 » » » » » itSource++; | 513 itSource++; |
| 524 » » » » } | 514 } |
| 525 » » » » break; | 515 break; |
| 526 » » » } | 516 } |
| 527 » » » break; | 517 break; |
| 528 » » case '9': | 518 case '9': |
| 529 » » » { | 519 { |
| 530 » » » » while(itSource < iSize) | 520 while(itSource < iSize) |
| 531 » » » » { | 521 { |
| 532 » » » » » if (cSource[itSource]>='0'&&cSource[itSo
urce]<='9') | 522 if (cSource[itSource]>='0'&&cSource[itSource]<='9') |
| 533 » » » » » { | 523 { |
| 534 » » » » » » //cPurpose.push_back(cSource[itS
ource]); | 524 //cPurpose.push_back(cSource[itSource]); |
| 535 » » » » » » cPurpose += cSource[itSource]; | 525 cPurpose += cSource[itSource]; |
| 536 » » » » » » itSource++; | 526 itSource++; |
| 537 » » » » » » break; | 527 break; |
| 538 » » » » » } | 528 } |
| 539 » » » » » itSource++; | 529 itSource++; |
| 540 » » » » } | 530 } |
| 541 » » » » break; | 531 break; |
| 542 » » » } | 532 } |
| 543 » » case '*': | 533 case '*': |
| 544 » » » { | 534 { |
| 545 » » » » cPurpose.append(cSource,itSource,iSize-itSource)
; | 535 cPurpose.append(cSource,itSource,iSize-itSource); |
| 546 » » » » itSource = iSize-1; | 536 itSource = iSize-1; |
| 547 » » » » break; | 537 break; |
| 548 » » » } | 538 } |
| 549 » » case '\\': | 539 case '\\': |
| 550 » » » break; | 540 break; |
| 551 » » case '>': | 541 case '>': |
| 552 » » » { | 542 { |
| 553 » » » » for(std::string::iterator it = cSource.begin();i
t != cSource.end(); it++) | 543 for(std::string::iterator it = cSource.begin();it != cSource.end
(); it++) |
| 554 » » » » { | 544 { |
| 555 » » » » » *it = toupper(*it); | 545 *it = toupper(*it); |
| 556 » » » » } | 546 } |
| 557 » » » » break; | 547 break; |
| 558 » » » } | 548 } |
| 559 » » case '<': | 549 case '<': |
| 560 » » » { | 550 { |
| 561 » » » » for(std::string::iterator it = cSource.begin();i
t != cSource.end(); it++) | 551 for(std::string::iterator it = cSource.begin();it != cSource.end
(); it++) |
| 562 » » » » { | 552 { |
| 563 » » » » » *it = tolower(*it); | 553 *it = tolower(*it); |
| 564 » » » » } | 554 } |
| 565 » » » » break; | 555 break; |
| 566 » » » } | 556 } |
| 567 » » case '=': | 557 case '=': |
| 568 » » » break; | 558 break; |
| 569 » » default: | 559 default: |
| 570 » » » //cPurpose.push_back(letter); | 560 //cPurpose.push_back(letter); |
| 571 » » » cPurpose += letter; | 561 cPurpose += letter; |
| 572 » » » break; | 562 break; |
| 573 » » } | 563 } |
| 574 » } | 564 } |
| 575 } | 565 } |
| 576 | 566 |
| 577 FX_BOOL util::scand(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) | 567 FX_BOOL util::scand(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) |
| 578 { | 568 { |
| 579 » v8::Isolate* isolate = GetIsolate(cc); | 569 v8::Isolate* isolate = GetIsolate(cc); |
| 580 » int iSize = params.size(); | 570 int iSize = params.size(); |
| 581 » if (iSize < 2) | 571 if (iSize < 2) |
| 582 » » return FALSE; | 572 return FALSE; |
| 583 | 573 |
| 584 » CFX_WideString sFormat = params[0].ToCFXWideString(); | 574 CFX_WideString sFormat = params[0].ToCFXWideString(); |
| 585 » CFX_WideString sDate = params[1].ToCFXWideString(); | 575 CFX_WideString sDate = params[1].ToCFXWideString(); |
| 586 » double dDate = JS_GetDateTime(); | 576 double dDate = JS_GetDateTime(); |
| 587 » if (sDate.GetLength() > 0) | 577 if (sDate.GetLength() > 0) |
| 588 » { | 578 { |
| 589 » » FX_BOOL bWrongFormat = FALSE; | 579 FX_BOOL bWrongFormat = FALSE; |
| 590 » » dDate = CJS_PublicMethods::MakeRegularDate(sDate,sFormat,bWrongF
ormat); | 580 dDate = CJS_PublicMethods::MakeRegularDate(sDate,sFormat,bWrongFormat); |
| 591 » } | 581 } |
| 592 | 582 |
| 593 » if (!JS_PortIsNan(dDate)) | 583 if (!JS_PortIsNan(dDate)) |
| 594 » { | 584 { |
| 595 » » CJS_Date date(isolate,dDate); | 585 CJS_Date date(isolate,dDate); |
| 596 » » vRet = date; | 586 vRet = date; |
| 597 » } | 587 } |
| 598 » else | 588 else |
| 599 » { | 589 { |
| 600 » » vRet.SetNull(); | 590 vRet.SetNull(); |
| 601 » } | 591 } |
| 602 | 592 |
| 603 » return TRUE; | 593 return TRUE; |
| 604 } | 594 } |
| 605 | 595 |
| 606 int64_t FX_atoi64(const char *nptr) | 596 int64_t FX_atoi64(const char *nptr) |
| 607 { | 597 { |
| 608 int c; /* current char */ | 598 int c; /* current char */ |
| 609 int64_t total; /* current total */ | 599 int64_t total; /* current total */ |
| 610 int sign; /* if '-', then negative, otherwise positive */ | 600 int sign; /* if '-', then negative, otherwise positive */ |
| 611 | 601 |
| 612 /* skip whitespace */ | 602 /* skip whitespace */ |
| 613 while ( isspace((int)(unsigned char)*nptr) ) | 603 while ( isspace((int)(unsigned char)*nptr) ) |
| 614 ++nptr; | 604 ++nptr; |
| 615 | 605 |
| 616 c = (int)(unsigned char)*nptr++; | 606 c = (int)(unsigned char)*nptr++; |
| 617 sign = c; /* save sign indication */ | 607 sign = c; /* save sign indication */ |
| 618 if (c == '-' || c == '+') | 608 if (c == '-' || c == '+') |
| 619 c = (int)(unsigned char)*nptr++; /* skip sign */ | 609 c = (int)(unsigned char)*nptr++; /* skip sign */ |
| 620 | 610 |
| 621 total = 0; | 611 total = 0; |
| 622 | 612 |
| 623 while (isdigit(c)) { | 613 while (isdigit(c)) { |
| 624 total = 10 * total + (c - '0'); /* accumulate digit */ | 614 total = 10 * total + (c - '0'); /* accumulate digit */ |
| 625 c = (int)(unsigned char)*nptr++; /* get next char */ | 615 c = (int)(unsigned char)*nptr++; /* get next char */ |
| 626 } | 616 } |
| 627 | 617 |
| 628 if (sign == '-') | 618 return sign == '-' ? -total : total; |
| 629 return -total; | |
| 630 else | |
| 631 return total; /* return result, negated if necessary */ | |
| 632 } | 619 } |
| 633 | 620 |
| 634 FX_BOOL util::byteToChar(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Va
lue& vRet, CFX_WideString& sError) | 621 FX_BOOL util::byteToChar(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Va
lue& vRet, CFX_WideString& sError) |
| 635 { | 622 { |
| 636 » int iSize = params.size(); | 623 int iSize = params.size(); |
| 637 » if (iSize == 0) | 624 if (iSize == 0) |
| 638 » » return FALSE; | 625 return FALSE; |
| 639 » int nByte = params[0].ToInt(); | 626 int nByte = params[0].ToInt(); |
| 640 » unsigned char cByte = (unsigned char)nByte; | 627 unsigned char cByte = (unsigned char)nByte; |
| 641 » CFX_WideString csValue; | 628 CFX_WideString csValue; |
| 642 » csValue.Format(L"%c", cByte); | 629 csValue.Format(L"%c", cByte); |
| 643 » vRet = csValue.c_str(); | 630 vRet = csValue.c_str(); |
| 644 » return TRUE; | 631 return TRUE; |
| 645 } | 632 } |
| OLD | NEW |