Tidy up JS_Defines.h
[pdfium.git] / fpdfsdk / src / javascript / util.cpp
index 6563a10..a53bb17 100644 (file)
@@ -63,32 +63,32 @@ struct stru_TbConvert
 };
 
 const stru_TbConvert fcTable[] = {
-       { (FX_LPCWSTR)L"mmmm", (FX_LPCWSTR)L"%B" },
-       { (FX_LPCWSTR)L"mmm", (FX_LPCWSTR)L"%b" },
-       { (FX_LPCWSTR)L"mm",  (FX_LPCWSTR)L"%m" },
+       { L"mmmm", L"%B" },
+       { L"mmm", L"%b" },
+       { L"mm",  L"%m" },
        //"m"
-       { (FX_LPCWSTR)L"dddd", (FX_LPCWSTR)L"%A" },
-       { (FX_LPCWSTR)L"ddd", (FX_LPCWSTR)L"%a" },
-       { (FX_LPCWSTR)L"dd",  (FX_LPCWSTR)L"%d" },
+       { L"dddd", L"%A" },
+       { L"ddd", L"%a" },
+       { L"dd",  L"%d" },
        //"d",   "%w",
-       { (FX_LPCWSTR)L"yyyy", (FX_LPCWSTR)L"%Y" },
-       { (FX_LPCWSTR)L"yy",  (FX_LPCWSTR)L"%y" },
-       { (FX_LPCWSTR)L"HH",  (FX_LPCWSTR)L"%H" },
+       { L"yyyy", L"%Y" },
+       { L"yy",  L"%y" },
+       { L"HH",  L"%H" },
        //"H"
-       { (FX_LPCWSTR)L"hh",  (FX_LPCWSTR)L"%I" },
+       { L"hh",  L"%I" },
        //"h"
-       { (FX_LPCWSTR)L"MM",  (FX_LPCWSTR)L"%M" },
+       { L"MM",  L"%M" },
        //"M"
-       { (FX_LPCWSTR)L"ss",  (FX_LPCWSTR)L"%S" },
+       { L"ss",  L"%S" },
        //"s
-       { (FX_LPCWSTR)L"TT",  (FX_LPCWSTR)L"%p" },
+       { L"TT",  L"%p" },
        //"t"
 #if defined(_WIN32)
-       { (FX_LPCWSTR)L"tt",  (FX_LPCWSTR)L"%p" },
-       { (FX_LPCWSTR)L"h",  (FX_LPCWSTR)L"%#I" },
+       { L"tt",  L"%p" },
+       { L"h",  L"%#I" },
 #else
-       { (FX_LPCWSTR)L"tt",  (FX_LPCWSTR)L"%P" },
-       { (FX_LPCWSTR)L"h",  (FX_LPCWSTR)L"%l" },
+       { L"tt",  L"%P" },
+       { L"h",  L"%l" },
 #endif
 };
 
@@ -137,7 +137,7 @@ int util::ParstDataType(std::wstring* sFormat)
        return -1;
 }
 
-FX_BOOL util::printf(OBJ_METHOD_PARAMS)
+FX_BOOL util::printf(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, JS_ErrorString& sError)
 {
        int iSize = params.size();
        if (iSize < 1)
@@ -182,27 +182,27 @@ FX_BOOL util::printf(OBJ_METHOD_PARAMS)
                switch (ParstDataType(&c_strFormat))
                {
                        case UTIL_INT:
-                               strSegment.Format((FX_LPCWSTR)c_strFormat.c_str(),(int)params[iIndex]);
+                               strSegment.Format(c_strFormat.c_str(),(int)params[iIndex]);
                                break;
                        case UTIL_DOUBLE:
-                               strSegment.Format((FX_LPCWSTR)c_strFormat.c_str(),(double)params[iIndex]);
+                               strSegment.Format(c_strFormat.c_str(),(double)params[iIndex]);
                                break;
                        case UTIL_STRING:
-                               strSegment.Format((FX_LPCWSTR)c_strFormat.c_str(),(FX_LPCWSTR)params[iIndex].operator CFX_WideString());
+                               strSegment.Format(c_strFormat.c_str(),(FX_LPCWSTR)params[iIndex].operator CFX_WideString());
                                break;
                        default:
-                               strSegment.Format((FX_LPCWSTR)L"%S", (FX_LPCWSTR)c_strFormat.c_str());
+                               strSegment.Format(L"%S", c_strFormat.c_str());
                                break;
                }
-               c_strResult += (wchar_t*)strSegment.GetBuffer(strSegment.GetLength()+1);
+               c_strResult += strSegment.GetBuffer(strSegment.GetLength()+1);
        }
 
        c_strResult.erase(c_strResult.begin());
