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