Fix some clang warnings with -Wmissing-braces in pdfium.
[pdfium.git] / fpdfsdk / src / javascript / util.cpp
index f7e97ac..c4f0309 100644 (file)
@@ -1,7 +1,7 @@
 // Copyright 2014 PDFium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
+
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
 #include "../../include/javascript/JavaScript.h"
@@ -58,8 +58,8 @@ util::~util(void)
 
 struct stru_TbConvert
 {
-       FX_LPCWSTR lpszJSMark;
-       FX_LPCWSTR lpszCppMark;
+       const FX_WCHAR* lpszJSMark;
+       const FX_WCHAR* lpszCppMark;
 };
 
 const stru_TbConvert fcTable[] = {
@@ -152,7 +152,7 @@ FX_BOOL util::printf(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
                iOffend = c_ConvChar.find(L"%",iOffset+1);
                std::wstring strSub;
                if (iOffend == -1)
-                       strSub = c_ConvChar.substr(iOffset);                    
+                       strSub = c_ConvChar.substr(iOffset);
                else
                        strSub = c_ConvChar.substr(iOffset ,iOffend - iOffset);
                c_strConvers.push_back(strSub);
@@ -235,7 +235,7 @@ FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
                switch (nFormat)
                {
                case 0:
-                       swResult.Format(L"D:%04d%02d%02d%02d%02d%02d", 
+                       swResult.Format(L"D:%04d%02d%02d%02d%02d%02d",
                                jsDate.GetYear(),
                                jsDate.GetMonth() + 1,
                                jsDate.GetDay(),
@@ -244,7 +244,7 @@ FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
                                jsDate.GetSeconds());
                        break;
                case 1:
-                       swResult.Format(L"%04d.%02d.%02d %02d:%02d:%02d", 
+                       swResult.Format(L"%04d.%02d.%02d %02d:%02d:%02d",
                                jsDate.GetYear(),
                                jsDate.GetMonth() + 1,
                                jsDate.GetDay(),
@@ -253,7 +253,7 @@ FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
                                jsDate.GetSeconds());
                        break;
                case 2:
-                       swResult.Format(L"%04d/%02d/%02d %02d:%02d:%02d", 
+                       swResult.Format(L"%04d/%02d/%02d %02d:%02d:%02d",
                                jsDate.GetYear(),
                                jsDate.GetMonth() + 1,
                                jsDate.GetDay(),
@@ -265,7 +265,7 @@ FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
                        return FALSE;
                }
 
-               vRet = swResult;
+               vRet = swResult.c_str();
                return TRUE;
        }
        else if (p1.GetType() == VT_string)
@@ -288,9 +288,9 @@ FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
                {
                        int iStart = 0;
                        int iEnd;
-                       while((iEnd = cFormat.find((CFX_WideString)fcTable[iIndex].lpszJSMark, iStart)) != -1)
+                       while((iEnd = cFormat.find(fcTable[iIndex].lpszJSMark, iStart)) != -1)
                        {
-                               cFormat.replace(iEnd, FXSYS_wcslen(fcTable[iIndex].lpszJSMark), (CFX_WideString)fcTable[iIndex].lpszCppMark);
+                               cFormat.replace(iEnd, FXSYS_wcslen(fcTable[iIndex].lpszJSMark), fcTable[iIndex].lpszCppMark);
                                iStart = iEnd;
                        }
                }
@@ -303,7 +303,7 @@ FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
                iMin = jsDate.GetMinutes();
                iSec = jsDate.GetSeconds();
 
-               struct tm time = {0};
+               struct tm time = {};
                time.tm_year = iYear-1900;
                time.tm_mon = iMonth;
                time.tm_mday = iDay;
@@ -315,7 +315,7 @@ FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
 
                struct stru_TbConvertAd
                {
-                       FX_LPCWSTR lpszJSMark;
+                       const FX_WCHAR* lpszJSMark;
                        int     iValue;
                };
 
@@ -342,7 +342,7 @@ FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
                        //strFormat.Format(strFormat,cTableAd[iIndex].iValue);
                        int iStart = 0;
                        int iEnd;
-                       while((iEnd = cFormat.find((CFX_WideString)cTableAd[iIndex].lpszJSMark,iStart)) != -1)
+                       while((iEnd = cFormat.find(cTableAd[iIndex].lpszJSMark, iStart)) != -1)
                        {
                                if (iEnd > 0)
                                {
@@ -360,7 +360,7 @@ FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
                CFX_WideString strFormat;
 //             strFormat.Format(L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour, iMin, iSec);
 //             CString strFormat = cppTm.Format(cFormat.c_str());
-               wchar_t buf[64] = {0};
+               wchar_t buf[64] = {};
                strFormat = wcsftime(buf, 64, cFormat.c_str(), &time);
                cFormat = buf;
                vRet = cFormat.c_str();
@@ -373,7 +373,7 @@ FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
 void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPicture, std::wstring &cPurpose)
 {
        std::wstring cFormat = cFormat2;
-           
+
        if (bXFAPicture)
        {
                return ; //currently, it doesn't support XFAPicture.
@@ -384,9 +384,9 @@ void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPictur
        {
                int iStart = 0;
                int iEnd;
-               while((iEnd = cFormat.find((CFX_WideString)fcTable[iIndex].lpszJSMark,iStart)) != -1)
+               while((iEnd = cFormat.find(fcTable[iIndex].lpszJSMark, iStart)) != -1)
                {
-                       cFormat.replace(iEnd,FXSYS_wcslen(fcTable[iIndex].lpszJSMark), (CFX_WideString)fcTable[iIndex].lpszCppMark);
+                       cFormat.replace(iEnd,FXSYS_wcslen(fcTable[iIndex].lpszJSMark), fcTable[iIndex].lpszCppMark);
                        iStart = iEnd;
                }
        }
@@ -399,7 +399,7 @@ void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPictur
        iMin = jsDate.GetMinutes();
        iSec = jsDate.GetSeconds();
 
-       struct tm time = {0};
+       struct tm time = {};
        time.tm_year = iYear-1900;
        time.tm_mon = iMonth;
        time.tm_mday = iDay;
@@ -411,7 +411,7 @@ void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPictur
 
        struct stru_TbConvertAd
        {
-               FX_LPCWSTR lpszJSMark;
+               const FX_WCHAR* lpszJSMark;
                int     iValue;
        };
 
@@ -438,7 +438,7 @@ void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPictur
                //strFormat.Format(strFormat,cTableAd[iIndex].iValue);
                int iStart = 0;
                int iEnd;
-               while((iEnd = cFormat.find((CFX_WideString)cTableAd[iIndex].lpszJSMark,iStart)) != -1)
+               while((iEnd = cFormat.find(cTableAd[iIndex].lpszJSMark, iStart)) != -1)
                {
                        if (iEnd > 0)
                        {
@@ -454,7 +454,7 @@ void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPictur
        }
 
        CFX_WideString strFormat;
-       wchar_t buf[64] = {0};
+       wchar_t buf[64] = {};
        strFormat = wcsftime(buf, 64, cFormat.c_str(), &time);
        cFormat = buf;
        cPurpose = cFormat;
@@ -588,8 +588,8 @@ FX_BOOL util::scand(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
        {
                FX_BOOL bWrongFormat = FALSE;
                dDate = CJS_PublicMethods::MakeRegularDate(sDate,sFormat,bWrongFormat);
-       }       
-       
+       }
+
        if (!JS_PortIsNan(dDate))
        {
                CJS_Date date(isolate,dDate);
@@ -603,10 +603,10 @@ FX_BOOL util::scand(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value&
        return TRUE;
 }
 
-FX_INT64 FX_atoi64(const char *nptr)
+int64_t FX_atoi64(const char *nptr)
 {
         int c;              /* current char */
-        FX_INT64 total;      /* current total */
+        int64_t total;      /* current total */
         int sign;           /* if '-', then negative, otherwise positive */
 
         /* skip whitespace */
@@ -640,6 +640,6 @@ FX_BOOL util::byteToChar(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Va
        unsigned char cByte = (unsigned char)nByte;
        CFX_WideString csValue;
        csValue.Format(L"%c", cByte);
-       vRet = csValue; 
+       vRet = csValue.c_str();
        return TRUE;
 }