| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 bool bPercent = FALSE; | 101 bool bPercent = false; |
| 102 for (size_t i = 0; i < sFormat->length(); ++i) | 102 for (size_t i = 0; i < sFormat->length(); ++i) |
| 103 { | 103 { |
| 104 wchar_t c = (*sFormat)[i]; | 104 wchar_t c = (*sFormat)[i]; |
| 105 if (c == L'%') | 105 if (c == L'%') |
| 106 { | 106 { |
| 107 bPercent = true; | 107 bPercent = true; |
| 108 continue; | 108 continue; |
| 109 } | 109 } |
| 110 | 110 |
| 111 if (bPercent) | 111 if (bPercent) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 129 { | 129 { |
| 130 continue; | 130 continue; |
| 131 } | 131 } |
| 132 break; | 132 break; |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 return -1; | 136 return -1; |
| 137 } | 137 } |
| 138 | 138 |
| 139 FX_BOOL util::printf(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) | 139 bool util::printf(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vR
et, CFX_WideString& sError) |
| 140 { | 140 { |
| 141 int iSize = params.size(); | 141 int iSize = params.size(); |
| 142 if (iSize < 1) | 142 if (iSize < 1) |
| 143 return FALSE; | 143 return false; |
| 144 std::wstring c_ConvChar(params[0].ToCFXWideString().c_str()); | 144 std::wstring c_ConvChar(params[0].ToCFXWideString().c_str()); |
| 145 std::vector<std::wstring> c_strConvers; | 145 std::vector<std::wstring> c_strConvers; |
| 146 int iOffset = 0; | 146 int iOffset = 0; |
| 147 int iOffend = 0; | 147 int iOffend = 0; |
| 148 c_ConvChar.insert(c_ConvChar.begin(),L'S'); | 148 c_ConvChar.insert(c_ConvChar.begin(),L'S'); |
| 149 while(iOffset != -1) | 149 while(iOffset != -1) |
| 150 { | 150 { |
| 151 iOffend = c_ConvChar.find(L"%",iOffset+1); | 151 iOffend = c_ConvChar.find(L"%",iOffset+1); |
| 152 std::wstring strSub; | 152 std::wstring strSub; |
| 153 if (iOffend == -1) | 153 if (iOffend == -1) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 break; | 191 break; |
| 192 default: | 192 default: |
| 193 strSegment.Format(L"%S", c_strFormat.c_str()); | 193 strSegment.Format(L"%S", c_strFormat.c_str()); |
| 194 break; | 194 break; |
| 195 } | 195 } |
| 196 c_strResult += strSegment.GetBuffer(strSegment.GetLength()+1); | 196 c_strResult += strSegment.GetBuffer(strSegment.GetLength()+1); |
| 197 } | 197 } |
| 198 | 198 |
| 199 c_strResult.erase(c_strResult.begin()); | 199 c_strResult.erase(c_strResult.begin()); |
| 200 vRet = c_strResult.c_str(); | 200 vRet = c_strResult.c_str(); |
| 201 return TRUE; | 201 return true; |
| 202 } | 202 } |
| 203 | 203 |
| 204 FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) | 204 bool util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vR
et, CFX_WideString& sError) |
| 205 { | 205 { |
| 206 v8::Isolate* isolate = GetIsolate(cc); | 206 v8::Isolate* isolate = GetIsolate(cc); |
| 207 | 207 |
| 208 int iSize = params.size(); | 208 int iSize = params.size(); |
| 209 if (iSize < 2) | 209 if (iSize < 2) |
| 210 return FALSE; | 210 return false; |
| 211 | 211 |
| 212 CJS_Value p1(isolate); | 212 CJS_Value p1(isolate); |
| 213 p1 = params[0]; | 213 p1 = params[0]; |
| 214 | 214 |
| 215 CJS_Value p2 = params[1]; | 215 CJS_Value p2 = params[1]; |
| 216 CJS_Date jsDate(isolate); | 216 CJS_Date jsDate(isolate); |
| 217 if (!p2.ConvertToDate(jsDate)) | 217 if (!p2.ConvertToDate(jsDate)) |
| 218 { | 218 { |
| 219 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT1); | 219 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT1); |
| 220 return FALSE; | 220 return false; |
| 221 } | 221 } |
| 222 | 222 |
| 223 if (!jsDate.IsValidDate()) | 223 if (!jsDate.IsValidDate()) |
| 224 { | 224 { |
| 225 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2); | 225 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2); |
| 226 return FALSE; | 226 return false; |
| 227 } | 227 } |
| 228 | 228 |
| 229 if (p1.GetType() == VT_number) | 229 if (p1.GetType() == VT_number) |
| 230 { | 230 { |
| 231 int nFormat = p1.ToInt(); | 231 int nFormat = p1.ToInt(); |
| 232 CFX_WideString swResult; | 232 CFX_WideString swResult; |
| 233 | 233 |
| 234 switch (nFormat) | 234 switch (nFormat) |
| 235 { | 235 { |
| 236 case 0: | 236 case 0: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 254 case 2: | 254 case 2: |
| 255 swResult.Format(L"%04d/%02d/%02d %02d:%02d:%02d", | 255 swResult.Format(L"%04d/%02d/%02d %02d:%02d:%02d", |
| 256 jsDate.GetYear(), | 256 jsDate.GetYear(), |
| 257 jsDate.GetMonth() + 1, | 257 jsDate.GetMonth() + 1, |
| 258 jsDate.GetDay(), | 258 jsDate.GetDay(), |
| 259 jsDate.GetHours(), | 259 jsDate.GetHours(), |
| 260 jsDate.GetMinutes(), | 260 jsDate.GetMinutes(), |
| 261 jsDate.GetSeconds()); | 261 jsDate.GetSeconds()); |
| 262 break; | 262 break; |
| 263 default: | 263 default: |
| 264 return FALSE; | 264 return false; |
| 265 } | 265 } |
| 266 | 266 |
| 267 vRet = swResult.c_str(); | 267 vRet = swResult.c_str(); |
| 268 return TRUE; | 268 return true; |
| 269 } | 269 } |
| 270 if (p1.GetType() == VT_string) | 270 if (p1.GetType() == VT_string) |
| 271 { | 271 { |
| 272 std::basic_string<wchar_t> cFormat = p1.ToCFXWideString().c_str(); | 272 std::basic_string<wchar_t> cFormat = p1.ToCFXWideString().c_str(); |
| 273 | 273 |
| 274 bool bXFAPicture = false; | 274 bool bXFAPicture = false; |
| 275 if (iSize > 2) | 275 if (iSize > 2) |
| 276 { | 276 { |
| 277 bXFAPicture = params[2].ToBool(); | 277 bXFAPicture = params[2].ToBool(); |
| 278 } | 278 } |
| 279 | 279 |
| 280 if (bXFAPicture) | 280 if (bXFAPicture) |
| 281 { | 281 { |
| 282 return FALSE; //currently, it doesn't support XFAPicture. | 282 return false; //currently, it doesn't support XFAPicture. |
| 283 } | 283 } |
| 284 | 284 |
| 285 int iIndex; | 285 int iIndex; |
| 286 for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIndex++) | 286 for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIndex++) |
| 287 { | 287 { |
| 288 int iStart = 0; | 288 int iStart = 0; |
| 289 int iEnd; | 289 int iEnd; |
| 290 while((iEnd = cFormat.find(fcTable[iIndex].lpszJSMark, iStart)) != -
1) | 290 while((iEnd = cFormat.find(fcTable[iIndex].lpszJSMark, iStart)) != -
1) |
| 291 { | 291 { |
| 292 cFormat.replace(iEnd, FXSYS_wcslen(fcTable[iIndex].lpszJSMark),
fcTable[iIndex].lpszCppMark); | 292 cFormat.replace(iEnd, FXSYS_wcslen(fcTable[iIndex].lpszJSMark),
fcTable[iIndex].lpszCppMark); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[iIndex].lpszJSMark),
tszValue); | 348 cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[iIndex].lpszJSMark),
tszValue); |
| 349 iStart = iEnd; | 349 iStart = iEnd; |
| 350 } | 350 } |
| 351 } | 351 } |
| 352 | 352 |
| 353 CFX_WideString strFormat; | 353 CFX_WideString strFormat; |
| 354 wchar_t buf[64] = {}; | 354 wchar_t buf[64] = {}; |
| 355 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); | 355 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); |
| 356 cFormat = buf; | 356 cFormat = buf; |
| 357 vRet = cFormat.c_str(); | 357 vRet = cFormat.c_str(); |
| 358 return TRUE; | 358 return true; |
| 359 } | 359 } |
| 360 return FALSE; | 360 return false; |
| 361 } | 361 } |
| 362 | 362 |
| 363 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) |
| 364 { | 364 { |
| 365 std::wstring cFormat = cFormat2; | 365 std::wstring cFormat = cFormat2; |
| 366 | 366 |
| 367 if (bXFAPicture) | 367 if (bXFAPicture) |
| 368 { | 368 { |
| 369 return ; //currently, it doesn't support XFAPicture. | 369 return ; //currently, it doesn't support XFAPicture. |
| 370 } | 370 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 } | 443 } |
| 444 } | 444 } |
| 445 | 445 |
| 446 CFX_WideString strFormat; | 446 CFX_WideString strFormat; |
| 447 wchar_t buf[64] = {}; | 447 wchar_t buf[64] = {}; |
| 448 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); | 448 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); |
| 449 cFormat = buf; | 449 cFormat = buf; |
| 450 cPurpose = cFormat; | 450 cPurpose = cFormat; |
| 451 } | 451 } |
| 452 | 452 |
| 453 FX_BOOL util::printx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) | 453 bool util::printx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vR
et, CFX_WideString& sError) |
| 454 { | 454 { |
| 455 int iSize = params.size(); | 455 int iSize = params.size(); |
| 456 if (iSize<2) | 456 if (iSize<2) |
| 457 return FALSE; | 457 return false; |
| 458 CFX_WideString sFormat = params[0].ToCFXWideString(); | 458 CFX_WideString sFormat = params[0].ToCFXWideString(); |
| 459 CFX_WideString sSource = params[1].ToCFXWideString(); | 459 CFX_WideString sSource = params[1].ToCFXWideString(); |
| 460 std::string cFormat = CFX_ByteString::FromUnicode(sFormat).c_str(); | 460 std::string cFormat = CFX_ByteString::FromUnicode(sFormat).c_str(); |
| 461 std::string cSource = CFX_ByteString::FromUnicode(sSource).c_str(); | 461 std::string cSource = CFX_ByteString::FromUnicode(sSource).c_str(); |
| 462 std::string cDest; | 462 std::string cDest; |
| 463 printx(cFormat,cSource,cDest); | 463 printx(cFormat,cSource,cDest); |
| 464 vRet = cDest.c_str(); | 464 vRet = cDest.c_str(); |
| 465 return TRUE; | 465 return true; |
| 466 } | 466 } |
| 467 | 467 |
| 468 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) |
| 469 { | 469 { |
| 470 std::string cSource(cSource2); | 470 std::string cSource(cSource2); |
| 471 if (!cPurpose.empty()) | 471 if (!cPurpose.empty()) |
| 472 //cPurpose.clear(); | 472 //cPurpose.clear(); |
| 473 cPurpose.erase(); | 473 cPurpose.erase(); |
| 474 int itSource = 0; | 474 int itSource = 0; |
| 475 int iSize = cSource.size(); | 475 int iSize = cSource.size(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 case '=': | 557 case '=': |
| 558 break; | 558 break; |
| 559 default: | 559 default: |
| 560 //cPurpose.push_back(letter); | 560 //cPurpose.push_back(letter); |
| 561 cPurpose += letter; | 561 cPurpose += letter; |
| 562 break; | 562 break; |
| 563 } | 563 } |
| 564 } | 564 } |
| 565 } | 565 } |
| 566 | 566 |
| 567 FX_BOOL util::scand(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
vRet, CFX_WideString& sError) | 567 bool util::scand(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRe
t, CFX_WideString& sError) |
| 568 { | 568 { |
| 569 v8::Isolate* isolate = GetIsolate(cc); | 569 v8::Isolate* isolate = GetIsolate(cc); |
| 570 int iSize = params.size(); | 570 int iSize = params.size(); |
| 571 if (iSize < 2) | 571 if (iSize < 2) |
| 572 return FALSE; | 572 return false; |
| 573 | 573 |
| 574 CFX_WideString sFormat = params[0].ToCFXWideString(); | 574 CFX_WideString sFormat = params[0].ToCFXWideString(); |
| 575 CFX_WideString sDate = params[1].ToCFXWideString(); | 575 CFX_WideString sDate = params[1].ToCFXWideString(); |
| 576 double dDate = JS_GetDateTime(); | 576 double dDate = JS_GetDateTime(); |
| 577 if (sDate.GetLength() > 0) | 577 if (sDate.GetLength() > 0) |
| 578 { | 578 { |
| 579 FX_BOOL bWrongFormat = FALSE; | 579 bool bWrongFormat = false; |
| 580 dDate = CJS_PublicMethods::MakeRegularDate(sDate,sFormat,bWrongFormat); | 580 dDate = CJS_PublicMethods::MakeRegularDate(sDate,sFormat,bWrongFormat); |
| 581 } | 581 } |
| 582 | 582 |
| 583 if (!JS_PortIsNan(dDate)) | 583 if (!JS_PortIsNan(dDate)) |
| 584 { | 584 { |
| 585 CJS_Date date(isolate,dDate); | 585 CJS_Date date(isolate,dDate); |
| 586 vRet = date; | 586 vRet = date; |
| 587 } | 587 } |
| 588 else | 588 else |
| 589 { | 589 { |
| 590 vRet.SetNull(); | 590 vRet.SetNull(); |
| 591 } | 591 } |
| 592 | 592 |
| 593 return TRUE; | 593 return true; |
| 594 } | 594 } |
| 595 | 595 |
| 596 int64_t FX_atoi64(const char *nptr) | 596 int64_t FX_atoi64(const char *nptr) |
| 597 { | 597 { |
| 598 int c; /* current char */ | 598 int c; /* current char */ |
| 599 int64_t total; /* current total */ | 599 int64_t total; /* current total */ |
| 600 int sign; /* if '-', then negative, otherwise positive */ | 600 int sign; /* if '-', then negative, otherwise positive */ |
| 601 | 601 |
| 602 /* skip whitespace */ | 602 /* skip whitespace */ |
| 603 while ( isspace((int)(unsigned char)*nptr) ) | 603 while ( isspace((int)(unsigned char)*nptr) ) |
| 604 ++nptr; | 604 ++nptr; |
| 605 | 605 |
| 606 c = (int)(unsigned char)*nptr++; | 606 c = (int)(unsigned char)*nptr++; |
| 607 sign = c; /* save sign indication */ | 607 sign = c; /* save sign indication */ |
| 608 if (c == '-' || c == '+') | 608 if (c == '-' || c == '+') |
| 609 c = (int)(unsigned char)*nptr++; /* skip sign */ | 609 c = (int)(unsigned char)*nptr++; /* skip sign */ |
| 610 | 610 |
| 611 total = 0; | 611 total = 0; |
| 612 | 612 |
| 613 while (isdigit(c)) { | 613 while (isdigit(c)) { |
| 614 total = 10 * total + (c - '0'); /* accumulate digit */ | 614 total = 10 * total + (c - '0'); /* accumulate digit */ |
| 615 c = (int)(unsigned char)*nptr++; /* get next char */ | 615 c = (int)(unsigned char)*nptr++; /* get next char */ |
| 616 } | 616 } |
| 617 | 617 |
| 618 return sign == '-' ? -total : total; | 618 return sign == '-' ? -total : total; |
| 619 } | 619 } |
| 620 | 620 |
| 621 FX_BOOL util::byteToChar(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Va
lue& vRet, CFX_WideString& sError) | 621 bool util::byteToChar(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value
& vRet, CFX_WideString& sError) |
| 622 { | 622 { |
| 623 int iSize = params.size(); | 623 int iSize = params.size(); |
| 624 if (iSize == 0) | 624 if (iSize == 0) |
| 625 return FALSE; | 625 return false; |
| 626 int nByte = params[0].ToInt(); | 626 int nByte = params[0].ToInt(); |
| 627 unsigned char cByte = (unsigned char)nByte; | 627 unsigned char cByte = (unsigned char)nByte; |
| 628 CFX_WideString csValue; | 628 CFX_WideString csValue; |
| 629 csValue.Format(L"%c", cByte); | 629 csValue.Format(L"%c", cByte); |
| 630 vRet = csValue.c_str(); | 630 vRet = csValue.c_str(); |
| 631 return TRUE; | 631 return true; |
| 632 } | 632 } |
| OLD | NEW |