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" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 size_t i = 0; |
102 » bool bPercent = FALSE; | 102 » bool bPercent = false; |
103 for (i=0; i<sFormat->length(); ++i) | 103 for (i=0; i<sFormat->length(); ++i) |
104 { | 104 { |
105 wchar_t c = (*sFormat)[i]; | 105 wchar_t c = (*sFormat)[i]; |
106 if (c == L'%') | 106 if (c == L'%') |
107 { | 107 { |
108 bPercent = true; | 108 bPercent = true; |
109 continue; | 109 continue; |
110 } | 110 } |
111 | 111 |
112 if (bPercent) | 112 if (bPercent) |
(...skipping 17 matching lines...) Expand all Loading... |
130 { | 130 { |
131 continue; | 131 continue; |
132 } | 132 } |
133 else break; | 133 else break; |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 return -1; | 137 return -1; |
138 } | 138 } |
139 | 139 |
140 FX_BOOL util::printf(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) | 140 bool util::printf(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vR
et, CFX_WideString& sError) |
141 { | 141 { |
142 int iSize = params.size(); | 142 int iSize = params.size(); |
143 if (iSize < 1) | 143 if (iSize < 1) |
144 » » return FALSE; | 144 » » return false; |
145 std::wstring c_ConvChar(params[0].ToCFXWideString().c_str()); | 145 std::wstring c_ConvChar(params[0].ToCFXWideString().c_str()); |
146 std::vector<std::wstring> c_strConvers; | 146 std::vector<std::wstring> c_strConvers; |
147 int iOffset = 0; | 147 int iOffset = 0; |
148 int iOffend = 0; | 148 int iOffend = 0; |
149 c_ConvChar.insert(c_ConvChar.begin(),L'S'); | 149 c_ConvChar.insert(c_ConvChar.begin(),L'S'); |
150 while(iOffset != -1) | 150 while(iOffset != -1) |
151 { | 151 { |
152 iOffend = c_ConvChar.find(L"%",iOffset+1); | 152 iOffend = c_ConvChar.find(L"%",iOffset+1); |
153 std::wstring strSub; | 153 std::wstring strSub; |
154 if (iOffend == -1) | 154 if (iOffend == -1) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 break; | 192 break; |
193 default: | 193 default: |
194 strSegment.Format(L"%S", c_strFormat.c_str()); | 194 strSegment.Format(L"%S", c_strFormat.c_str()); |
195 break; | 195 break; |
196 } | 196 } |
197 c_strResult += strSegment.GetBuffer(strSegment.GetLength()+1); | 197 c_strResult += strSegment.GetBuffer(strSegment.GetLength()+1); |
198 } | 198 } |
199 | 199 |
200 c_strResult.erase(c_strResult.begin()); | 200 c_strResult.erase(c_strResult.begin()); |
201 vRet = c_strResult.c_str(); | 201 vRet = c_strResult.c_str(); |
202 » return TRUE; | 202 » return true; |
203 } | 203 } |
204 | 204 |
205 FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) | 205 bool util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vR
et, CFX_WideString& sError) |
206 { | 206 { |
207 v8::Isolate* isolate = GetIsolate(cc); | 207 v8::Isolate* isolate = GetIsolate(cc); |
208 | 208 |
209 int iSize = params.size(); | 209 int iSize = params.size(); |
210 if (iSize < 2) | 210 if (iSize < 2) |
211 » » return FALSE; | 211 » » return false; |
212 | 212 |
213 CJS_Value p1(isolate); | 213 CJS_Value p1(isolate); |
214 p1 = params[0]; | 214 p1 = params[0]; |
215 | 215 |
216 CJS_Value p2 = params[1]; | 216 CJS_Value p2 = params[1]; |
217 CJS_Date jsDate(isolate); | 217 CJS_Date jsDate(isolate); |
218 if (!p2.ConvertToDate(jsDate)) | 218 if (!p2.ConvertToDate(jsDate)) |
219 { | 219 { |
220 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT1
); | 220 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT1
); |
221 » » return FALSE; | 221 » » return false; |
222 } | 222 } |
223 | 223 |
224 if (!jsDate.IsValidDate()) | 224 if (!jsDate.IsValidDate()) |
225 { | 225 { |
226 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2
); | 226 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2
); |
227 » » return FALSE; | 227 » » return false; |
228 } | 228 } |
229 | 229 |
230 if (p1.GetType() == VT_number) | 230 if (p1.GetType() == VT_number) |
231 { | 231 { |
232 int nFormat = p1.ToInt(); | 232 int nFormat = p1.ToInt(); |
233 CFX_WideString swResult; | 233 CFX_WideString swResult; |
234 | 234 |
235 switch (nFormat) | 235 switch (nFormat) |
236 { | 236 { |
237 case 0: | 237 case 0: |
(...skipping 17 matching lines...) Expand all Loading... |
255 case 2: | 255 case 2: |
256 swResult.Format(L"%04d/%02d/%02d %02d:%02d:%02d", | 256 swResult.Format(L"%04d/%02d/%02d %02d:%02d:%02d", |
257 jsDate.GetYear(), | 257 jsDate.GetYear(), |
258 jsDate.GetMonth() + 1, | 258 jsDate.GetMonth() + 1, |
259 jsDate.GetDay(), | 259 jsDate.GetDay(), |
260 jsDate.GetHours(), | 260 jsDate.GetHours(), |
261 jsDate.GetMinutes(), | 261 jsDate.GetMinutes(), |
262 jsDate.GetSeconds()); | 262 jsDate.GetSeconds()); |
263 break; | 263 break; |
264 default: | 264 default: |
265 » » » return FALSE; | 265 » » » return false; |
266 } | 266 } |
267 | 267 |
268 vRet = swResult.c_str(); | 268 vRet = swResult.c_str(); |
269 » » return TRUE; | 269 » » return true; |
270 } | 270 } |
271 else if (p1.GetType() == VT_string) | 271 else if (p1.GetType() == VT_string) |
272 { | 272 { |
273 std::basic_string<wchar_t> cFormat = p1.ToCFXWideString().c_str(
); | 273 std::basic_string<wchar_t> cFormat = p1.ToCFXWideString().c_str(
); |
274 | 274 |
275 bool bXFAPicture = false; | 275 bool bXFAPicture = false; |
276 if (iSize > 2) | 276 if (iSize > 2) |
277 { | 277 { |
278 bXFAPicture = params[2].ToBool(); | 278 bXFAPicture = params[2].ToBool(); |
279 } | 279 } |
280 | 280 |
281 if (bXFAPicture) | 281 if (bXFAPicture) |
282 { | 282 { |
283 » » » return FALSE; //currently, it doesn't support XFAPicture
. | 283 » » » return false; //currently, it doesn't support XFAPicture
. |
284 } | 284 } |
285 | 285 |
286 int iIndex; | 286 int iIndex; |
287 for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIn
dex++) | 287 for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIn
dex++) |
288 { | 288 { |
289 int iStart = 0; | 289 int iStart = 0; |
290 int iEnd; | 290 int iEnd; |
291 while((iEnd = cFormat.find(fcTable[iIndex].lpszJSMark, i
Start)) != -1) | 291 while((iEnd = cFormat.find(fcTable[iIndex].lpszJSMark, i
Start)) != -1) |
292 { | 292 { |
293 cFormat.replace(iEnd, FXSYS_wcslen(fcTable[iInde
x].lpszJSMark), fcTable[iIndex].lpszCppMark); | 293 cFormat.replace(iEnd, FXSYS_wcslen(fcTable[iInde
x].lpszJSMark), fcTable[iIndex].lpszCppMark); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 } | 358 } |
359 | 359 |
360 CFX_WideString strFormat; | 360 CFX_WideString strFormat; |
361 // strFormat.Format(L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour
, iMin, iSec); | 361 // strFormat.Format(L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour
, iMin, iSec); |
362 // CString strFormat = cppTm.Format(cFormat.c_str()); | 362 // CString strFormat = cppTm.Format(cFormat.c_str()); |
363 wchar_t buf[64] = {}; | 363 wchar_t buf[64] = {}; |
364 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); | 364 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); |
365 cFormat = buf; | 365 cFormat = buf; |
366 vRet = cFormat.c_str(); | 366 vRet = cFormat.c_str(); |
367 //rtRet = strFormat.GetBuffer(strFormat.GetLength()+1); | 367 //rtRet = strFormat.GetBuffer(strFormat.GetLength()+1); |
368 » » return TRUE; | 368 » » return true; |
369 } | 369 } |
370 » return FALSE; | 370 » return false; |
371 } | 371 } |
372 | 372 |
373 void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPictur
e, std::wstring &cPurpose) | 373 void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPictur
e, std::wstring &cPurpose) |
374 { | 374 { |
375 std::wstring cFormat = cFormat2; | 375 std::wstring cFormat = cFormat2; |
376 | 376 |
377 if (bXFAPicture) | 377 if (bXFAPicture) |
378 { | 378 { |
379 return ; //currently, it doesn't support XFAPicture. | 379 return ; //currently, it doesn't support XFAPicture. |
380 } | 380 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 } | 453 } |
454 } | 454 } |
455 | 455 |
456 CFX_WideString strFormat; | 456 CFX_WideString strFormat; |
457 wchar_t buf[64] = {}; | 457 wchar_t buf[64] = {}; |
458 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); | 458 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); |
459 cFormat = buf; | 459 cFormat = buf; |
460 cPurpose = cFormat; | 460 cPurpose = cFormat; |
461 } | 461 } |
462 | 462 |
463 FX_BOOL util::printx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) | 463 bool util::printx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vR
et, CFX_WideString& sError) |
464 { | 464 { |
465 int iSize = params.size(); | 465 int iSize = params.size(); |
466 if (iSize<2) | 466 if (iSize<2) |
467 » » return FALSE; | 467 » » return false; |
468 CFX_WideString sFormat = params[0].ToCFXWideString(); | 468 CFX_WideString sFormat = params[0].ToCFXWideString(); |
469 CFX_WideString sSource = params[1].ToCFXWideString(); | 469 CFX_WideString sSource = params[1].ToCFXWideString(); |
470 std::string cFormat = CFX_ByteString::FromUnicode(sFormat).c_str(); | 470 std::string cFormat = CFX_ByteString::FromUnicode(sFormat).c_str(); |
471 std::string cSource = CFX_ByteString::FromUnicode(sSource).c_str(); | 471 std::string cSource = CFX_ByteString::FromUnicode(sSource).c_str(); |
472 std::string cDest; | 472 std::string cDest; |
473 printx(cFormat,cSource,cDest); | 473 printx(cFormat,cSource,cDest); |
474 vRet = cDest.c_str(); | 474 vRet = cDest.c_str(); |
475 » return TRUE; | 475 » return true; |
476 } | 476 } |
477 | 477 |
478 void util::printx(const std::string &cFormat,const std::string &cSource2,std::st
ring &cPurpose) | 478 void util::printx(const std::string &cFormat,const std::string &cSource2,std::st
ring &cPurpose) |
479 { | 479 { |
480 std::string cSource(cSource2); | 480 std::string cSource(cSource2); |
481 if (!cPurpose.empty()) | 481 if (!cPurpose.empty()) |
482 //cPurpose.clear(); | 482 //cPurpose.clear(); |
483 cPurpose.erase(); | 483 cPurpose.erase(); |
484 int itSource = 0; | 484 int itSource = 0; |
485 int iSize = cSource.size(); | 485 int iSize = cSource.size(); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 case '=': | 567 case '=': |
568 break; | 568 break; |
569 default: | 569 default: |
570 //cPurpose.push_back(letter); | 570 //cPurpose.push_back(letter); |
571 cPurpose += letter; | 571 cPurpose += letter; |
572 break; | 572 break; |
573 } | 573 } |
574 } | 574 } |
575 } | 575 } |
576 | 576 |
577 FX_BOOL util::scand(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) | 577 bool util::scand(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRe
t, CFX_WideString& sError) |
578 { | 578 { |
579 v8::Isolate* isolate = GetIsolate(cc); | 579 v8::Isolate* isolate = GetIsolate(cc); |
580 int iSize = params.size(); | 580 int iSize = params.size(); |
581 if (iSize < 2) | 581 if (iSize < 2) |
582 » » return FALSE; | 582 » » return false; |
583 | 583 |
584 CFX_WideString sFormat = params[0].ToCFXWideString(); | 584 CFX_WideString sFormat = params[0].ToCFXWideString(); |
585 CFX_WideString sDate = params[1].ToCFXWideString(); | 585 CFX_WideString sDate = params[1].ToCFXWideString(); |
586 double dDate = JS_GetDateTime(); | 586 double dDate = JS_GetDateTime(); |
587 if (sDate.GetLength() > 0) | 587 if (sDate.GetLength() > 0) |
588 { | 588 { |
589 » » FX_BOOL bWrongFormat = FALSE; | 589 » » bool bWrongFormat = false; |
590 dDate = CJS_PublicMethods::MakeRegularDate(sDate,sFormat,bWrongF
ormat); | 590 dDate = CJS_PublicMethods::MakeRegularDate(sDate,sFormat,bWrongF
ormat); |
591 } | 591 } |
592 | 592 |
593 if (!JS_PortIsNan(dDate)) | 593 if (!JS_PortIsNan(dDate)) |
594 { | 594 { |
595 CJS_Date date(isolate,dDate); | 595 CJS_Date date(isolate,dDate); |
596 vRet = date; | 596 vRet = date; |
597 } | 597 } |
598 else | 598 else |
599 { | 599 { |
600 vRet.SetNull(); | 600 vRet.SetNull(); |
601 } | 601 } |
602 | 602 |
603 » return TRUE; | 603 » return true; |
604 } | 604 } |
605 | 605 |
606 int64_t FX_atoi64(const char *nptr) | 606 int64_t FX_atoi64(const char *nptr) |
607 { | 607 { |
608 int c; /* current char */ | 608 int c; /* current char */ |
609 int64_t total; /* current total */ | 609 int64_t total; /* current total */ |
610 int sign; /* if '-', then negative, otherwise positive */ | 610 int sign; /* if '-', then negative, otherwise positive */ |
611 | 611 |
612 /* skip whitespace */ | 612 /* skip whitespace */ |
613 while ( isspace((int)(unsigned char)*nptr) ) | 613 while ( isspace((int)(unsigned char)*nptr) ) |
(...skipping 10 matching lines...) Expand all Loading... |
624 total = 10 * total + (c - '0'); /* accumulate digit */ | 624 total = 10 * total + (c - '0'); /* accumulate digit */ |
625 c = (int)(unsigned char)*nptr++; /* get next char */ | 625 c = (int)(unsigned char)*nptr++; /* get next char */ |
626 } | 626 } |
627 | 627 |
628 if (sign == '-') | 628 if (sign == '-') |
629 return -total; | 629 return -total; |
630 else | 630 else |
631 return total; /* return result, negated if necessary */ | 631 return total; /* return result, negated if necessary */ |
632 } | 632 } |
633 | 633 |
634 FX_BOOL util::byteToChar(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Va
lue& vRet, CFX_WideString& sError) | 634 bool util::byteToChar(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value
& vRet, CFX_WideString& sError) |
635 { | 635 { |
636 int iSize = params.size(); | 636 int iSize = params.size(); |
637 if (iSize == 0) | 637 if (iSize == 0) |
638 » » return FALSE; | 638 » » return false; |
639 int nByte = params[0].ToInt(); | 639 int nByte = params[0].ToInt(); |
640 unsigned char cByte = (unsigned char)nByte; | 640 unsigned char cByte = (unsigned char)nByte; |
641 CFX_WideString csValue; | 641 CFX_WideString csValue; |
642 csValue.Format(L"%c", cByte); | 642 csValue.Format(L"%c", cByte); |
643 vRet = csValue.c_str(); | 643 vRet = csValue.c_str(); |
644 » return TRUE; | 644 » return true; |
645 } | 645 } |
OLD | NEW |