-       vRet = (FX_LPCWSTR)c_strResult.c_str();
+       vRet = c_strResult.c_str();
        return TRUE;
 }
 
-FX_BOOL util::printd(OBJ_METHOD_PARAMS)
+FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, JS_ErrorString& sError)
 {
        v8::Isolate* isolate = GetIsolate(cc);
 
@@ -236,7 +236,7 @@ FX_BOOL util::printd(OBJ_METHOD_PARAMS)
                switch (nFormat)
                {
                case 0:
-                       swResult.Format((FX_LPCWSTR)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(),
@@ -245,7 +245,7 @@ FX_BOOL util::printd(OBJ_METHOD_PARAMS)
                                jsDate.GetSeconds());
                        break;
                case 1:
-                       swResult.Format((FX_LPCWSTR)L"%04d.%02d.%02d %02d:%02d:%02d", 
+                       swResult.Format(L"%04d.%02d.%02d %02d:%02d:%02d", 
                                jsDate.GetYear(),
                                jsDate.GetMonth() + 1,
                                jsDate.GetDay(),
@@ -254,7 +254,7 @@ FX_BOOL util::printd(OBJ_METHOD_PARAMS)
                                jsDate.GetSeconds());
                        break;
                case 2:
-                       swResult.Format((FX_LPCWSTR)L"%04d/%02d/%02d %02d:%02d:%02d", 
+                       swResult.Format(L"%04d/%02d/%02d %02d:%02d:%02d", 
                                jsDate.GetYear(),
                                jsDate.GetMonth() + 1,
                                jsDate.GetDay(),
@@ -271,7 +271,7 @@ FX_BOOL util::printd(OBJ_METHOD_PARAMS)
        }
        else if (p1.GetType() == VT_string)
        {
-               std::basic_string<wchar_t> cFormat = (wchar_t*)(FX_LPCWSTR)p1.operator CFX_WideString();                
+               std::basic_string<wchar_t> cFormat = (FX_LPCWSTR)p1.operator CFX_WideString();          
 
                bool bXFAPicture = false;
                if (iSize > 2)
@@ -322,12 +322,12 @@ FX_BOOL util::printd(OBJ_METHOD_PARAMS)
                };
 
                stru_TbConvertAd cTableAd[] ={
-                       (FX_LPCWSTR)L"m", iMonth+1,
-                               (FX_LPCWSTR)L"d", iDay,
-                               (FX_LPCWSTR)L"H", iHour,
-                               (FX_LPCWSTR)L"h", iHour>12?iHour-12:iHour,
-                               (FX_LPCWSTR)L"M", iMin,
-                               (FX_LPCWSTR)L"s", iSec
+                       { L"m", iMonth+1 },
+                       { L"d", iDay },
+                       { L"H", iHour },
+                       { L"h", iHour>12?iHour-12:iHour },
+                       { L"M", iMin },
+                       { L"s", iSec },
                };
 
                //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1);
@@ -336,7 +336,7 @@ FX_BOOL util::printd(OBJ_METHOD_PARAMS)
                        wchar_t tszValue[10];
                        //_itot(cTableAd[iIndex].iValue,tszValue,10);
                        CFX_WideString sValue;
-                       sValue.Format((FX_LPCWSTR)L"%d",cTableAd[iIndex].iValue);
+                       sValue.Format(L"%d",cTableAd[iIndex].iValue);
                        memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+1),
                                (sValue.GetLength()+1)*sizeof(wchar_t));
 
@@ -360,12 +360,12 @@ FX_BOOL util::printd(OBJ_METHOD_PARAMS)
                }
 
                CFX_WideString strFormat;
-//             strFormat.Format((FX_LPCWSTR)L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour, iMin, iSec);
+//             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};
                strFormat = wcsftime(buf, 64, cFormat.c_str(), &time);
                cFormat = buf;
-               vRet = (FX_LPCWSTR)cFormat.c_str();
+               vRet = cFormat.c_str();
                //rtRet = strFormat.GetBuffer(strFormat.GetLength()+1);
                return TRUE;
        }
