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

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

Issue 1243883003: Fix else-after-returns throughout pdfium. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 5 months 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
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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 size_t i = 0;
102 bool bPercent = FALSE; 101 bool bPercent = FALSE;
103 » for (i=0; i<sFormat->length(); ++i) 102 » for (size_t i = 0; i < sFormat->length(); ++i)
104 { 103 {
105 wchar_t c = (*sFormat)[i]; 104 wchar_t c = (*sFormat)[i];
106 if (c == L'%') 105 if (c == L'%')
107 { 106 {
108 bPercent = true; 107 bPercent = true;
109 continue; 108 continue;
110 } 109 }
111 110
112 if (bPercent) 111 if (bPercent)
113 { 112 {
114 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') 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')
115 » » » { 114 {
116 return UTIL_INT; 115 return UTIL_INT;
117 } 116 }
118 » » » else if (c == L'e' || c == L'E' || c == L'f' || c == L'g ' || c == L'G') 117 » » » if (c == L'e' || c == L'E' || c == L'f' || c == L'g' || c == L'G')
119 { 118 {
120 return UTIL_DOUBLE; 119 return UTIL_DOUBLE;
121 } 120 }
122 » » » else if (c == L's' || c == L'S') 121 » » » if (c == L's' || c == L'S')
123 { 122 {
124 // Map s to S since we always deal internally 123 // Map s to S since we always deal internally
125 // with wchar_t strings. 124 // with wchar_t strings.
126 (*sFormat)[i] = L'S'; 125 (*sFormat)[i] = L'S';
127 return UTIL_STRING; 126 return UTIL_STRING;
128 } 127 }
129 » » » else if (c == L'.' || c == L'+' || c == L'-' || c == L'# ' || c == L' ' || CJS_PublicMethods::IsDigit(c)) 128 » » » if (c == L'.' || c == L'+' || c == L'-' || c == L'#' || c == L' ' || CJS_PublicMethods::IsDigit(c))
130 { 129 {
131 continue; 130 continue;
132 } 131 }
133 » » » else break; 132 » » » break;
134 } 133 }
135 } 134 }
136 135
137 return -1; 136 return -1;
138 } 137 }
139 138
140 FX_BOOL util::printf(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) 139 FX_BOOL util::printf(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
141 { 140 {
142 int iSize = params.size(); 141 int iSize = params.size();
143 if (iSize < 1) 142 if (iSize < 1)
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 jsDate.GetMinutes(), 260 jsDate.GetMinutes(),
262 jsDate.GetSeconds()); 261 jsDate.GetSeconds());
263 break; 262 break;
264 default: 263 default:
265 return FALSE; 264 return FALSE;
266 } 265 }
267 266
268 vRet = swResult.c_str(); 267 vRet = swResult.c_str();
269 return TRUE; 268 return TRUE;
270 } 269 }
271 » else if (p1.GetType() == VT_string) 270 if (p1.GetType() == VT_string)
272 { 271 {
273 std::basic_string<wchar_t> cFormat = p1.ToCFXWideString().c_str( ); 272 std::basic_string<wchar_t> cFormat = p1.ToCFXWideString().c_str( );
274 273
275 bool bXFAPicture = false; 274 bool bXFAPicture = false;
276 if (iSize > 2) 275 if (iSize > 2)
277 { 276 {
278 bXFAPicture = params[2].ToBool(); 277 bXFAPicture = params[2].ToBool();
279 } 278 }
280 279
281 if (bXFAPicture) 280 if (bXFAPicture)
(...skipping 21 matching lines...) Expand all
303 iMin = jsDate.GetMinutes(); 302 iMin = jsDate.GetMinutes();
304 iSec = jsDate.GetSeconds(); 303 iSec = jsDate.GetSeconds();
305 304
306 struct tm time = {}; 305 struct tm time = {};
307 time.tm_year = iYear-1900; 306 time.tm_year = iYear-1900;
308 time.tm_mon = iMonth; 307 time.tm_mon = iMonth;
309 time.tm_mday = iDay; 308 time.tm_mday = iDay;
310 time.tm_hour = iHour; 309 time.tm_hour = iHour;
311 time.tm_min = iMin; 310 time.tm_min = iMin;
312 time.tm_sec = iSec; 311 time.tm_sec = iSec;
313 //COleDateTime cppTm(iYear,iMonth+1,iDay,iHour,iMin,iSec);
314 //CString strFormat = cppTm.Format(cFormat.c_str());
315 312
316 struct stru_TbConvertAd 313 struct stru_TbConvertAd
317 { 314 {
318 const FX_WCHAR* lpszJSMark; 315 const FX_WCHAR* lpszJSMark;
319 int iValue; 316 int iValue;
320 }; 317 };
321 318
322 stru_TbConvertAd cTableAd[] ={ 319 stru_TbConvertAd cTableAd[] ={
323 { L"m", iMonth+1 }, 320 { L"m", iMonth+1 },
324 { L"d", iDay }, 321 { L"d", iDay },
325 { L"H", iHour }, 322 { L"H", iHour },
326 { L"h", iHour>12?iHour-12:iHour }, 323 { L"h", iHour>12?iHour-12:iHour },
327 { L"M", iMin }, 324 { L"M", iMin },
328 { L"s", iSec }, 325 { L"s", iSec },
329 }; 326 };
330 327
331 //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1);
332 for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd); iIndex++) 328 for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd); iIndex++)
333 { 329 {
334 wchar_t tszValue[10]; 330 wchar_t tszValue[10];
335 //_itot(cTableAd[iIndex].iValue,tszValue,10);
336 CFX_WideString sValue; 331 CFX_WideString sValue;
337 sValue.Format(L"%d",cTableAd[iIndex].iValue); 332 sValue.Format(L"%d",cTableAd[iIndex].iValue);
338 memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetL ength()+1), 333 memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetL ength()+1),
339 (sValue.GetLength()+1)*sizeof(wchar_t)); 334 (sValue.GetLength()+1)*sizeof(wchar_t));
340 335
341 //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d");
342 //strFormat.Format(strFormat,cTableAd[iIndex].iValue);
343 int iStart = 0; 336 int iStart = 0;
344 int iEnd; 337 int iEnd;
345 while((iEnd = cFormat.find(cTableAd[iIndex].lpszJSMark, iStart)) != -1) 338 while((iEnd = cFormat.find(cTableAd[iIndex].lpszJSMark, iStart)) != -1)
346 { 339 {
347 if (iEnd > 0) 340 if (iEnd > 0)
348 { 341 {
349 if (cFormat[iEnd-1] == L'%') 342 if (cFormat[iEnd-1] == L'%')
350 { 343 {
351 iStart = iEnd+1; 344 iStart = iEnd+1;
352 continue; 345 continue;
353 } 346 }
354 } 347 }
355 cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[iInd ex].lpszJSMark), tszValue); 348 cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[iInd ex].lpszJSMark), tszValue);
356 iStart = iEnd; 349 iStart = iEnd;
357 } 350 }
358 } 351 }
359 352
360 CFX_WideString strFormat; 353 CFX_WideString strFormat;
361 // strFormat.Format(L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour , iMin, iSec);
362 // CString strFormat = cppTm.Format(cFormat.c_str());
363 wchar_t buf[64] = {}; 354 wchar_t buf[64] = {};
364 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); 355 strFormat = wcsftime(buf, 64, cFormat.c_str(), &time);
365 cFormat = buf; 356 cFormat = buf;
366 vRet = cFormat.c_str(); 357 vRet = cFormat.c_str();
367 //rtRet = strFormat.GetBuffer(strFormat.GetLength()+1);
368 return TRUE; 358 return TRUE;
369 } 359 }
370 return FALSE; 360 return FALSE;
371 } 361 }
372 362
373 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)
374 { 364 {
375 std::wstring cFormat = cFormat2; 365 std::wstring cFormat = cFormat2;
376 366
377 if (bXFAPicture) 367 if (bXFAPicture)
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 if (c == '-' || c == '+') 608 if (c == '-' || c == '+')
619 c = (int)(unsigned char)*nptr++; /* skip sign */ 609 c = (int)(unsigned char)*nptr++; /* skip sign */
620 610
621 total = 0; 611 total = 0;
622 612
623 while (isdigit(c)) { 613 while (isdigit(c)) {
624 total = 10 * total + (c - '0'); /* accumulate digit */ 614 total = 10 * total + (c - '0'); /* accumulate digit */
625 c = (int)(unsigned char)*nptr++; /* get next char */ 615 c = (int)(unsigned char)*nptr++; /* get next char */
626 } 616 }
627 617
628 if (sign == '-') 618 return sign == '-' ? -total : total;
629 return -total;
630 else
631 return total; /* return result, negated if necessary */
632 } 619 }
633 620
634 FX_BOOL util::byteToChar(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Va lue& vRet, CFX_WideString& sError) 621 FX_BOOL util::byteToChar(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Va lue& vRet, CFX_WideString& sError)
635 { 622 {
636 int iSize = params.size(); 623 int iSize = params.size();
637 if (iSize == 0) 624 if (iSize == 0)
638 return FALSE; 625 return FALSE;
639 int nByte = params[0].ToInt(); 626 int nByte = params[0].ToInt();
640 unsigned char cByte = (unsigned char)nByte; 627 unsigned char cByte = (unsigned char)nByte;
641 CFX_WideString csValue; 628 CFX_WideString csValue;
642 csValue.Format(L"%c", cByte); 629 csValue.Format(L"%c", cByte);
643 vRet = csValue.c_str(); 630 vRet = csValue.c_str();
644 return TRUE; 631 return TRUE;
645 } 632 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698