Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: fpdfsdk/src/javascript/util.cpp

Issue 726143002: Remove FX_LPCWSTR cast to wchar_t* literals (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/javascript/app.cpp ('k') | fpdfsdk/src/pdfwindow/PWL_Note.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } 56 }
57 57
58 58
59 struct stru_TbConvert 59 struct stru_TbConvert
60 { 60 {
61 FX_LPCWSTR lpszJSMark; 61 FX_LPCWSTR lpszJSMark;
62 FX_LPCWSTR lpszCppMark; 62 FX_LPCWSTR lpszCppMark;
63 }; 63 };
64 64
65 const stru_TbConvert fcTable[] = { 65 const stru_TbConvert fcTable[] = {
66 » { (FX_LPCWSTR)L"mmmm", (FX_LPCWSTR)L"%B" }, 66 » { L"mmmm", L"%B" },
67 » { (FX_LPCWSTR)L"mmm", (FX_LPCWSTR)L"%b" }, 67 » { L"mmm", L"%b" },
68 » { (FX_LPCWSTR)L"mm", (FX_LPCWSTR)L"%m" }, 68 » { L"mm", L"%m" },
69 //"m" 69 //"m"
70 » { (FX_LPCWSTR)L"dddd", (FX_LPCWSTR)L"%A" }, 70 » { L"dddd", L"%A" },
71 » { (FX_LPCWSTR)L"ddd", (FX_LPCWSTR)L"%a" }, 71 » { L"ddd", L"%a" },
72 » { (FX_LPCWSTR)L"dd", (FX_LPCWSTR)L"%d" }, 72 » { L"dd", L"%d" },
73 //"d", "%w", 73 //"d", "%w",
74 » { (FX_LPCWSTR)L"yyyy", (FX_LPCWSTR)L"%Y" }, 74 » { L"yyyy", L"%Y" },
75 » { (FX_LPCWSTR)L"yy", (FX_LPCWSTR)L"%y" }, 75 » { L"yy", L"%y" },
76 » { (FX_LPCWSTR)L"HH", (FX_LPCWSTR)L"%H" }, 76 » { L"HH", L"%H" },
77 //"H" 77 //"H"
78 » { (FX_LPCWSTR)L"hh", (FX_LPCWSTR)L"%I" }, 78 » { L"hh", L"%I" },
79 //"h" 79 //"h"
80 » { (FX_LPCWSTR)L"MM", (FX_LPCWSTR)L"%M" }, 80 » { L"MM", L"%M" },
81 //"M" 81 //"M"
82 » { (FX_LPCWSTR)L"ss", (FX_LPCWSTR)L"%S" }, 82 » { L"ss", L"%S" },
83 //"s 83 //"s
84 » { (FX_LPCWSTR)L"TT", (FX_LPCWSTR)L"%p" }, 84 » { L"TT", L"%p" },
85 //"t" 85 //"t"
86 #if defined(_WIN32) 86 #if defined(_WIN32)
87 » { (FX_LPCWSTR)L"tt", (FX_LPCWSTR)L"%p" }, 87 » { L"tt", L"%p" },
88 » { (FX_LPCWSTR)L"h", (FX_LPCWSTR)L"%#I" }, 88 » { L"h", L"%#I" },
89 #else 89 #else
90 » { (FX_LPCWSTR)L"tt", (FX_LPCWSTR)L"%P" }, 90 » { L"tt", L"%P" },
91 » { (FX_LPCWSTR)L"h", (FX_LPCWSTR)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 size_t i = 0;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 case UTIL_INT: 184 case UTIL_INT:
185 strSegment.Format((FX_LPCWSTR)c_strFormat.c_str( ),(int)params[iIndex]); 185 strSegment.Format((FX_LPCWSTR)c_strFormat.c_str( ),(int)params[iIndex]);
186 break; 186 break;
187 case UTIL_DOUBLE: 187 case UTIL_DOUBLE:
188 strSegment.Format((FX_LPCWSTR)c_strFormat.c_str( ),(double)params[iIndex]); 188 strSegment.Format((FX_LPCWSTR)c_strFormat.c_str( ),(double)params[iIndex]);
189 break; 189 break;
190 case UTIL_STRING: 190 case UTIL_STRING:
191 strSegment.Format((FX_LPCWSTR)c_strFormat.c_str( ),(FX_LPCWSTR)params[iIndex].operator CFX_WideString()); 191 strSegment.Format((FX_LPCWSTR)c_strFormat.c_str( ),(FX_LPCWSTR)params[iIndex].operator CFX_WideString());
192 break; 192 break;
193 default: 193 default:
194 » » » » strSegment.Format((FX_LPCWSTR)L"%S", (FX_LPCWSTR )c_strFormat.c_str()); 194 » » » » strSegment.Format(L"%S", (FX_LPCWSTR)c_strFormat .c_str());
195 break; 195 break;
196 } 196 }
197 c_strResult += (wchar_t*)strSegment.GetBuffer(strSegment.GetLeng th()+1); 197 c_strResult += (wchar_t*)strSegment.GetBuffer(strSegment.GetLeng th()+1);
198 } 198 }
199 199
200 c_strResult.erase(c_strResult.begin()); 200 c_strResult.erase(c_strResult.begin());
201 vRet = (FX_LPCWSTR)c_strResult.c_str(); 201 vRet = (FX_LPCWSTR)c_strResult.c_str();
202 return TRUE; 202 return TRUE;
203 } 203 }
204 204
(...skipping 24 matching lines...) Expand all
229 229
230 if (p1.GetType() == VT_number) 230 if (p1.GetType() == VT_number)
231 { 231 {
232 int nFormat = p1; 232 int nFormat = p1;
233 233
234 CFX_WideString swResult; 234 CFX_WideString swResult;
235 235
236 switch (nFormat) 236 switch (nFormat)
237 { 237 {
238 case 0: 238 case 0:
239 » » » swResult.Format((FX_LPCWSTR)L"D:%04d%02d%02d%02d%02d%02d ", 239 » » » swResult.Format(L"D:%04d%02d%02d%02d%02d%02d",
240 jsDate.GetYear(), 240 jsDate.GetYear(),
241 jsDate.GetMonth() + 1, 241 jsDate.GetMonth() + 1,
242 jsDate.GetDay(), 242 jsDate.GetDay(),
243 jsDate.GetHours(), 243 jsDate.GetHours(),
244 jsDate.GetMinutes(), 244 jsDate.GetMinutes(),
245 jsDate.GetSeconds()); 245 jsDate.GetSeconds());
246 break; 246 break;
247 case 1: 247 case 1:
248 » » » swResult.Format((FX_LPCWSTR)L"%04d.%02d.%02d %02d:%02d:% 02d", 248 » » » swResult.Format(L"%04d.%02d.%02d %02d:%02d:%02d",
249 jsDate.GetYear(), 249 jsDate.GetYear(),
250 jsDate.GetMonth() + 1, 250 jsDate.GetMonth() + 1,
251 jsDate.GetDay(), 251 jsDate.GetDay(),
252 jsDate.GetHours(), 252 jsDate.GetHours(),
253 jsDate.GetMinutes(), 253 jsDate.GetMinutes(),
254 jsDate.GetSeconds()); 254 jsDate.GetSeconds());
255 break; 255 break;
256 case 2: 256 case 2:
257 » » » swResult.Format((FX_LPCWSTR)L"%04d/%02d/%02d %02d:%02d:% 02d", 257 » » » swResult.Format(L"%04d/%02d/%02d %02d:%02d:%02d",
258 jsDate.GetYear(), 258 jsDate.GetYear(),
259 jsDate.GetMonth() + 1, 259 jsDate.GetMonth() + 1,
260 jsDate.GetDay(), 260 jsDate.GetDay(),
261 jsDate.GetHours(), 261 jsDate.GetHours(),
262 jsDate.GetMinutes(), 262 jsDate.GetMinutes(),
263 jsDate.GetSeconds()); 263 jsDate.GetSeconds());
264 break; 264 break;
265 default: 265 default:
266 return FALSE; 266 return FALSE;
267 } 267 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 //COleDateTime cppTm(iYear,iMonth+1,iDay,iHour,iMin,iSec); 315 //COleDateTime cppTm(iYear,iMonth+1,iDay,iHour,iMin,iSec);
316 //CString strFormat = cppTm.Format(cFormat.c_str()); 316 //CString strFormat = cppTm.Format(cFormat.c_str());
317 317
318 struct stru_TbConvertAd 318 struct stru_TbConvertAd
319 { 319 {
320 FX_LPCWSTR lpszJSMark; 320 FX_LPCWSTR lpszJSMark;
321 int iValue; 321 int iValue;
322 }; 322 };
323 323
324 stru_TbConvertAd cTableAd[] ={ 324 stru_TbConvertAd cTableAd[] ={
325 » » » { (FX_LPCWSTR)L"m", iMonth+1 }, 325 » » » { L"m", iMonth+1 },
326 » » » { (FX_LPCWSTR)L"d", iDay }, 326 » » » { L"d", iDay },
327 » » » { (FX_LPCWSTR)L"H", iHour }, 327 » » » { L"H", iHour },
328 » » » { (FX_LPCWSTR)L"h", iHour>12?iHour-12:iHour }, 328 » » » { L"h", iHour>12?iHour-12:iHour },
329 » » » { (FX_LPCWSTR)L"M", iMin }, 329 » » » { L"M", iMin },
330 » » » { (FX_LPCWSTR)L"s", iSec }, 330 » » » { L"s", iSec },
331 }; 331 };
332 332
333 //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1); 333 //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1);
334 for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd); iIndex++) 334 for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd); iIndex++)
335 { 335 {
336 wchar_t tszValue[10]; 336 wchar_t tszValue[10];
337 //_itot(cTableAd[iIndex].iValue,tszValue,10); 337 //_itot(cTableAd[iIndex].iValue,tszValue,10);
338 CFX_WideString sValue; 338 CFX_WideString sValue;
339 » » » sValue.Format((FX_LPCWSTR)L"%d",cTableAd[iIndex].iValue) ; 339 » » » sValue.Format(L"%d",cTableAd[iIndex].iValue);
340 memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetL ength()+1), 340 memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetL ength()+1),
341 (sValue.GetLength()+1)*sizeof(wchar_t)); 341 (sValue.GetLength()+1)*sizeof(wchar_t));
342 342
343 //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d"); 343 //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d");
344 //strFormat.Format(strFormat,cTableAd[iIndex].iValue); 344 //strFormat.Format(strFormat,cTableAd[iIndex].iValue);
345 int iStart = 0; 345 int iStart = 0;
346 int iEnd; 346 int iEnd;
347 while((iEnd = cFormat.find((CFX_WideString)cTableAd[iInd ex].lpszJSMark,iStart)) != -1) 347 while((iEnd = cFormat.find((CFX_WideString)cTableAd[iInd ex].lpszJSMark,iStart)) != -1)
348 { 348 {
349 if (iEnd > 0) 349 if (iEnd > 0)
350 { 350 {
351 if (cFormat[iEnd-1] == L'%') 351 if (cFormat[iEnd-1] == L'%')
352 { 352 {
353 iStart = iEnd+1; 353 iStart = iEnd+1;
354 continue; 354 continue;
355 } 355 }
356 } 356 }
357 cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[iInd ex].lpszJSMark), tszValue); 357 cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[iInd ex].lpszJSMark), tszValue);
358 iStart = iEnd; 358 iStart = iEnd;
359 } 359 }
360 } 360 }
361 361
362 CFX_WideString strFormat; 362 CFX_WideString strFormat;
363 //» » strFormat.Format((FX_LPCWSTR)L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour, iMin, iSec); 363 //» » strFormat.Format(L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour , iMin, iSec);
364 // CString strFormat = cppTm.Format(cFormat.c_str()); 364 // CString strFormat = cppTm.Format(cFormat.c_str());
365 wchar_t buf[64] = {0}; 365 wchar_t buf[64] = {0};
366 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); 366 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time);
367 cFormat = buf; 367 cFormat = buf;
368 vRet = (FX_LPCWSTR)cFormat.c_str(); 368 vRet = (FX_LPCWSTR)cFormat.c_str();
369 //rtRet = strFormat.GetBuffer(strFormat.GetLength()+1); 369 //rtRet = strFormat.GetBuffer(strFormat.GetLength()+1);
370 return TRUE; 370 return TRUE;
371 } 371 }
372 return FALSE; 372 return FALSE;
373 } 373 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 // COleDateTime cppTm(iYear,iMonth+1,iDay,iHour,iMin,iSec); 411 // COleDateTime cppTm(iYear,iMonth+1,iDay,iHour,iMin,iSec);
412 //CString strFormat = cppTm.Format(cFormat.c_str()); 412 //CString strFormat = cppTm.Format(cFormat.c_str());
413 413
414 struct stru_TbConvertAd 414 struct stru_TbConvertAd
415 { 415 {
416 FX_LPCWSTR lpszJSMark; 416 FX_LPCWSTR lpszJSMark;
417 int iValue; 417 int iValue;
418 }; 418 };
419 419
420 stru_TbConvertAd cTableAd[] ={ 420 stru_TbConvertAd cTableAd[] ={
421 » » { (FX_LPCWSTR)L"m", iMonth+1 }, 421 » » { L"m", iMonth+1 },
422 » » { (FX_LPCWSTR)L"d", iDay }, 422 » » { L"d", iDay },
423 » » { (FX_LPCWSTR)L"H", iHour }, 423 » » { L"H", iHour },
424 » » { (FX_LPCWSTR)L"h", iHour>12?iHour-12:iHour }, 424 » » { L"h", iHour>12?iHour-12:iHour },
425 » » { (FX_LPCWSTR)L"M", iMin }, 425 » » { L"M", iMin },
426 » » { (FX_LPCWSTR)L"s", iSec }, 426 » » { L"s", iSec },
427 }; 427 };
428 428
429 //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1); 429 //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1);
430 for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd);iIndex++ ) 430 for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd);iIndex++ )
431 { 431 {
432 wchar_t tszValue[10]; 432 wchar_t tszValue[10];
433 //_itot(cTableAd[iIndex].iValue,tszValue,10); 433 //_itot(cTableAd[iIndex].iValue,tszValue,10);
434 CFX_WideString sValue; 434 CFX_WideString sValue;
435 » » sValue.Format((FX_LPCWSTR)L"%d",cTableAd[iIndex].iValue); 435 » » sValue.Format(L"%d",cTableAd[iIndex].iValue);
436 memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+ 1),sValue.GetLength()*sizeof(wchar_t)); 436 memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+ 1),sValue.GetLength()*sizeof(wchar_t));
437 437
438 438
439 //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d"); 439 //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d");
440 //strFormat.Format(strFormat,cTableAd[iIndex].iValue); 440 //strFormat.Format(strFormat,cTableAd[iIndex].iValue);
441 int iStart = 0; 441 int iStart = 0;
442 int iEnd; 442 int iEnd;
443 while((iEnd = cFormat.find((CFX_WideString)cTableAd[iIndex].lpsz JSMark,iStart)) != -1) 443 while((iEnd = cFormat.find((CFX_WideString)cTableAd[iIndex].lpsz JSMark,iStart)) != -1)
444 { 444 {
445 if (iEnd > 0) 445 if (iEnd > 0)
446 { 446 {
447 if (cFormat[iEnd-1] == L'%') 447 if (cFormat[iEnd-1] == L'%')
448 { 448 {
449 iStart = iEnd+1; 449 iStart = iEnd+1;
450 continue; 450 continue;
451 } 451 }
452 } 452 }
453 cFormat.replace(iEnd,FXSYS_wcslen(cTableAd[iIndex].lpszJ SMark),tszValue); 453 cFormat.replace(iEnd,FXSYS_wcslen(cTableAd[iIndex].lpszJ SMark),tszValue);
454 iStart = iEnd; 454 iStart = iEnd;
455 } 455 }
456 } 456 }
457 457
458 CFX_WideString strFormat; 458 CFX_WideString strFormat;
459 //» » strFormat.Format((FX_LPCWSTR)L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour, iMin, iSec); 459 //» » strFormat.Format(L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour , iMin, iSec);
460 // CString strFormat = cppTm.Format(cFormat.c_str()); 460 // CString strFormat = cppTm.Format(cFormat.c_str());
461 wchar_t buf[64] = {0}; 461 wchar_t buf[64] = {0};
462 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); 462 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time);
463 cFormat = buf; 463 cFormat = buf;
464 cPurpose = cFormat; 464 cPurpose = cFormat;
465 } 465 }
466 466
467 FX_BOOL util::printx(OBJ_METHOD_PARAMS) 467 FX_BOOL util::printx(OBJ_METHOD_PARAMS)
468 { 468 {
469 int iSize = params.size(); 469 int iSize = params.size();
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 } 636 }
637 637
638 FX_BOOL util::byteToChar(OBJ_METHOD_PARAMS) 638 FX_BOOL util::byteToChar(OBJ_METHOD_PARAMS)
639 { 639 {
640 int iSize = params.size(); 640 int iSize = params.size();
641 if (iSize == 0) 641 if (iSize == 0)
642 return FALSE; 642 return FALSE;
643 int nByte = (int)params[0]; 643 int nByte = (int)params[0];
644 unsigned char cByte = (unsigned char)nByte; 644 unsigned char cByte = (unsigned char)nByte;
645 CFX_WideString csValue; 645 CFX_WideString csValue;
646 » csValue.Format((FX_LPCWSTR)L"%c", cByte); 646 » csValue.Format(L"%c", cByte);
647 vRet = csValue; 647 vRet = csValue;
648 return TRUE; 648 return TRUE;
649 } 649 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/app.cpp ('k') | fpdfsdk/src/pdfwindow/PWL_Note.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698