@@ -418,12 +418,12 @@ void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPictur
        };
 
        stru_TbConvertAd cTableAd[] ={
-               (FX_LPCWSTR)L"m", iMonth+1,
-                       (FX_LPCWSTR)L"d", iDay,
-                       (FX_LPCWSTR)L"H", iHour,
-                       (FX_LPCWSTR)L"h", iHour>12?iHour-12:iHour,
-                       (FX_LPCWSTR)L"M", iMin,
-                       (FX_LPCWSTR)L"s", iSec
+               { L"m", iMonth+1 },
+               { L"d", iDay },
+               { L"H", iHour },
+               { L"h", iHour>12?iHour-12:iHour },
+               { L"M", iMin },
+               { L"s", iSec },
        };
 
        //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1);
@@ -432,7 +432,7 @@ void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPictur
                wchar_t tszValue[10];
                //_itot(cTableAd[iIndex].iValue,tszValue,10);
                CFX_WideString sValue;
-               sValue.Format((FX_LPCWSTR)L"%d",cTableAd[iIndex].iValue);
+               sValue.Format(L"%d",cTableAd[iIndex].iValue);
                memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+1),sValue.GetLength()*sizeof(wchar_t));
 
 
@@ -456,7 +456,7 @@ void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPictur
        }
 
                CFX_WideString strFormat;
-//             strFormat.Format((FX_LPCWSTR)L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour, iMin, iSec);
+//             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};
                strFormat = wcsftime(buf, 64, cFormat.c_str(), &time);
@@ -464,15 +464,15 @@ void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPictur
                cPurpose = cFormat;
 }
 
-FX_BOOL util::printx(OBJ_METHOD_PARAMS)
+FX_BOOL util::printx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, JS_ErrorString& sError)
 {
        int iSize = params.size();
        if (iSize<2)
                return FALSE;
        CFX_WideString sFormat = params[0].operator CFX_WideString();
        CFX_WideString sSource = params[1].operator CFX_WideString();
-       std::string cFormat = (FX_LPCSTR)CFX_ByteString::FromUnicode(sFormat);
-       std::string cSource = (FX_LPCSTR)CFX_ByteString::FromUnicode(sSource);
+       std::string cFormat = CFX_ByteString::FromUnicode(sFormat).c_str();
+       std::string cSource = CFX_ByteString::FromUnicode(sSource).c_str();
        std::string cDest;
        printx(cFormat,cSource,cDest);
        vRet = cDest.c_str();
@@ -578,7 +578,7 @@ void util::printx(const std::string &cFormat,const std::string &cSource2,std::st
        }
 }
 
-FX_BOOL util::scand(OBJ_METHOD_PARAMS)
+FX_BOOL util::scand(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, JS_ErrorString& sError)
 {
        v8::Isolate* isolate = GetIsolate(cc);
        int iSize = params.size();
@@ -635,7 +635,7 @@ FX_INT64 FX_atoi64(const char *nptr)
             return total;   /* return result, negated if necessary */
 }
 
-FX_BOOL util::byteToChar(OBJ_METHOD_PARAMS)
+FX_BOOL util::byteToChar(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, JS_ErrorString& sError)
 {
        int iSize = params.size();
        if (iSize == 0)
@@ -643,7 +643,7 @@ FX_BOOL util::byteToChar(OBJ_METHOD_PARAMS)
        int nByte = (int)params[0];
        unsigned char cByte = (unsigned char)nByte;
        CFX_WideString csValue;
-       csValue.Format((FX_LPCWSTR)L"%c", cByte);
+       csValue.Format(L"%c", cByte);
        vRet = csValue; 
        return TRUE;
 }