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 "util.h" | 7 #include "util.h" |
8 | 8 |
9 #include "../../include/javascript/IJavaScript.h" | 9 #include "../../include/javascript/IJavaScript.h" |
10 #include "JS_Context.h" | 10 #include "JS_Context.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 continue; | 108 continue; |
109 } | 109 } |
110 break; | 110 break; |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 return -1; | 114 return -1; |
115 } | 115 } |
116 | 116 |
117 FX_BOOL util::printf(IJS_Context* cc, | 117 FX_BOOL util::printf(IJS_Context* cc, |
118 const CJS_Parameters& params, | 118 const std::vector<CJS_Value>& params, |
119 CJS_Value& vRet, | 119 CJS_Value& vRet, |
120 CFX_WideString& sError) { | 120 CFX_WideString& sError) { |
121 int iSize = params.size(); | 121 int iSize = params.size(); |
122 if (iSize < 1) | 122 if (iSize < 1) |
123 return FALSE; | 123 return FALSE; |
124 std::wstring c_ConvChar(params[0].ToCFXWideString().c_str()); | 124 std::wstring c_ConvChar(params[0].ToCFXWideString().c_str()); |
125 std::vector<std::wstring> c_strConvers; | 125 std::vector<std::wstring> c_strConvers; |
126 int iOffset = 0; | 126 int iOffset = 0; |
127 int iOffend = 0; | 127 int iOffend = 0; |
128 c_ConvChar.insert(c_ConvChar.begin(), L'S'); | 128 c_ConvChar.insert(c_ConvChar.begin(), L'S'); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 171 } |
172 c_strResult += strSegment.GetBuffer(strSegment.GetLength() + 1); | 172 c_strResult += strSegment.GetBuffer(strSegment.GetLength() + 1); |
173 } | 173 } |
174 | 174 |
175 c_strResult.erase(c_strResult.begin()); | 175 c_strResult.erase(c_strResult.begin()); |
176 vRet = c_strResult.c_str(); | 176 vRet = c_strResult.c_str(); |
177 return TRUE; | 177 return TRUE; |
178 } | 178 } |
179 | 179 |
180 FX_BOOL util::printd(IJS_Context* cc, | 180 FX_BOOL util::printd(IJS_Context* cc, |
181 const CJS_Parameters& params, | 181 const std::vector<CJS_Value>& params, |
182 CJS_Value& vRet, | 182 CJS_Value& vRet, |
183 CFX_WideString& sError) { | 183 CFX_WideString& sError) { |
184 int iSize = params.size(); | 184 int iSize = params.size(); |
185 if (iSize < 2) | 185 if (iSize < 2) |
186 return FALSE; | 186 return FALSE; |
187 | 187 |
188 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 188 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
189 CJS_Value p1(pRuntime); | 189 CJS_Value p1(pRuntime); |
190 p1 = params[0]; | 190 p1 = params[0]; |
191 | 191 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 } | 383 } |
384 | 384 |
385 CFX_WideString strFormat; | 385 CFX_WideString strFormat; |
386 wchar_t buf[64] = {}; | 386 wchar_t buf[64] = {}; |
387 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); | 387 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); |
388 cFormat = buf; | 388 cFormat = buf; |
389 cPurpose = cFormat; | 389 cPurpose = cFormat; |
390 } | 390 } |
391 | 391 |
392 FX_BOOL util::printx(IJS_Context* cc, | 392 FX_BOOL util::printx(IJS_Context* cc, |
393 const CJS_Parameters& params, | 393 const std::vector<CJS_Value>& params, |
394 CJS_Value& vRet, | 394 CJS_Value& vRet, |
395 CFX_WideString& sError) { | 395 CFX_WideString& sError) { |
396 int iSize = params.size(); | 396 int iSize = params.size(); |
397 if (iSize < 2) | 397 if (iSize < 2) |
398 return FALSE; | 398 return FALSE; |
399 CFX_WideString sFormat = params[0].ToCFXWideString(); | 399 CFX_WideString sFormat = params[0].ToCFXWideString(); |
400 CFX_WideString sSource = params[1].ToCFXWideString(); | 400 CFX_WideString sSource = params[1].ToCFXWideString(); |
401 std::string cFormat = CFX_ByteString::FromUnicode(sFormat).c_str(); | 401 std::string cFormat = CFX_ByteString::FromUnicode(sFormat).c_str(); |
402 std::string cSource = CFX_ByteString::FromUnicode(sSource).c_str(); | 402 std::string cSource = CFX_ByteString::FromUnicode(sSource).c_str(); |
403 std::string cDest; | 403 std::string cDest; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 case '=': | 483 case '=': |
484 break; | 484 break; |
485 default: | 485 default: |
486 cPurpose += letter; | 486 cPurpose += letter; |
487 break; | 487 break; |
488 } | 488 } |
489 } | 489 } |
490 } | 490 } |
491 | 491 |
492 FX_BOOL util::scand(IJS_Context* cc, | 492 FX_BOOL util::scand(IJS_Context* cc, |
493 const CJS_Parameters& params, | 493 const std::vector<CJS_Value>& params, |
494 CJS_Value& vRet, | 494 CJS_Value& vRet, |
495 CFX_WideString& sError) { | 495 CFX_WideString& sError) { |
496 int iSize = params.size(); | 496 int iSize = params.size(); |
497 if (iSize < 2) | 497 if (iSize < 2) |
498 return FALSE; | 498 return FALSE; |
499 | 499 |
500 CFX_WideString sFormat = params[0].ToCFXWideString(); | 500 CFX_WideString sFormat = params[0].ToCFXWideString(); |
501 CFX_WideString sDate = params[1].ToCFXWideString(); | 501 CFX_WideString sDate = params[1].ToCFXWideString(); |
502 double dDate = JS_GetDateTime(); | 502 double dDate = JS_GetDateTime(); |
503 if (sDate.GetLength() > 0) { | 503 if (sDate.GetLength() > 0) { |
(...skipping 28 matching lines...) Expand all Loading... |
532 | 532 |
533 while (isdigit(c)) { | 533 while (isdigit(c)) { |
534 total = 10 * total + (c - '0'); /* accumulate digit */ | 534 total = 10 * total + (c - '0'); /* accumulate digit */ |
535 c = (int)(unsigned char)*nptr++; /* get next char */ | 535 c = (int)(unsigned char)*nptr++; /* get next char */ |
536 } | 536 } |
537 | 537 |
538 return sign == '-' ? -total : total; | 538 return sign == '-' ? -total : total; |
539 } | 539 } |
540 | 540 |
541 FX_BOOL util::byteToChar(IJS_Context* cc, | 541 FX_BOOL util::byteToChar(IJS_Context* cc, |
542 const CJS_Parameters& params, | 542 const std::vector<CJS_Value>& params, |
543 CJS_Value& vRet, | 543 CJS_Value& vRet, |
544 CFX_WideString& sError) { | 544 CFX_WideString& sError) { |
545 int iSize = params.size(); | 545 int iSize = params.size(); |
546 if (iSize == 0) | 546 if (iSize == 0) |
547 return FALSE; | 547 return FALSE; |
548 int nByte = params[0].ToInt(); | 548 int nByte = params[0].ToInt(); |
549 unsigned char cByte = (unsigned char)nByte; | 549 unsigned char cByte = (unsigned char)nByte; |
550 CFX_WideString csValue; | 550 CFX_WideString csValue; |
551 csValue.Format(L"%c", cByte); | 551 csValue.Format(L"%c", cByte); |
552 vRet = csValue.c_str(); | 552 vRet = csValue.c_str(); |
553 return TRUE; | 553 return TRUE; |
554 } | 554 } |
OLD | NEW |