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

Side by Side Diff: xfa/fxfa/fm2js/xfa_fm2jscontext.cpp

Issue 2047103004: xfa_fm2jscontext method cleanup - pt VII (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@c_method_remove
Patch Set: Created 4 years, 6 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
« no previous file with comments | « no previous file | no next file » | 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 "xfa/fxfa/fm2js/xfa_fm2jscontext.h" 7 #include "xfa/fxfa/fm2js/xfa_fm2jscontext.h"
8 8
9 #include <time.h> 9 #include <time.h>
10 10
(...skipping 3671 matching lines...) Expand 10 before | Expand all | Expand 10 after
3682 szResultString.Clear(); 3682 szResultString.Clear();
3683 szResultString << FX_UTF8Encode(wsXMLBuf.GetBuffer(), wsXMLBuf.GetLength()) 3683 szResultString << FX_UTF8Encode(wsXMLBuf.GetBuffer(), wsXMLBuf.GetLength())
3684 .AsStringC(); 3684 .AsStringC();
3685 } 3685 }
3686 3686
3687 // static 3687 // static
3688 void CXFA_FM2JSContext::Encode(CFXJSE_Value* pThis, 3688 void CXFA_FM2JSContext::Encode(CFXJSE_Value* pThis,
3689 const CFX_ByteStringC& szFuncName, 3689 const CFX_ByteStringC& szFuncName,
3690 CFXJSE_Arguments& args) { 3690 CFXJSE_Arguments& args) {
3691 int32_t argc = args.GetLength(); 3691 int32_t argc = args.GetLength();
3692 if (argc < 1 || argc > 2) {
3693 ToJSContext(pThis, nullptr)
3694 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Encode");
3695 return;
3696 }
3697
3692 if (argc == 1) { 3698 if (argc == 1) {
3693 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); 3699 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
3694 if (ValueIsNull(pThis, argOne.get())) { 3700 if (ValueIsNull(pThis, argOne.get())) {
3695 args.GetReturnValue()->SetNull(); 3701 args.GetReturnValue()->SetNull();
3696 } else { 3702 return;
3697 CFX_ByteString toEncodeString;
3698 ValueToUTF8String(argOne.get(), toEncodeString);
3699 CFX_ByteTextBuf resultBuf;
3700 EncodeURL(toEncodeString.AsStringC(), resultBuf);
3701 args.GetReturnValue()->SetString(resultBuf.AsStringC());
3702 } 3703 }
3703 } else if (argc == 2) { 3704
3704 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); 3705 CFX_ByteString toEncodeString;
3705 std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1); 3706 ValueToUTF8String(argOne.get(), toEncodeString);
3706 if (ValueIsNull(pThis, argOne.get()) || ValueIsNull(pThis, argTwo.get())) { 3707 CFX_ByteTextBuf resultBuf;
3707 args.GetReturnValue()->SetNull(); 3708 EncodeURL(toEncodeString.AsStringC(), resultBuf);
3708 } else { 3709 args.GetReturnValue()->SetString(resultBuf.AsStringC());
3709 CFX_ByteString toEncodeString; 3710 return;
3710 ValueToUTF8String(argOne.get(), toEncodeString);
3711 CFX_ByteString identifyString;
3712 ValueToUTF8String(argTwo.get(), identifyString);
3713 CFX_ByteTextBuf resultBuf;
3714 if (identifyString.EqualNoCase("html")) {
3715 EncodeHTML(toEncodeString.AsStringC(), resultBuf);
3716 } else if (identifyString.EqualNoCase("xml")) {
3717 EncodeXML(toEncodeString.AsStringC(), resultBuf);
3718 } else {
3719 EncodeURL(toEncodeString.AsStringC(), resultBuf);
3720 }
3721 args.GetReturnValue()->SetString(resultBuf.AsStringC());
3722 }
3723 } else {
3724 ToJSContext(pThis, nullptr)
3725 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Encode");
3726 } 3711 }
3712
3713 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
3714 std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1);
3715 if (ValueIsNull(pThis, argOne.get()) || ValueIsNull(pThis, argTwo.get())) {
3716 args.GetReturnValue()->SetNull();
3717 return;
3718 }
3719
3720 CFX_ByteString toEncodeString;
3721 ValueToUTF8String(argOne.get(), toEncodeString);
3722 CFX_ByteString identifyString;
3723 ValueToUTF8String(argTwo.get(), identifyString);
3724 CFX_ByteTextBuf resultBuf;
3725 if (identifyString.EqualNoCase("html"))
3726 EncodeHTML(toEncodeString.AsStringC(), resultBuf);
3727 else if (identifyString.EqualNoCase("xml"))
3728 EncodeXML(toEncodeString.AsStringC(), resultBuf);
3729 else
3730 EncodeURL(toEncodeString.AsStringC(), resultBuf);
3731
3732 args.GetReturnValue()->SetString(resultBuf.AsStringC());
3727 } 3733 }
3728 3734
3729 // static 3735 // static
3730 void CXFA_FM2JSContext::EncodeURL(const CFX_ByteStringC& szURLString, 3736 void CXFA_FM2JSContext::EncodeURL(const CFX_ByteStringC& szURLString,
3731 CFX_ByteTextBuf& szResultBuf) { 3737 CFX_ByteTextBuf& szResultBuf) {
3732 CFX_WideString wsURLString = CFX_WideString::FromUTF8(szURLString); 3738 CFX_WideString wsURLString = CFX_WideString::FromUTF8(szURLString);
3733 CFX_WideTextBuf wsResultBuf; 3739 CFX_WideTextBuf wsResultBuf;
3734 FX_WCHAR ch = 0;
3735 int32_t iLength = wsURLString.GetLength();
3736 FX_WCHAR strEncode[4]; 3740 FX_WCHAR strEncode[4];
3737 strEncode[0] = '%'; 3741 strEncode[0] = '%';
3738 strEncode[3] = 0; 3742 strEncode[3] = 0;
3739 FX_WCHAR strUnsafe[] = {' ', '<', '>', '"', '#', '%', '{', '}', 3743 FX_WCHAR strUnsafe[] = {' ', '<', '>', '"', '#', '%', '{', '}',
3740 '|', '\\', '^', '~', '[', ']', '`'}; 3744 '|', '\\', '^', '~', '[', ']', '`'};
3741 FX_WCHAR strReserved[] = {';', '/', '?', ':', '@', '=', '&'}; 3745 FX_WCHAR strReserved[] = {';', '/', '?', ':', '@', '=', '&'};
3742 FX_WCHAR strSpecial[] = {'$', '-', '+', '!', '*', '\'', '(', ')', ','}; 3746 FX_WCHAR strSpecial[] = {'$', '-', '+', '!', '*', '\'', '(', ')', ','};
3743 const FX_WCHAR* strCode = L"0123456789abcdef"; 3747 const FX_WCHAR* strCode = L"0123456789abcdef";
3744 for (int32_t u = 0; u < iLength; ++u) { 3748 for (int32_t u = 0; u < wsURLString.GetLength(); ++u) {
3745 ch = wsURLString.GetAt(u); 3749 FX_WCHAR ch = wsURLString.GetAt(u);
3746 int32_t i = 0; 3750 int32_t i = 0;
3747 int32_t iCount = sizeof(strUnsafe) / sizeof(strUnsafe[0]); 3751 int32_t iCount = FX_ArraySize(strUnsafe);
3748 while (i < iCount) { 3752 while (i < iCount) {
3749 if (ch == strUnsafe[i]) { 3753 if (ch == strUnsafe[i]) {
3750 int32_t iIndex = ch / 16; 3754 int32_t iIndex = ch / 16;
3751 strEncode[1] = strCode[iIndex]; 3755 strEncode[1] = strCode[iIndex];
3752 strEncode[2] = strCode[ch - iIndex * 16]; 3756 strEncode[2] = strCode[ch - iIndex * 16];
3753 wsResultBuf << FX_WSTRC(strEncode); 3757 wsResultBuf << FX_WSTRC(strEncode);
3754 break; 3758 break;
3755 } 3759 }
3756 ++i; 3760 ++i;
3757 } 3761 }
3758 if (i < iCount) { 3762 if (i < iCount)
3759 continue; 3763 continue;
3760 } 3764
3761 i = 0; 3765 i = 0;
3762 iCount = sizeof(strReserved) / sizeof(strReserved[0]); 3766 iCount = FX_ArraySize(strReserved);
3763 while (i < iCount) { 3767 while (i < iCount) {
3764 if (ch == strReserved[i]) { 3768 if (ch == strReserved[i]) {
3765 int32_t iIndex = ch / 16; 3769 int32_t iIndex = ch / 16;
3766 strEncode[1] = strCode[iIndex]; 3770 strEncode[1] = strCode[iIndex];
3767 strEncode[2] = strCode[ch - iIndex * 16]; 3771 strEncode[2] = strCode[ch - iIndex * 16];
3768 wsResultBuf << FX_WSTRC(strEncode); 3772 wsResultBuf << FX_WSTRC(strEncode);
3769 break; 3773 break;
3770 } 3774 }
3771 ++i; 3775 ++i;
3772 } 3776 }
3773 if (i < iCount) { 3777 if (i < iCount)
3774 continue; 3778 continue;
3775 } 3779
3776 i = 0; 3780 i = 0;
3777 iCount = sizeof(strSpecial) / sizeof(strSpecial[0]); 3781 iCount = FX_ArraySize(strSpecial);
3778 while (i < iCount) { 3782 while (i < iCount) {
3779 if (ch == strSpecial[i]) { 3783 if (ch == strSpecial[i]) {
3780 wsResultBuf.AppendChar(ch); 3784 wsResultBuf.AppendChar(ch);
3781 break; 3785 break;
3782 } 3786 }
3783 ++i; 3787 ++i;
3784 } 3788 }
3785 if (i < iCount) { 3789 if (i < iCount)
3786 continue; 3790 continue;
3787 } 3791
3788 if (ch >= 0x80 && ch <= 0xff) { 3792 if ((ch >= 0x80 && ch <= 0xff) || ch <= 0x1f || ch == 0x7f) {
3789 int32_t iIndex = ch / 16; 3793 int32_t iIndex = ch / 16;
3790 strEncode[1] = strCode[iIndex]; 3794 strEncode[1] = strCode[iIndex];
3791 strEncode[2] = strCode[ch - iIndex * 16]; 3795 strEncode[2] = strCode[ch - iIndex * 16];
3792 wsResultBuf << FX_WSTRC(strEncode);
3793 } else if (ch <= 0x1f || ch == 0x7f) {
3794 int32_t iIndex = ch / 16;
3795 strEncode[1] = strCode[iIndex];
3796 strEncode[2] = strCode[ch - iIndex * 16];
3797 wsResultBuf << FX_WSTRC(strEncode); 3796 wsResultBuf << FX_WSTRC(strEncode);
3798 } else if (ch >= 0x20 && ch <= 0x7e) { 3797 } else if (ch >= 0x20 && ch <= 0x7e) {
3799 wsResultBuf.AppendChar(ch); 3798 wsResultBuf.AppendChar(ch);
3800 } else { 3799 } else {
3801 const FX_WCHAR iRadix = 16; 3800 const FX_WCHAR iRadix = 16;
3802 CFX_WideString strTmp; 3801 CFX_WideString strTmp;
3803 while (ch >= iRadix) { 3802 while (ch >= iRadix) {
3804 FX_WCHAR tmp = strCode[ch % iRadix]; 3803 FX_WCHAR tmp = strCode[ch % iRadix];
3805 ch /= iRadix; 3804 ch /= iRadix;
3806 strTmp += tmp; 3805 strTmp += tmp;
3807 } 3806 }
3808 strTmp += strCode[ch]; 3807 strTmp += strCode[ch];
3809 int32_t iLen = strTmp.GetLength(); 3808 int32_t iLen = strTmp.GetLength();
3810 if (iLen < 2) { 3809 if (iLen < 2)
3811 break; 3810 break;
3812 } 3811
3813 int32_t iIndex = 0; 3812 int32_t iIndex = 0;
3814 if (iLen % 2 != 0) { 3813 if (iLen % 2 != 0) {
3815 strEncode[1] = '0'; 3814 strEncode[1] = '0';
3816 strEncode[2] = strTmp.GetAt(iLen - 1); 3815 strEncode[2] = strTmp.GetAt(iLen - 1);
3817 iIndex = iLen - 2; 3816 iIndex = iLen - 2;
3818 } else { 3817 } else {
3819 strEncode[1] = strTmp.GetAt(iLen - 1); 3818 strEncode[1] = strTmp.GetAt(iLen - 1);
3820 strEncode[2] = strTmp.GetAt(iLen - 2); 3819 strEncode[2] = strTmp.GetAt(iLen - 2);
3821 iIndex = iLen - 3; 3820 iIndex = iLen - 3;
3822 } 3821 }
3823 wsResultBuf << FX_WSTRC(strEncode); 3822 wsResultBuf << FX_WSTRC(strEncode);
3824 while (iIndex > 0) { 3823 while (iIndex > 0) {
3825 strEncode[1] = strTmp.GetAt(iIndex); 3824 strEncode[1] = strTmp.GetAt(iIndex);
3826 strEncode[2] = strTmp.GetAt(iIndex - 1); 3825 strEncode[2] = strTmp.GetAt(iIndex - 1);
3827 iIndex -= 2; 3826 iIndex -= 2;
3828 wsResultBuf << FX_WSTRC(strEncode); 3827 wsResultBuf << FX_WSTRC(strEncode);
3829 } 3828 }
3830 } 3829 }
3831 } 3830 }
3832 wsResultBuf.AppendChar(0); 3831 wsResultBuf.AppendChar(0);
3833 szResultBuf.Clear(); 3832 szResultBuf.Clear();
3833
3834 szResultBuf << FX_UTF8Encode(wsResultBuf.GetBuffer(), wsResultBuf.GetLength()) 3834 szResultBuf << FX_UTF8Encode(wsResultBuf.GetBuffer(), wsResultBuf.GetLength())
3835 .AsStringC(); 3835 .AsStringC();
3836 } 3836 }
3837 3837
3838 // static 3838 // static
3839 void CXFA_FM2JSContext::EncodeHTML(const CFX_ByteStringC& szHTMLString, 3839 void CXFA_FM2JSContext::EncodeHTML(const CFX_ByteStringC& szHTMLString,
3840 CFX_ByteTextBuf& szResultBuf) { 3840 CFX_ByteTextBuf& szResultBuf) {
3841 CFX_ByteString str = szHTMLString.c_str(); 3841 CFX_ByteString str = szHTMLString.c_str();
3842 CFX_WideString wsHTMLString = CFX_WideString::FromUTF8(str.AsStringC()); 3842 CFX_WideString wsHTMLString = CFX_WideString::FromUTF8(str.AsStringC());
3843 const FX_WCHAR* strCode = L"0123456789abcdef"; 3843 const FX_WCHAR* strCode = L"0123456789abcdef";
3844 FX_WCHAR strEncode[9]; 3844 FX_WCHAR strEncode[9];
3845 strEncode[0] = '&'; 3845 strEncode[0] = '&';
3846 strEncode[1] = '#'; 3846 strEncode[1] = '#';
3847 strEncode[2] = 'x'; 3847 strEncode[2] = 'x';
3848 strEncode[5] = ';'; 3848 strEncode[5] = ';';
3849 strEncode[6] = 0; 3849 strEncode[6] = 0;
3850 strEncode[7] = ';'; 3850 strEncode[7] = ';';
3851 strEncode[8] = 0; 3851 strEncode[8] = 0;
3852 CFX_WideTextBuf wsResultBuf; 3852 CFX_WideTextBuf wsResultBuf;
3853 uint32_t ch = 0;
3854 int32_t iLen = wsHTMLString.GetLength(); 3853 int32_t iLen = wsHTMLString.GetLength();
3855 int32_t i = 0; 3854 int32_t i = 0;
3856 const FX_WCHAR* pData = wsHTMLString.c_str(); 3855 const FX_WCHAR* pData = wsHTMLString.c_str();
3857 int32_t iIndex = 0;
3858 CFX_WideString htmlReserve;
3859 while (i < iLen) { 3856 while (i < iLen) {
3860 ch = pData[i]; 3857 uint32_t ch = pData[i];
3861 htmlReserve.clear(); 3858 CFX_WideString htmlReserve;
3862 if (HTMLCode2STR(ch, htmlReserve)) { 3859 if (HTMLCode2STR(ch, htmlReserve)) {
3863 wsResultBuf.AppendChar(L'&'); 3860 wsResultBuf.AppendChar(L'&');
3864 wsResultBuf << htmlReserve; 3861 wsResultBuf << htmlReserve;
3865 wsResultBuf.AppendChar(L';'); 3862 wsResultBuf.AppendChar(L';');
3863 } else if (ch >= 32 && ch <= 126) {
3864 wsResultBuf.AppendChar((FX_WCHAR)ch);
3865 } else if (ch < 256) {
3866 int32_t iIndex = ch / 16;
3867 strEncode[3] = strCode[iIndex];
3868 strEncode[4] = strCode[ch - iIndex * 16];
3869 strEncode[5] = ';';
3870 strEncode[6] = 0;
3871 wsResultBuf << FX_WSTRC(strEncode);
3866 } else { 3872 } else {
3867 if (ch >= 32 && ch <= 126) { 3873 int32_t iBigByte = ch / 256;
3868 wsResultBuf.AppendChar((FX_WCHAR)ch); 3874 int32_t iLittleByte = ch % 256;
3869 } else if (ch < 256) { 3875 strEncode[3] = strCode[iBigByte / 16];
3870 iIndex = ch / 16; 3876 strEncode[4] = strCode[iBigByte % 16];
3871 strEncode[3] = strCode[iIndex]; 3877 strEncode[5] = strCode[iLittleByte / 16];
3872 strEncode[4] = strCode[ch - iIndex * 16]; 3878 strEncode[6] = strCode[iLittleByte % 16];
3873 strEncode[5] = ';'; 3879 wsResultBuf << FX_WSTRC(strEncode);
3874 strEncode[6] = 0;
3875 wsResultBuf << FX_WSTRC(strEncode);
3876 } else {
3877 int32_t iBigByte = ch / 256;
3878 int32_t iLittleByte = ch % 256;
3879 strEncode[3] = strCode[iBigByte / 16];
3880 strEncode[4] = strCode[iBigByte % 16];
3881 strEncode[5] = strCode[iLittleByte / 16];
3882 strEncode[6] = strCode[iLittleByte % 16];
3883 wsResultBuf << FX_WSTRC(strEncode);
3884 }
3885 } 3880 }
3886 ++i; 3881 ++i;
3887 } 3882 }
3888 wsResultBuf.AppendChar(0); 3883 wsResultBuf.AppendChar(0);
3889 szResultBuf.Clear(); 3884 szResultBuf.Clear();
3885
3890 szResultBuf << FX_UTF8Encode(wsResultBuf.GetBuffer(), wsResultBuf.GetLength()) 3886 szResultBuf << FX_UTF8Encode(wsResultBuf.GetBuffer(), wsResultBuf.GetLength())
3891 .AsStringC(); 3887 .AsStringC();
3892 } 3888 }
3893 3889
3894 // static 3890 // static
3895 void CXFA_FM2JSContext::EncodeXML(const CFX_ByteStringC& szXMLString, 3891 void CXFA_FM2JSContext::EncodeXML(const CFX_ByteStringC& szXMLString,
3896 CFX_ByteTextBuf& szResultBuf) { 3892 CFX_ByteTextBuf& szResultBuf) {
3897 CFX_WideString wsXMLString = CFX_WideString::FromUTF8(szXMLString); 3893 CFX_WideString wsXMLString = CFX_WideString::FromUTF8(szXMLString);
3898 CFX_WideTextBuf wsResultBuf; 3894 CFX_WideTextBuf wsResultBuf;
3899 enum {
3900 QUOT,
3901 AMP,
3902 APOS,
3903 LT,
3904 GT,
3905 };
3906 FX_WCHAR strEncode[9]; 3895 FX_WCHAR strEncode[9];
3907 strEncode[0] = '&'; 3896 strEncode[0] = '&';
3908 strEncode[1] = '#'; 3897 strEncode[1] = '#';
3909 strEncode[2] = 'x'; 3898 strEncode[2] = 'x';
3910 strEncode[5] = ';'; 3899 strEncode[5] = ';';
3911 strEncode[6] = 0; 3900 strEncode[6] = 0;
3912 strEncode[7] = ';'; 3901 strEncode[7] = ';';
3913 strEncode[8] = 0; 3902 strEncode[8] = 0;
3914 const FX_WCHAR* const strName[] = {L"quot", L"amp", L"apos", L"lt", L"gt"};
3915 const FX_WCHAR* strCode = L"0123456789abcdef"; 3903 const FX_WCHAR* strCode = L"0123456789abcdef";
3916 FX_WCHAR ch = 0;
3917 int32_t iLength = wsXMLString.GetLength();
3918 int32_t iIndex = 0;
3919 int32_t u = 0;
3920 const FX_WCHAR* pData = wsXMLString.c_str(); 3904 const FX_WCHAR* pData = wsXMLString.c_str();
3921 for (u = 0; u < iLength; ++u) { 3905 for (int32_t u = 0; u < wsXMLString.GetLength(); ++u) {
3922 ch = pData[u]; 3906 FX_WCHAR ch = pData[u];
3923 switch (ch) { 3907 switch (ch) {
3924 case '"': 3908 case '"':
3925 wsResultBuf.AppendChar('&'); 3909 wsResultBuf.AppendChar('&');
3926 wsResultBuf << CFX_WideStringC(strName[QUOT]); 3910 wsResultBuf << CFX_WideStringC(L"quot");
3927 wsResultBuf.AppendChar(';'); 3911 wsResultBuf.AppendChar(';');
3928 break; 3912 break;
3929 case '&': 3913 case '&':
3930 wsResultBuf.AppendChar('&'); 3914 wsResultBuf.AppendChar('&');
3931 wsResultBuf << CFX_WideStringC(strName[AMP]); 3915 wsResultBuf << CFX_WideStringC(L"amp");
3932 wsResultBuf.AppendChar(';'); 3916 wsResultBuf.AppendChar(';');
3933 break; 3917 break;
3934 case '\'': 3918 case '\'':
3935 wsResultBuf.AppendChar('&'); 3919 wsResultBuf.AppendChar('&');
3936 wsResultBuf << CFX_WideStringC(strName[APOS]); 3920 wsResultBuf << CFX_WideStringC(L"apos");
3937 wsResultBuf.AppendChar(';'); 3921 wsResultBuf.AppendChar(';');
3938 break; 3922 break;
3939 case '<': 3923 case '<':
3940 wsResultBuf.AppendChar('&'); 3924 wsResultBuf.AppendChar('&');
3941 wsResultBuf << CFX_WideStringC(strName[LT]); 3925 wsResultBuf << CFX_WideStringC(L"lt");
3942 wsResultBuf.AppendChar(';'); 3926 wsResultBuf.AppendChar(';');
3943 break; 3927 break;
3944 case '>': 3928 case '>':
3945 wsResultBuf.AppendChar('&'); 3929 wsResultBuf.AppendChar('&');
3946 wsResultBuf << CFX_WideStringC(strName[GT]); 3930 wsResultBuf << CFX_WideStringC(L"gt");
3947 wsResultBuf.AppendChar(';'); 3931 wsResultBuf.AppendChar(';');
3948 break; 3932 break;
3949 default: { 3933 default: {
3950 if (ch >= 32 && ch <= 126) { 3934 if (ch >= 32 && ch <= 126) {
3951 wsResultBuf.AppendChar(ch); 3935 wsResultBuf.AppendChar(ch);
3952 } else if (ch < 256) { 3936 } else if (ch < 256) {
3953 iIndex = ch / 16; 3937 int32_t iIndex = ch / 16;
3954 strEncode[3] = strCode[iIndex]; 3938 strEncode[3] = strCode[iIndex];
3955 strEncode[4] = strCode[ch - iIndex * 16]; 3939 strEncode[4] = strCode[ch - iIndex * 16];
3956 strEncode[5] = ';'; 3940 strEncode[5] = ';';
3957 strEncode[6] = 0; 3941 strEncode[6] = 0;
3958 wsResultBuf << FX_WSTRC(strEncode); 3942 wsResultBuf << FX_WSTRC(strEncode);
3959 } else { 3943 } else {
3960 int32_t iBigByte = ch / 256; 3944 int32_t iBigByte = ch / 256;
3961 int32_t iLittleByte = ch % 256; 3945 int32_t iLittleByte = ch % 256;
3962 strEncode[3] = strCode[iBigByte / 16]; 3946 strEncode[3] = strCode[iBigByte / 16];
3963 strEncode[4] = strCode[iBigByte % 16]; 3947 strEncode[4] = strCode[iBigByte % 16];
3964 strEncode[5] = strCode[iLittleByte / 16]; 3948 strEncode[5] = strCode[iLittleByte / 16];
3965 strEncode[6] = strCode[iLittleByte % 16]; 3949 strEncode[6] = strCode[iLittleByte % 16];
3966 wsResultBuf << FX_WSTRC(strEncode); 3950 wsResultBuf << FX_WSTRC(strEncode);
3967 } 3951 }
3968 } break; 3952 break;
3953 }
3969 } 3954 }
3970 } 3955 }
3971 wsResultBuf.AppendChar(0); 3956 wsResultBuf.AppendChar(0);
3972 szResultBuf.Clear(); 3957 szResultBuf.Clear();
3958
3973 szResultBuf << FX_UTF8Encode(wsResultBuf.GetBuffer(), wsResultBuf.GetLength()) 3959 szResultBuf << FX_UTF8Encode(wsResultBuf.GetBuffer(), wsResultBuf.GetLength())
3974 .AsStringC(); 3960 .AsStringC();
3975 } 3961 }
3976 3962
3977 // static 3963 // static
3978 FX_BOOL CXFA_FM2JSContext::HTMLSTR2Code(const CFX_WideStringC& pData, 3964 FX_BOOL CXFA_FM2JSContext::HTMLSTR2Code(const CFX_WideStringC& pData,
3979 uint32_t& iCode) { 3965 uint32_t& iCode) {
3980 uint32_t uHash = FX_HashCode_GetW(pData, false); 3966 uint32_t uHash = FX_HashCode_GetW(pData, false);
3981 int32_t iStart = 0; 3967 int32_t iStart = 0;
3982 int32_t iEnd = FX_ArraySize(reservesForDecode) - 1; 3968 int32_t iEnd = FX_ArraySize(reservesForDecode) - 1;
3983 do { 3969 do {
3984 int32_t iMid = (iStart + iEnd) / 2; 3970 int32_t iMid = (iStart + iEnd) / 2;
3985 XFA_FMHtmlHashedReserveCode htmlhashedreservecode = reservesForDecode[iMid]; 3971 XFA_FMHtmlHashedReserveCode htmlhashedreservecode = reservesForDecode[iMid];
3986 if (uHash == htmlhashedreservecode.m_uHash) { 3972 if (uHash == htmlhashedreservecode.m_uHash) {
3987 iCode = htmlhashedreservecode.m_uCode; 3973 iCode = htmlhashedreservecode.m_uCode;
3988 return TRUE; 3974 return TRUE;
3989 } 3975 }
3990 if (uHash < htmlhashedreservecode.m_uHash) { 3976
3977 if (uHash < htmlhashedreservecode.m_uHash)
3991 iEnd = iMid - 1; 3978 iEnd = iMid - 1;
3992 } else { 3979 else
3993 iStart = iMid + 1; 3980 iStart = iMid + 1;
3994 }
3995 } while (iStart <= iEnd); 3981 } while (iStart <= iEnd);
3996 return FALSE; 3982 return FALSE;
3997 } 3983 }
3998 3984
3999 // static 3985 // static
4000 FX_BOOL CXFA_FM2JSContext::HTMLCode2STR(uint32_t iCode, 3986 FX_BOOL CXFA_FM2JSContext::HTMLCode2STR(uint32_t iCode,
4001 CFX_WideString& wsHTMLReserve) { 3987 CFX_WideString& wsHTMLReserve) {
4002 XFA_FMHtmlReserveCode htmlreservecode; 3988 int32_t iStart = 0;
4003 int32_t iStart = 0, 3989 int32_t iEnd = FX_ArraySize(reservesForEncode) - 1;
4004 iEnd = (sizeof(reservesForEncode) / sizeof(reservesForEncode[0])) - 1;
4005 int32_t iMid = (iStart + iEnd) / 2;
4006 do { 3990 do {
4007 iMid = (iStart + iEnd) / 2; 3991 int32_t iMid = (iStart + iEnd) / 2;
4008 htmlreservecode = reservesForEncode[iMid]; 3992 XFA_FMHtmlReserveCode htmlreservecode = reservesForEncode[iMid];
4009 if (iCode == htmlreservecode.m_uCode) { 3993 if (iCode == htmlreservecode.m_uCode) {
4010 wsHTMLReserve = htmlreservecode.m_htmlReserve; 3994 wsHTMLReserve = htmlreservecode.m_htmlReserve;
4011 return TRUE; 3995 return TRUE;
4012 } else if (iCode < htmlreservecode.m_uCode) { 3996 }
3997
3998 if (iCode < htmlreservecode.m_uCode)
4013 iEnd = iMid - 1; 3999 iEnd = iMid - 1;
4014 } else { 4000 else
4015 iStart = iMid + 1; 4001 iStart = iMid + 1;
4016 }
4017 } while (iStart <= iEnd); 4002 } while (iStart <= iEnd);
4018 return FALSE; 4003 return FALSE;
4019 } 4004 }
4020 4005
4021 // static 4006 // static
4022 void CXFA_FM2JSContext::Format(CFXJSE_Value* pThis, 4007 void CXFA_FM2JSContext::Format(CFXJSE_Value* pThis,
4023 const CFX_ByteStringC& szFuncName, 4008 const CFX_ByteStringC& szFuncName,
4024 CFXJSE_Arguments& args) { 4009 CFXJSE_Arguments& args) {
4025 CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr); 4010 CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr);
4026 if (args.GetLength() >= 2) { 4011 if (args.GetLength() < 2) {
4027 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); 4012 pContext->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Format");
4028 std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1); 4013 return;
4029 CFX_ByteString szPattern; 4014 }
4030 ValueToUTF8String(argOne.get(), szPattern); 4015
4031 CFX_ByteString szValue; 4016 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4032 ValueToUTF8String(argTwo.get(), szValue); 4017 CFX_ByteString szPattern;
4033 CXFA_Document* pDoc = pContext->GetDocument(); 4018 ValueToUTF8String(argOne.get(), szPattern);
4034 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr(); 4019
4035 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); 4020 std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1);
4036 ASSERT(pThisNode); 4021 CFX_ByteString szValue;
4037 CXFA_WidgetData widgetData(pThisNode); 4022 ValueToUTF8String(argTwo.get(), szValue);
4038 IFX_Locale* pLocale = widgetData.GetLocal(); 4023
4039 uint32_t patternType; 4024 CXFA_Document* pDoc = pContext->GetDocument();
4040 CFX_WideString wsPattern = CFX_WideString::FromUTF8(szPattern.AsStringC()); 4025 CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr();
4041 CFX_WideString wsValue = CFX_WideString::FromUTF8(szValue.AsStringC()); 4026 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
4042 if (!PatternStringType(szPattern.AsStringC(), patternType)) { 4027 ASSERT(pThisNode);
4043 switch (patternType) { 4028
4044 case XFA_VT_DATETIME: { 4029 CXFA_WidgetData widgetData(pThisNode);
4045 FX_STRSIZE iTChar = wsPattern.Find(L'T'); 4030 IFX_Locale* pLocale = widgetData.GetLocal();
4046 CFX_WideString wsDatePattern(L"date{"); 4031 uint32_t patternType;
4047 wsDatePattern += wsPattern.Left(iTChar); 4032 CFX_WideString wsPattern = CFX_WideString::FromUTF8(szPattern.AsStringC());
4048 wsDatePattern += FX_WSTRC(L"} "); 4033 CFX_WideString wsValue = CFX_WideString::FromUTF8(szValue.AsStringC());
4049 CFX_WideString wsTimePattern(L"time{"); 4034 if (!PatternStringType(szPattern.AsStringC(), patternType)) {
4050 wsTimePattern += wsPattern.Mid(iTChar + 1); 4035 switch (patternType) {
4051 wsTimePattern += FX_WSTRC(L"}"); 4036 case XFA_VT_DATETIME: {
4052 wsPattern = wsDatePattern + wsTimePattern; 4037 FX_STRSIZE iTChar = wsPattern.Find(L'T');
4053 } break; 4038 CFX_WideString wsDatePattern(L"date{");
4054 case XFA_VT_DATE: { 4039 wsDatePattern += wsPattern.Left(iTChar);
4055 wsPattern = FX_WSTRC(L"date{") + wsPattern; 4040 wsDatePattern += FX_WSTRC(L"} ");
4056 wsPattern += FX_WSTRC(L"}"); 4041
4057 } break; 4042 CFX_WideString wsTimePattern(L"time{");
4058 case XFA_VT_TIME: { 4043 wsTimePattern += wsPattern.Mid(iTChar + 1);
4059 wsPattern = FX_WSTRC(L"time{") + wsPattern; 4044 wsTimePattern += FX_WSTRC(L"}");
4060 wsPattern += FX_WSTRC(L"}"); 4045 wsPattern = wsDatePattern + wsTimePattern;
4061 } break; 4046 } break;
4062 case XFA_VT_TEXT: { 4047 case XFA_VT_DATE: {
4063 wsPattern = FX_WSTRC(L"text{") + wsPattern; 4048 wsPattern = FX_WSTRC(L"date{") + wsPattern;
4064 wsPattern += FX_WSTRC(L"}"); 4049 wsPattern += FX_WSTRC(L"}");
Tom Sepez 2016/06/08 17:24:07 nit: why not just wsPattern = FX_WSTRC(L"date{"
dsinclair 2016/06/08 19:56:25 Done.
4065 } break; 4050 } break;
4066 case XFA_VT_FLOAT: { 4051 case XFA_VT_TIME: {
4067 wsPattern = FX_WSTRC(L"num{") + wsPattern; 4052 wsPattern = FX_WSTRC(L"time{") + wsPattern;
4068 wsPattern += FX_WSTRC(L"}"); 4053 wsPattern += FX_WSTRC(L"}");
4069 } break; 4054 } break;
4070 default: { 4055 case XFA_VT_TEXT: {
4071 CFX_WideString wsTestPattern; 4056 wsPattern = FX_WSTRC(L"text{") + wsPattern;
4072 wsTestPattern = FX_WSTRC(L"num{") + wsPattern; 4057 wsPattern += FX_WSTRC(L"}");
4058 } break;
4059 case XFA_VT_FLOAT: {
4060 wsPattern = FX_WSTRC(L"num{") + wsPattern;
4061 wsPattern += FX_WSTRC(L"}");
4062 } break;
4063 default: {
4064 CFX_WideString wsTestPattern;
4065 wsTestPattern = FX_WSTRC(L"num{") + wsPattern;
4066 wsTestPattern += FX_WSTRC(L"}");
4067 CXFA_LocaleValue tempLocaleValue(XFA_VT_FLOAT, wsValue, wsTestPattern,
4068 pLocale, pMgr);
4069 if (tempLocaleValue.IsValid()) {
4070 wsPattern = wsTestPattern;
4071 patternType = XFA_VT_FLOAT;
4072 } else {
4073 wsTestPattern = FX_WSTRC(L"text{") + wsPattern;
4073 wsTestPattern += FX_WSTRC(L"}"); 4074 wsTestPattern += FX_WSTRC(L"}");
4074 CXFA_LocaleValue tempLocaleValue(XFA_VT_FLOAT, wsValue, wsTestPattern, 4075 wsPattern = wsTestPattern;
4075 pLocale, (CXFA_LocaleMgr*)pMgr); 4076 patternType = XFA_VT_TEXT;
4076 if (tempLocaleValue.IsValid()) { 4077 }
4077 wsPattern = wsTestPattern; 4078 } break;
4078 patternType = XFA_VT_FLOAT;
4079 } else {
4080 wsTestPattern = FX_WSTRC(L"text{") + wsPattern;
4081 wsTestPattern += FX_WSTRC(L"}");
4082 wsPattern = wsTestPattern;
4083 patternType = XFA_VT_TEXT;
4084 }
4085 } break;
4086 }
4087 } 4079 }
4088 CXFA_LocaleValue localeValue(patternType, wsValue, wsPattern, pLocale,
4089 (CXFA_LocaleMgr*)pMgr);
4090 CFX_WideString wsRet;
4091 if (localeValue.FormatPatterns(wsRet, wsPattern, pLocale,
4092 XFA_VALUEPICTURE_Display)) {
4093 args.GetReturnValue()->SetString(
4094 FX_UTF8Encode(wsRet.c_str(), wsRet.GetLength()).AsStringC());
4095 } else {
4096 args.GetReturnValue()->SetString("");
4097 }
4098 } else {
4099 pContext->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Format");
4100 } 4080 }
4081 CXFA_LocaleValue localeValue(patternType, wsValue, wsPattern, pLocale, pMgr);
4082 CFX_WideString wsRet;
4083 if (!localeValue.FormatPatterns(wsRet, wsPattern, pLocale,
4084 XFA_VALUEPICTURE_Display)) {
4085 args.GetReturnValue()->SetString("");
4086 return;
4087 }
4088
4089 args.GetReturnValue()->SetString(
4090 FX_UTF8Encode(wsRet.c_str(), wsRet.GetLength()).AsStringC());
4101 } 4091 }
4102 4092
4103 // static 4093 // static
4104 void CXFA_FM2JSContext::Left(CFXJSE_Value* pThis, 4094 void CXFA_FM2JSContext::Left(CFXJSE_Value* pThis,
4105 const CFX_ByteStringC& szFuncName, 4095 const CFX_ByteStringC& szFuncName,
4106 CFXJSE_Arguments& args) { 4096 CFXJSE_Arguments& args) {
4107 if (args.GetLength() == 2) { 4097 if (args.GetLength() != 2) {
4108 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4109 std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1);
4110 FX_BOOL argIsNull = FALSE;
4111 if ((ValueIsNull(pThis, argOne.get())) ||
4112 (ValueIsNull(pThis, argTwo.get()))) {
4113 argIsNull = TRUE;
4114 }
4115 if (argIsNull) {
4116 args.GetReturnValue()->SetNull();
4117 } else {
4118 CFX_ByteString sourceString;
4119 ValueToUTF8String(argOne.get(), sourceString);
4120 int32_t count = ValueToInteger(pThis, argTwo.get());
4121 if (count < 0) {
4122 count = 0;
4123 }
4124 args.GetReturnValue()->SetString(sourceString.Left(count).AsStringC());
4125 }
4126 } else {
4127 ToJSContext(pThis, nullptr) 4098 ToJSContext(pThis, nullptr)
4128 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Left"); 4099 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Left");
4100 return;
4129 } 4101 }
4102
4103 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4104 std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1);
4105 if ((ValueIsNull(pThis, argOne.get())) ||
4106 (ValueIsNull(pThis, argTwo.get()))) {
4107 args.GetReturnValue()->SetNull();
4108 return;
4109 }
4110
4111 CFX_ByteString sourceString;
4112 ValueToUTF8String(argOne.get(), sourceString);
4113 int32_t count = std::max(0, ValueToInteger(pThis, argTwo.get()));
4114 args.GetReturnValue()->SetString(sourceString.Left(count).AsStringC());
4130 } 4115 }
4131 4116
4132 // static 4117 // static
4133 void CXFA_FM2JSContext::Len(CFXJSE_Value* pThis, 4118 void CXFA_FM2JSContext::Len(CFXJSE_Value* pThis,
4134 const CFX_ByteStringC& szFuncName, 4119 const CFX_ByteStringC& szFuncName,
4135 CFXJSE_Arguments& args) { 4120 CFXJSE_Arguments& args) {
4136 if (args.GetLength() == 1) { 4121 if (args.GetLength() != 1) {
4137 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4138 if (ValueIsNull(pThis, argOne.get())) {
4139 args.GetReturnValue()->SetNull();
4140 } else {
4141 CFX_ByteString sourceString;
4142 ValueToUTF8String(argOne.get(), sourceString);
4143 args.GetReturnValue()->SetInteger(sourceString.GetLength());
4144 }
4145 } else {
4146 ToJSContext(pThis, nullptr) 4122 ToJSContext(pThis, nullptr)
4147 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Len"); 4123 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Len");
4124 return;
4148 } 4125 }
4126
4127 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4128 if (ValueIsNull(pThis, argOne.get())) {
4129 args.GetReturnValue()->SetNull();
4130 return;
4131 }
4132
4133 CFX_ByteString sourceString;
4134 ValueToUTF8String(argOne.get(), sourceString);
4135 args.GetReturnValue()->SetInteger(sourceString.GetLength());
4149 } 4136 }
4150 4137
4151 // static 4138 // static
4152 void CXFA_FM2JSContext::Lower(CFXJSE_Value* pThis, 4139 void CXFA_FM2JSContext::Lower(CFXJSE_Value* pThis,
4153 const CFX_ByteStringC& szFuncName, 4140 const CFX_ByteStringC& szFuncName,
4154 CFXJSE_Arguments& args) { 4141 CFXJSE_Arguments& args) {
4155 int32_t argc = args.GetLength(); 4142 int32_t argc = args.GetLength();
4156 if ((argc > 0) && (argc < 3)) { 4143 if (argc < 1 || argc > 2) {
4157 CFX_ByteString argString;
4158 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4159 if (ValueIsNull(pThis, argOne.get())) {
4160 args.GetReturnValue()->SetNull();
4161 } else {
4162 ValueToUTF8String(argOne.get(), argString);
4163 CFX_WideTextBuf lowStringBuf;
4164 CFX_WideString wsArgString =
4165 CFX_WideString::FromUTF8(argString.AsStringC());
4166 const FX_WCHAR* pData = wsArgString.c_str();
4167 int32_t iLen = argString.GetLength();
4168 int32_t i = 0;
4169 int32_t ch = 0;
4170 while (i < iLen) {
4171 ch = pData[i];
4172 if (ch >= 0x41 && ch <= 0x5A) {
4173 ch += 32;
4174 } else if (ch >= 0xC0 && ch <= 0xDE) {
4175 ch += 32;
4176 } else if (ch == 0x100 || ch == 0x102 || ch == 0x104) {
4177 ch += 1;
4178 }
4179 lowStringBuf.AppendChar(ch);
4180 ++i;
4181 }
4182 lowStringBuf.AppendChar(0);
4183 args.GetReturnValue()->SetString(
4184 FX_UTF8Encode(lowStringBuf.GetBuffer(), lowStringBuf.GetLength())
4185 .AsStringC());
4186 }
4187 } else {
4188 ToJSContext(pThis, nullptr) 4144 ToJSContext(pThis, nullptr)
4189 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Lower"); 4145 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Lower");
4146 return;
4190 } 4147 }
4148
4149 CFX_ByteString argString;
4150 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4151 if (ValueIsNull(pThis, argOne.get())) {
4152 args.GetReturnValue()->SetNull();
4153 return;
4154 }
4155
4156 ValueToUTF8String(argOne.get(), argString);
4157 CFX_WideTextBuf lowStringBuf;
4158 CFX_WideString wsArgString = CFX_WideString::FromUTF8(argString.AsStringC());
4159 const FX_WCHAR* pData = wsArgString.c_str();
4160 int32_t i = 0;
4161 while (i < argString.GetLength()) {
4162 int32_t ch = pData[i];
4163 if ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0xC0 && ch <= 0xDE))
4164 ch += 32;
4165 else if (ch == 0x100 || ch == 0x102 || ch == 0x104)
4166 ch += 1;
4167
4168 lowStringBuf.AppendChar(ch);
4169 ++i;
4170 }
4171 lowStringBuf.AppendChar(0);
4172
4173 args.GetReturnValue()->SetString(
4174 FX_UTF8Encode(lowStringBuf.GetBuffer(), lowStringBuf.GetLength())
4175 .AsStringC());
4191 } 4176 }
4192 4177
4193 // static 4178 // static
4194 void CXFA_FM2JSContext::Ltrim(CFXJSE_Value* pThis, 4179 void CXFA_FM2JSContext::Ltrim(CFXJSE_Value* pThis,
4195 const CFX_ByteStringC& szFuncName, 4180 const CFX_ByteStringC& szFuncName,
4196 CFXJSE_Arguments& args) { 4181 CFXJSE_Arguments& args) {
4197 if (args.GetLength() == 1) { 4182 if (args.GetLength() != 1) {
4198 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4199 if (ValueIsNull(pThis, argOne.get())) {
4200 args.GetReturnValue()->SetNull();
4201 } else {
4202 CFX_ByteString sourceString;
4203 ValueToUTF8String(argOne.get(), sourceString);
4204 sourceString.TrimLeft();
4205 args.GetReturnValue()->SetString(sourceString.AsStringC());
4206 }
4207 } else {
4208 ToJSContext(pThis, nullptr) 4183 ToJSContext(pThis, nullptr)
4209 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Ltrim"); 4184 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Ltrim");
4185 return;
4210 } 4186 }
4187
4188 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4189 if (ValueIsNull(pThis, argOne.get())) {
4190 args.GetReturnValue()->SetNull();
4191 return;
4192 }
4193
4194 CFX_ByteString sourceString;
4195 ValueToUTF8String(argOne.get(), sourceString);
4196 sourceString.TrimLeft();
4197 args.GetReturnValue()->SetString(sourceString.AsStringC());
4211 } 4198 }
4212 4199
4213 // static 4200 // static
4214 void CXFA_FM2JSContext::Parse(CFXJSE_Value* pThis, 4201 void CXFA_FM2JSContext::Parse(CFXJSE_Value* pThis,
4215 const CFX_ByteStringC& szFuncName, 4202 const CFX_ByteStringC& szFuncName,
4216 CFXJSE_Arguments& args) { 4203 CFXJSE_Arguments& args) {
4217 CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr); 4204 CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr);
4218 if (args.GetLength() == 2) { 4205 if (args.GetLength() != 2) {
4219 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4220 std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1);
4221 if (ValueIsNull(pThis, argTwo.get())) {
4222 args.GetReturnValue()->SetNull();
4223 } else {
4224 CFX_ByteString szPattern;
4225 ValueToUTF8String(argOne.get(), szPattern);
4226 CFX_ByteString szValue;
4227 ValueToUTF8String(argTwo.get(), szValue);
4228 CXFA_Document* pDoc = pContext->GetDocument();
4229 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr();
4230 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
4231 ASSERT(pThisNode);
4232 CXFA_WidgetData widgetData(pThisNode);
4233 IFX_Locale* pLocale = widgetData.GetLocal();
4234 uint32_t patternType;
4235 CFX_WideString wsPattern =
4236 CFX_WideString::FromUTF8(szPattern.AsStringC());
4237 CFX_WideString wsValue = CFX_WideString::FromUTF8(szValue.AsStringC());
4238 CFX_ByteString szParsedValue;
4239 if (PatternStringType(szPattern.AsStringC(), patternType)) {
4240 CXFA_LocaleValue localeValue(patternType, wsValue, wsPattern, pLocale,
4241 (CXFA_LocaleMgr*)pMgr);
4242 if (localeValue.IsValid()) {
4243 szParsedValue = FX_UTF8Encode(localeValue.GetValue());
4244 args.GetReturnValue()->SetString(szParsedValue.AsStringC());
4245 } else {
4246 args.GetReturnValue()->SetString("");
4247 }
4248 } else {
4249 switch (patternType) {
4250 case XFA_VT_DATETIME: {
4251 FX_STRSIZE iTChar = wsPattern.Find(L'T');
4252 CFX_WideString wsDatePattern(L"date{");
4253 wsDatePattern += wsPattern.Left(iTChar);
4254 wsDatePattern += FX_WSTRC(L"} ");
4255 CFX_WideString wsTimePattern(L"time{");
4256 wsTimePattern += wsPattern.Mid(iTChar + 1);
4257 wsTimePattern += FX_WSTRC(L"}");
4258 wsPattern = wsDatePattern + wsTimePattern;
4259 CXFA_LocaleValue localeValue(patternType, wsValue, wsPattern,
4260 pLocale, (CXFA_LocaleMgr*)pMgr);
4261 if (localeValue.IsValid()) {
4262 szParsedValue = FX_UTF8Encode(localeValue.GetValue());
4263 args.GetReturnValue()->SetString(szParsedValue.AsStringC());
4264 } else {
4265 args.GetReturnValue()->SetString("");
4266 }
4267 } break;
4268 case XFA_VT_DATE: {
4269 wsPattern = FX_WSTRC(L"date{") + wsPattern;
4270 wsPattern += FX_WSTRC(L"}");
4271 CXFA_LocaleValue localeValue(patternType, wsValue, wsPattern,
4272 pLocale, (CXFA_LocaleMgr*)pMgr);
4273 if (localeValue.IsValid()) {
4274 szParsedValue = FX_UTF8Encode(localeValue.GetValue());
4275 args.GetReturnValue()->SetString(szParsedValue.AsStringC());
4276 } else {
4277 args.GetReturnValue()->SetString("");
4278 }
4279 } break;
4280 case XFA_VT_TIME: {
4281 wsPattern = FX_WSTRC(L"time{") + wsPattern;
4282 wsPattern += FX_WSTRC(L"}");
4283 CXFA_LocaleValue localeValue(patternType, wsValue, wsPattern,
4284 pLocale, (CXFA_LocaleMgr*)pMgr);
4285 if (localeValue.IsValid()) {
4286 szParsedValue = FX_UTF8Encode(localeValue.GetValue());
4287 args.GetReturnValue()->SetString(szParsedValue.AsStringC());
4288 } else {
4289 args.GetReturnValue()->SetString("");
4290 }
4291 } break;
4292 case XFA_VT_TEXT: {
4293 wsPattern = FX_WSTRC(L"text{") + wsPattern;
4294 wsPattern += FX_WSTRC(L"}");
4295 CXFA_LocaleValue localeValue(XFA_VT_TEXT, wsValue, wsPattern,
4296 pLocale, (CXFA_LocaleMgr*)pMgr);
4297 if (localeValue.IsValid()) {
4298 szParsedValue = FX_UTF8Encode(localeValue.GetValue());
4299 args.GetReturnValue()->SetString(szParsedValue.AsStringC());
4300 } else {
4301 args.GetReturnValue()->SetString("");
4302 }
4303 } break;
4304 case XFA_VT_FLOAT: {
4305 wsPattern = FX_WSTRC(L"num{") + wsPattern;
4306 wsPattern += FX_WSTRC(L"}");
4307 CXFA_LocaleValue localeValue(XFA_VT_FLOAT, wsValue, wsPattern,
4308 pLocale, (CXFA_LocaleMgr*)pMgr);
4309 if (localeValue.IsValid()) {
4310 args.GetReturnValue()->SetDouble(localeValue.GetDoubleNum());
4311 } else {
4312 args.GetReturnValue()->SetString("");
4313 }
4314 } break;
4315 default: {
4316 CFX_WideString wsTestPattern;
4317 wsTestPattern = FX_WSTRC(L"num{") + wsPattern;
4318 wsTestPattern += FX_WSTRC(L"}");
4319 CXFA_LocaleValue localeValue(XFA_VT_FLOAT, wsValue, wsTestPattern,
4320 pLocale, (CXFA_LocaleMgr*)pMgr);
4321 if (localeValue.IsValid()) {
4322 args.GetReturnValue()->SetDouble(localeValue.GetDoubleNum());
4323 } else {
4324 wsTestPattern = FX_WSTRC(L"text{") + wsPattern;
4325 wsTestPattern += FX_WSTRC(L"}");
4326 CXFA_LocaleValue localeValue2(XFA_VT_TEXT, wsValue, wsTestPattern,
4327 pLocale, (CXFA_LocaleMgr*)pMgr);
4328 if (localeValue2.IsValid()) {
4329 szParsedValue = FX_UTF8Encode(localeValue2.GetValue());
4330 args.GetReturnValue()->SetString(szParsedValue.AsStringC());
4331 } else {
4332 args.GetReturnValue()->SetString("");
4333 }
4334 }
4335 } break;
4336 }
4337 }
4338 }
4339 } else {
4340 pContext->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Parse"); 4206 pContext->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Parse");
4207 return;
4208 }
4209
4210 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4211 std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1);
4212 if (ValueIsNull(pThis, argTwo.get())) {
4213 args.GetReturnValue()->SetNull();
4214 return;
4215 }
4216
4217 CFX_ByteString szPattern;
4218 ValueToUTF8String(argOne.get(), szPattern);
4219 CFX_ByteString szValue;
4220 ValueToUTF8String(argTwo.get(), szValue);
4221
4222 CXFA_Document* pDoc = pContext->GetDocument();
4223 CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr();
4224 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
4225 ASSERT(pThisNode);
4226
4227 CXFA_WidgetData widgetData(pThisNode);
4228 IFX_Locale* pLocale = widgetData.GetLocal();
4229 CFX_WideString wsPattern = CFX_WideString::FromUTF8(szPattern.AsStringC());
4230 CFX_WideString wsValue = CFX_WideString::FromUTF8(szValue.AsStringC());
4231 uint32_t patternType;
4232 if (PatternStringType(szPattern.AsStringC(), patternType)) {
4233 CXFA_LocaleValue localeValue(patternType, wsValue, wsPattern, pLocale,
4234 pMgr);
4235 if (!localeValue.IsValid()) {
4236 args.GetReturnValue()->SetString("");
4237 return;
4238 }
4239 args.GetReturnValue()->SetString(
4240 FX_UTF8Encode(localeValue.GetValue()).AsStringC());
4241 return;
4242 }
4243
4244 switch (patternType) {
4245 case XFA_VT_DATETIME: {
4246 FX_STRSIZE iTChar = wsPattern.Find(L'T');
4247 CFX_WideString wsDatePattern(L"date{");
4248 wsDatePattern += wsPattern.Left(iTChar);
4249 wsDatePattern += FX_WSTRC(L"} ");
4250 CFX_WideString wsTimePattern(L"time{");
4251 wsTimePattern += wsPattern.Mid(iTChar + 1);
4252 wsTimePattern += FX_WSTRC(L"}");
4253 wsPattern = wsDatePattern + wsTimePattern;
4254 CXFA_LocaleValue localeValue(patternType, wsValue, wsPattern, pLocale,
4255 pMgr);
4256 if (!localeValue.IsValid()) {
4257 args.GetReturnValue()->SetString("");
4258 return;
4259 }
4260 args.GetReturnValue()->SetString(
4261 FX_UTF8Encode(localeValue.GetValue()).AsStringC());
4262 return;
4263 }
4264 case XFA_VT_DATE: {
4265 wsPattern = FX_WSTRC(L"date{") + wsPattern;
4266 wsPattern += FX_WSTRC(L"}");
4267 CXFA_LocaleValue localeValue(patternType, wsValue, wsPattern, pLocale,
4268 pMgr);
4269 if (!localeValue.IsValid()) {
4270 args.GetReturnValue()->SetString("");
4271 return;
4272 }
4273 args.GetReturnValue()->SetString(
4274 FX_UTF8Encode(localeValue.GetValue()).AsStringC());
4275 return;
4276 }
4277 case XFA_VT_TIME: {
4278 wsPattern = FX_WSTRC(L"time{") + wsPattern;
4279 wsPattern += FX_WSTRC(L"}");
4280 CXFA_LocaleValue localeValue(patternType, wsValue, wsPattern, pLocale,
4281 pMgr);
4282 if (!localeValue.IsValid()) {
4283 args.GetReturnValue()->SetString("");
4284 return;
4285 }
4286 args.GetReturnValue()->SetString(
4287 FX_UTF8Encode(localeValue.GetValue()).AsStringC());
4288 return;
4289 }
4290 case XFA_VT_TEXT: {
4291 wsPattern = FX_WSTRC(L"text{") + wsPattern;
4292 wsPattern += FX_WSTRC(L"}");
4293 CXFA_LocaleValue localeValue(XFA_VT_TEXT, wsValue, wsPattern, pLocale,
4294 pMgr);
4295 if (!localeValue.IsValid()) {
4296 args.GetReturnValue()->SetString("");
4297 return;
4298 }
4299 args.GetReturnValue()->SetString(
4300 FX_UTF8Encode(localeValue.GetValue()).AsStringC());
4301 return;
4302 }
4303 case XFA_VT_FLOAT: {
4304 wsPattern = FX_WSTRC(L"num{") + wsPattern;
4305 wsPattern += FX_WSTRC(L"}");
4306 CXFA_LocaleValue localeValue(XFA_VT_FLOAT, wsValue, wsPattern, pLocale,
4307 pMgr);
4308 if (!localeValue.IsValid()) {
4309 args.GetReturnValue()->SetString("");
4310 return;
4311 }
4312 args.GetReturnValue()->SetDouble(localeValue.GetDoubleNum());
4313 return;
4314 }
4315 default: {
4316 CFX_WideString wsTestPattern;
4317 wsTestPattern = FX_WSTRC(L"num{") + wsPattern;
4318 wsTestPattern += FX_WSTRC(L"}");
4319 CXFA_LocaleValue localeValue(XFA_VT_FLOAT, wsValue, wsTestPattern,
4320 pLocale, pMgr);
4321 if (localeValue.IsValid()) {
4322 args.GetReturnValue()->SetDouble(localeValue.GetDoubleNum());
4323 return;
4324 }
4325
4326 wsTestPattern = FX_WSTRC(L"text{") + wsPattern;
4327 wsTestPattern += FX_WSTRC(L"}");
4328 CXFA_LocaleValue localeValue2(XFA_VT_TEXT, wsValue, wsTestPattern,
4329 pLocale, pMgr);
4330 if (!localeValue2.IsValid()) {
4331 args.GetReturnValue()->SetString("");
4332 return;
4333 }
4334 args.GetReturnValue()->SetString(
4335 FX_UTF8Encode(localeValue2.GetValue()).AsStringC());
4336 return;
4337 }
4341 } 4338 }
4342 } 4339 }
4343 4340
4344 // static 4341 // static
4345 void CXFA_FM2JSContext::Replace(CFXJSE_Value* pThis, 4342 void CXFA_FM2JSContext::Replace(CFXJSE_Value* pThis,
4346 const CFX_ByteStringC& szFuncName, 4343 const CFX_ByteStringC& szFuncName,
4347 CFXJSE_Arguments& args) { 4344 CFXJSE_Arguments& args) {
4348 int32_t argc = args.GetLength(); 4345 int32_t argc = args.GetLength();
4349 if ((argc == 2) || (argc == 3)) { 4346 if (argc < 2 || argc > 3) {
4350 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4351 std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1);
4352 CFX_ByteString oneString;
4353 CFX_ByteString twoString;
4354 CFX_ByteString threeString;
4355 if (!ValueIsNull(pThis, argOne.get()) &&
4356 !ValueIsNull(pThis, argTwo.get())) {
4357 ValueToUTF8String(argOne.get(), oneString);
4358 ValueToUTF8String(argTwo.get(), twoString);
4359 }
4360 if (argc > 2) {
4361 std::unique_ptr<CFXJSE_Value> argThree = GetSimpleValue(pThis, args, 2);
4362 ValueToUTF8String(argThree.get(), threeString);
4363 }
4364 int32_t iSrcLen = oneString.GetLength();
4365 int32_t iFindLen = twoString.GetLength();
4366 CFX_ByteTextBuf resultString;
4367 int32_t iFindIndex = 0;
4368 uint8_t ch = 0;
4369 for (int32_t u = 0; u < iSrcLen; ++u) {
4370 ch = oneString.GetAt(u);
4371 if (ch == twoString.GetAt(iFindIndex)) {
4372 int32_t iTemp = u + 1;
4373 ++iFindIndex;
4374 uint8_t chTemp = 0;
4375 while (iFindIndex < iFindLen) {
4376 chTemp = oneString.GetAt(iTemp);
4377 if (chTemp == twoString.GetAt(iFindIndex)) {
4378 ++iTemp;
4379 ++iFindIndex;
4380 } else {
4381 iFindIndex = 0;
4382 break;
4383 }
4384 }
4385 if (iFindIndex == iFindLen) {
4386 resultString << threeString.AsStringC();
4387 u += iFindLen - 1;
4388 iFindIndex = 0;
4389 } else {
4390 resultString.AppendChar(ch);
4391 }
4392 } else {
4393 resultString.AppendChar(ch);
4394 }
4395 }
4396 resultString.AppendChar(0);
4397 args.GetReturnValue()->SetString(resultString.AsStringC());
4398 } else {
4399 ToJSContext(pThis, nullptr) 4347 ToJSContext(pThis, nullptr)
4400 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Replace"); 4348 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Replace");
4401 } 4349 return;
4350 }
4351
4352 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4353 std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1);
4354 CFX_ByteString oneString;
4355 CFX_ByteString twoString;
4356 if (!ValueIsNull(pThis, argOne.get()) && !ValueIsNull(pThis, argTwo.get())) {
4357 ValueToUTF8String(argOne.get(), oneString);
4358 ValueToUTF8String(argTwo.get(), twoString);
4359 }
4360
4361 CFX_ByteString threeString;
4362 if (argc > 2) {
4363 std::unique_ptr<CFXJSE_Value> argThree = GetSimpleValue(pThis, args, 2);
4364 ValueToUTF8String(argThree.get(), threeString);
4365 }
4366
4367 int32_t iFindLen = twoString.GetLength();
4368 CFX_ByteTextBuf resultString;
4369 int32_t iFindIndex = 0;
4370 for (int32_t u = 0; u < oneString.GetLength(); ++u) {
4371 uint8_t ch = oneString.GetAt(u);
4372 if (ch != twoString.GetAt(iFindIndex)) {
4373 resultString.AppendChar(ch);
4374 continue;
4375 }
4376
4377 int32_t iTemp = u + 1;
4378 ++iFindIndex;
4379 while (iFindIndex < iFindLen) {
4380 uint8_t chTemp = oneString.GetAt(iTemp);
4381 if (chTemp != twoString.GetAt(iFindIndex)) {
4382 iFindIndex = 0;
4383 break;
4384 }
4385
4386 ++iTemp;
4387 ++iFindIndex;
4388 }
4389 if (iFindIndex == iFindLen) {
4390 resultString << threeString.AsStringC();
4391 u += iFindLen - 1;
4392 iFindIndex = 0;
4393 } else {
4394 resultString.AppendChar(ch);
4395 }
4396 }
4397 resultString.AppendChar(0);
4398 args.GetReturnValue()->SetString(resultString.AsStringC());
4402 } 4399 }
4403 4400
4404 // static 4401 // static
4405 void CXFA_FM2JSContext::Right(CFXJSE_Value* pThis, 4402 void CXFA_FM2JSContext::Right(CFXJSE_Value* pThis,
4406 const CFX_ByteStringC& szFuncName, 4403 const CFX_ByteStringC& szFuncName,
4407 CFXJSE_Arguments& args) { 4404 CFXJSE_Arguments& args) {
4408 if (args.GetLength() == 2) { 4405 if (args.GetLength() != 2) {
4409 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4410 std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1);
4411 FX_BOOL argIsNull = FALSE;
4412 if ((ValueIsNull(pThis, argOne.get())) ||
4413 (ValueIsNull(pThis, argTwo.get()))) {
4414 argIsNull = TRUE;
4415 }
4416 if (argIsNull) {
4417 args.GetReturnValue()->SetNull();
4418 } else {
4419 CFX_ByteString sourceString;
4420 ValueToUTF8String(argOne.get(), sourceString);
4421 int32_t count = ValueToInteger(pThis, argTwo.get());
4422 if (count < 0) {
4423 count = 0;
4424 }
4425 args.GetReturnValue()->SetString(sourceString.Right(count).AsStringC());
4426 }
4427 } else {
4428 ToJSContext(pThis, nullptr) 4406 ToJSContext(pThis, nullptr)
4429 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Right"); 4407 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Right");
4430 } 4408 return;
4409 }
4410
4411 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4412 std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1);
4413 if ((ValueIsNull(pThis, argOne.get())) ||
4414 (ValueIsNull(pThis, argTwo.get()))) {
4415 args.GetReturnValue()->SetNull();
4416 return;
4417 }
4418
4419 CFX_ByteString sourceString;
4420 ValueToUTF8String(argOne.get(), sourceString);
4421 int32_t count = std::max(0, ValueToInteger(pThis, argTwo.get()));
4422 args.GetReturnValue()->SetString(sourceString.Right(count).AsStringC());
4431 } 4423 }
4432 4424
4433 // static 4425 // static
4434 void CXFA_FM2JSContext::Rtrim(CFXJSE_Value* pThis, 4426 void CXFA_FM2JSContext::Rtrim(CFXJSE_Value* pThis,
4435 const CFX_ByteStringC& szFuncName, 4427 const CFX_ByteStringC& szFuncName,
4436 CFXJSE_Arguments& args) { 4428 CFXJSE_Arguments& args) {
4437 if (args.GetLength() == 1) { 4429 if (args.GetLength() != 1) {
4438 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4439 if (ValueIsNull(pThis, argOne.get())) {
4440 args.GetReturnValue()->SetNull();
4441 } else {
4442 CFX_ByteString sourceString;
4443 ValueToUTF8String(argOne.get(), sourceString);
4444 sourceString.TrimRight();
4445 args.GetReturnValue()->SetString(sourceString.AsStringC());
4446 }
4447 } else {
4448 ToJSContext(pThis, nullptr) 4430 ToJSContext(pThis, nullptr)
4449 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Rtrim"); 4431 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Rtrim");
4450 } 4432 return;
4433 }
4434
4435 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4436 if (ValueIsNull(pThis, argOne.get())) {
4437 args.GetReturnValue()->SetNull();
4438 return;
4439 }
4440
4441 CFX_ByteString sourceString;
4442 ValueToUTF8String(argOne.get(), sourceString);
4443 sourceString.TrimRight();
4444 args.GetReturnValue()->SetString(sourceString.AsStringC());
4451 } 4445 }
4452 4446
4453 // static 4447 // static
4454 void CXFA_FM2JSContext::Space(CFXJSE_Value* pThis, 4448 void CXFA_FM2JSContext::Space(CFXJSE_Value* pThis,
4455 const CFX_ByteStringC& szFuncName, 4449 const CFX_ByteStringC& szFuncName,
4456 CFXJSE_Arguments& args) { 4450 CFXJSE_Arguments& args) {
4457 if (args.GetLength() == 1) { 4451 if (args.GetLength() != 1) {
4458 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4459 if (CFXJSE_Value::IsNull(argOne.get())) {
4460 args.GetReturnValue()->SetNull();
4461 } else {
4462 int32_t count = 0;
4463 count = ValueToInteger(pThis, argOne.get());
4464 count = (count < 0) ? 0 : count;
4465 CFX_ByteTextBuf spaceString;
4466 int32_t index = 0;
4467 while (index < count) {
4468 spaceString.AppendByte(' ');
4469 index++;
4470 }
4471 spaceString.AppendByte(0);
4472 args.GetReturnValue()->SetString(spaceString.AsStringC());
4473 }
4474 } else {
4475 ToJSContext(pThis, nullptr) 4452 ToJSContext(pThis, nullptr)
4476 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Space"); 4453 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Space");
4477 } 4454 return;
4478 } 4455 }
4479 4456
4480 // static 4457 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4458 if (CFXJSE_Value::IsNull(argOne.get())) {
4459 args.GetReturnValue()->SetNull();
4460 return;
4461 }
4462
4463 int32_t count = std::max(0, ValueToInteger(pThis, argOne.get()));
4464 CFX_ByteTextBuf spaceString;
4465 int32_t index = 0;
4466 while (index < count) {
4467 spaceString.AppendByte(' ');
4468 index++;
4469 }
4470 spaceString.AppendByte(0);
4471 args.GetReturnValue()->SetString(spaceString.AsStringC());
4472 }
4473
4474 // static
4481 void CXFA_FM2JSContext::Str(CFXJSE_Value* pThis, 4475 void CXFA_FM2JSContext::Str(CFXJSE_Value* pThis,
4482 const CFX_ByteStringC& szFuncName, 4476 const CFX_ByteStringC& szFuncName,
4483 CFXJSE_Arguments& args) { 4477 CFXJSE_Arguments& args) {
4484 int32_t argc = args.GetLength(); 4478 int32_t argc = args.GetLength();
4485 if ((argc > 0) && (argc < 4)) { 4479 if (argc < 1 || argc > 3) {
4486 FX_BOOL bFlags = FALSE;
4487 FX_FLOAT fNumber = 0.0f;
4488 int32_t iWidth = 10;
4489 int32_t iPrecision = 0;
4490 std::unique_ptr<CFXJSE_Value> numberValue = GetSimpleValue(pThis, args, 0);
4491 if (CFXJSE_Value::IsNull(numberValue.get())) {
4492 bFlags = TRUE;
4493 } else {
4494 fNumber = ValueToFloat(pThis, numberValue.get());
4495 }
4496 if (argc > 1) {
4497 std::unique_ptr<CFXJSE_Value> widthValue = GetSimpleValue(pThis, args, 1);
4498 iWidth = (int32_t)ValueToFloat(pThis, widthValue.get());
4499 }
4500 if (argc > 2) {
4501 std::unique_ptr<CFXJSE_Value> precisionValue =
4502 GetSimpleValue(pThis, args, 2);
4503 iPrecision = (int32_t)ValueToFloat(pThis, precisionValue.get());
4504 if (iPrecision < 0) {
4505 iPrecision = 0;
4506 }
4507 }
4508 if (!bFlags) {
4509 CFX_ByteString numberString;
4510 CFX_ByteString formatStr = "%";
4511 if (iPrecision) {
4512 formatStr += ".";
4513 formatStr += CFX_ByteString::FormatInteger(iPrecision);
4514 }
4515 formatStr += "f";
4516 numberString.Format(formatStr.c_str(), fNumber);
4517 const FX_CHAR* pData = numberString.c_str();
4518 int32_t iLength = numberString.GetLength();
4519 int32_t u = 0;
4520 while (u < iLength) {
4521 if (pData[u] == '.') {
4522 break;
4523 }
4524 ++u;
4525 }
4526 CFX_ByteTextBuf resultBuf;
4527 if (u > iWidth || (iPrecision + u) >= iWidth) {
4528 int32_t i = 0;
4529 while (i < iWidth) {
4530 resultBuf.AppendChar('*');
4531 ++i;
4532 }
4533 resultBuf.AppendChar(0);
4534 } else {
4535 if (u == iLength) {
4536 if (iLength > iWidth) {
4537 int32_t i = 0;
4538 while (i < iWidth) {
4539 resultBuf.AppendChar('*');
4540 ++i;
4541 }
4542 } else {
4543 int32_t i = 0;
4544 int32_t iSpace = iWidth - iLength;
4545 while (i < iSpace) {
4546 resultBuf.AppendChar(' ');
4547 ++i;
4548 }
4549 resultBuf << pData;
4550 }
4551 } else {
4552 int32_t iLeavingSpace = 0;
4553 if (iPrecision == 0) {
4554 iLeavingSpace = iWidth - (u + iPrecision);
4555 } else {
4556 iLeavingSpace = iWidth - (u + iPrecision + 1);
4557 }
4558 int32_t i = 0;
4559 while (i < iLeavingSpace) {
4560 resultBuf.AppendChar(' ');
4561 ++i;
4562 }
4563 i = 0;
4564 while (i < u) {
4565 resultBuf.AppendChar(pData[i]);
4566 ++i;
4567 }
4568 if (iPrecision != 0) {
4569 resultBuf.AppendChar('.');
4570 }
4571 u++;
4572 i = 0;
4573 while (u < iLength) {
4574 if (i >= iPrecision) {
4575 break;
4576 }
4577 resultBuf.AppendChar(pData[u]);
4578 ++i;
4579 ++u;
4580 }
4581 while (i < iPrecision) {
4582 resultBuf.AppendChar('0');
4583 ++i;
4584 }
4585 resultBuf.AppendChar(0);
4586 }
4587 }
4588 args.GetReturnValue()->SetString(resultBuf.AsStringC());
4589 } else {
4590 args.GetReturnValue()->SetNull();
4591 }
4592 } else {
4593 ToJSContext(pThis, nullptr) 4480 ToJSContext(pThis, nullptr)
4594 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Str"); 4481 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Str");
4482 return;
4595 } 4483 }
4484
4485 std::unique_ptr<CFXJSE_Value> numberValue = GetSimpleValue(pThis, args, 0);
4486 if (CFXJSE_Value::IsNull(numberValue.get())) {
4487 args.GetReturnValue()->SetNull();
4488 return;
4489 }
4490 FX_FLOAT fNumber = ValueToFloat(pThis, numberValue.get());
4491
4492 int32_t iWidth = 10;
4493 if (argc > 1) {
4494 std::unique_ptr<CFXJSE_Value> widthValue = GetSimpleValue(pThis, args, 1);
4495 iWidth = static_cast<int32_t>(ValueToFloat(pThis, widthValue.get()));
4496 }
4497
4498 int32_t iPrecision = 0;
4499 if (argc > 2) {
4500 std::unique_ptr<CFXJSE_Value> precisionValue =
4501 GetSimpleValue(pThis, args, 2);
4502 iPrecision = std::max(
4503 0, static_cast<int32_t>(ValueToFloat(pThis, precisionValue.get())));
4504 }
4505
4506 CFX_ByteString numberString;
4507 CFX_ByteString formatStr = "%";
4508 if (iPrecision) {
4509 formatStr += ".";
4510 formatStr += CFX_ByteString::FormatInteger(iPrecision);
4511 }
4512 formatStr += "f";
4513 numberString.Format(formatStr.c_str(), fNumber);
4514
4515 const FX_CHAR* pData = numberString.c_str();
4516 int32_t iLength = numberString.GetLength();
4517 int32_t u = 0;
4518 while (u < iLength) {
4519 if (pData[u] == '.')
4520 break;
4521
4522 ++u;
4523 }
4524
4525 CFX_ByteTextBuf resultBuf;
4526 if (u > iWidth || (iPrecision + u) >= iWidth) {
4527 int32_t i = 0;
4528 while (i < iWidth) {
4529 resultBuf.AppendChar('*');
4530 ++i;
4531 }
4532 resultBuf.AppendChar(0);
4533 args.GetReturnValue()->SetString(resultBuf.AsStringC());
4534 return;
4535 }
4536
4537 if (u == iLength) {
4538 if (iLength > iWidth) {
4539 int32_t i = 0;
4540 while (i < iWidth) {
4541 resultBuf.AppendChar('*');
4542 ++i;
4543 }
4544 } else {
4545 int32_t i = 0;
4546 while (i < iWidth - iLength) {
4547 resultBuf.AppendChar(' ');
4548 ++i;
4549 }
4550 resultBuf << pData;
4551 }
4552 args.GetReturnValue()->SetString(resultBuf.AsStringC());
4553 return;
4554 }
4555
4556 int32_t iLeavingSpace = iWidth - u - iPrecision;
4557 if (iPrecision != 0)
4558 iLeavingSpace--;
4559
4560 int32_t i = 0;
4561 while (i < iLeavingSpace) {
4562 resultBuf.AppendChar(' ');
4563 ++i;
4564 }
4565 i = 0;
4566 while (i < u) {
4567 resultBuf.AppendChar(pData[i]);
4568 ++i;
4569 }
4570 if (iPrecision != 0)
4571 resultBuf.AppendChar('.');
4572
4573 u++;
4574 i = 0;
4575 while (u < iLength) {
4576 if (i >= iPrecision)
4577 break;
4578
4579 resultBuf.AppendChar(pData[u]);
4580 ++i;
4581 ++u;
4582 }
4583 while (i < iPrecision) {
4584 resultBuf.AppendChar('0');
4585 ++i;
4586 }
4587 resultBuf.AppendChar(0);
4588 args.GetReturnValue()->SetString(resultBuf.AsStringC());
4596 } 4589 }
4597 4590
4598 // static 4591 // static
4599 void CXFA_FM2JSContext::Stuff(CFXJSE_Value* pThis, 4592 void CXFA_FM2JSContext::Stuff(CFXJSE_Value* pThis,
4600 const CFX_ByteStringC& szFuncName, 4593 const CFX_ByteStringC& szFuncName,
4601 CFXJSE_Arguments& args) { 4594 CFXJSE_Arguments& args) {
4602 int32_t argc = args.GetLength(); 4595 int32_t argc = args.GetLength();
4603 if ((argc == 3) || (argc == 4)) { 4596 if (argc < 3 || argc > 4) {
4604 CFX_ByteString sourceString;
4605 CFX_ByteString insertString;
4606 int32_t iLength = 0;
4607 int32_t iStart = 0;
4608 int32_t iDelete = 0;
4609 std::unique_ptr<CFXJSE_Value> sourceValue = GetSimpleValue(pThis, args, 0);
4610 std::unique_ptr<CFXJSE_Value> startValue = GetSimpleValue(pThis, args, 1);
4611 std::unique_ptr<CFXJSE_Value> deleteValue = GetSimpleValue(pThis, args, 2);
4612 if (!CFXJSE_Value::IsNull(sourceValue.get()) &&
4613 !CFXJSE_Value::IsNull(startValue.get()) &&
4614 !CFXJSE_Value::IsNull(deleteValue.get())) {
4615 ValueToUTF8String(sourceValue.get(), sourceString);
4616 iLength = sourceString.GetLength();
4617 iStart = (int32_t)ValueToFloat(pThis, startValue.get());
4618 if (iStart < 1) {
4619 iStart = 1;
4620 }
4621 if (iStart > iLength) {
4622 iStart = iLength;
4623 }
4624 iDelete = (int32_t)ValueToFloat(pThis, deleteValue.get());
4625 if (iDelete <= 0) {
4626 iDelete = 0;
4627 }
4628 }
4629 if (argc > 3) {
4630 std::unique_ptr<CFXJSE_Value> insertValue =
4631 GetSimpleValue(pThis, args, 3);
4632 ValueToUTF8String(insertValue.get(), insertString);
4633 }
4634 iStart -= 1;
4635 CFX_ByteTextBuf resultString;
4636 int32_t i = 0;
4637 while (i < iStart) {
4638 resultString.AppendChar(sourceString.GetAt(i));
4639 ++i;
4640 }
4641 resultString << insertString.AsStringC();
4642 i = iStart + iDelete;
4643 while (i < iLength) {
4644 resultString.AppendChar(sourceString.GetAt(i));
4645 ++i;
4646 }
4647 resultString.AppendChar(0);
4648 args.GetReturnValue()->SetString(resultString.AsStringC());
4649 } else {
4650 ToJSContext(pThis, nullptr) 4597 ToJSContext(pThis, nullptr)
4651 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Stuff"); 4598 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Stuff");
4599 return;
4652 } 4600 }
4601
4602 CFX_ByteString sourceString;
4603 CFX_ByteString insertString;
4604 int32_t iLength = 0;
4605 int32_t iStart = 0;
4606 int32_t iDelete = 0;
4607 std::unique_ptr<CFXJSE_Value> sourceValue = GetSimpleValue(pThis, args, 0);
4608 std::unique_ptr<CFXJSE_Value> startValue = GetSimpleValue(pThis, args, 1);
4609 std::unique_ptr<CFXJSE_Value> deleteValue = GetSimpleValue(pThis, args, 2);
4610 if (!CFXJSE_Value::IsNull(sourceValue.get()) &&
4611 !CFXJSE_Value::IsNull(startValue.get()) &&
4612 !CFXJSE_Value::IsNull(deleteValue.get())) {
4613 ValueToUTF8String(sourceValue.get(), sourceString);
4614 iLength = sourceString.GetLength();
4615 iStart = std::min(iLength, std::max(1, static_cast<int32_t>(ValueToFloat(
4616 pThis, startValue.get()))));
4617 iDelete = std::max(
4618 0, static_cast<int32_t>(ValueToFloat(pThis, deleteValue.get())));
4619 }
4620
4621 if (argc > 3) {
4622 std::unique_ptr<CFXJSE_Value> insertValue = GetSimpleValue(pThis, args, 3);
4623 ValueToUTF8String(insertValue.get(), insertString);
4624 }
4625
4626 iStart -= 1;
4627 CFX_ByteTextBuf resultString;
4628 int32_t i = 0;
4629 while (i < iStart) {
4630 resultString.AppendChar(sourceString.GetAt(i));
4631 ++i;
4632 }
4633 resultString << insertString.AsStringC();
4634 i = iStart + iDelete;
4635 while (i < iLength) {
4636 resultString.AppendChar(sourceString.GetAt(i));
4637 ++i;
4638 }
4639 resultString.AppendChar(0);
4640 args.GetReturnValue()->SetString(resultString.AsStringC());
4653 } 4641 }
4654 4642
4655 // static 4643 // static
4656 void CXFA_FM2JSContext::Substr(CFXJSE_Value* pThis, 4644 void CXFA_FM2JSContext::Substr(CFXJSE_Value* pThis,
4657 const CFX_ByteStringC& szFuncName, 4645 const CFX_ByteStringC& szFuncName,
4658 CFXJSE_Arguments& args) { 4646 CFXJSE_Arguments& args) {
4659 if (args.GetLength() == 3) { 4647 if (args.GetLength() != 3) {
4660 std::unique_ptr<CFXJSE_Value> stringValue = GetSimpleValue(pThis, args, 0);
4661 std::unique_ptr<CFXJSE_Value> startValue = GetSimpleValue(pThis, args, 1);
4662 std::unique_ptr<CFXJSE_Value> endValue = GetSimpleValue(pThis, args, 2);
4663 if (ValueIsNull(pThis, stringValue.get()) ||
4664 (ValueIsNull(pThis, startValue.get())) ||
4665 (ValueIsNull(pThis, endValue.get()))) {
4666 args.GetReturnValue()->SetNull();
4667 } else {
4668 CFX_ByteString szSourceStr;
4669 int32_t iStart = 0;
4670 int32_t iCount = 0;
4671 ValueToUTF8String(stringValue.get(), szSourceStr);
4672 int32_t iLength = szSourceStr.GetLength();
4673 if (iLength == 0) {
4674 args.GetReturnValue()->SetString("");
4675 } else {
4676 iStart = (int32_t)ValueToFloat(pThis, startValue.get());
4677 iCount = (int32_t)ValueToFloat(pThis, endValue.get());
4678 if (iStart < 1) {
4679 iStart = 1;
4680 }
4681 if (iStart > iLength) {
4682 iStart = iLength;
4683 }
4684 if (iCount <= 0) {
4685 iCount = 0;
4686 }
4687 iStart -= 1;
4688 args.GetReturnValue()->SetString(
4689 szSourceStr.Mid(iStart, iCount).AsStringC());
4690 }
4691 }
4692 } else {
4693 ToJSContext(pThis, nullptr) 4648 ToJSContext(pThis, nullptr)
4694 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Substr"); 4649 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Substr");
4650 return;
4695 } 4651 }
4652
4653 std::unique_ptr<CFXJSE_Value> stringValue = GetSimpleValue(pThis, args, 0);
4654 std::unique_ptr<CFXJSE_Value> startValue = GetSimpleValue(pThis, args, 1);
4655 std::unique_ptr<CFXJSE_Value> endValue = GetSimpleValue(pThis, args, 2);
4656 if (ValueIsNull(pThis, stringValue.get()) ||
4657 (ValueIsNull(pThis, startValue.get())) ||
4658 (ValueIsNull(pThis, endValue.get()))) {
4659 args.GetReturnValue()->SetNull();
4660 return;
4661 }
4662
4663 CFX_ByteString szSourceStr;
4664 int32_t iStart = 0;
4665 int32_t iCount = 0;
4666 ValueToUTF8String(stringValue.get(), szSourceStr);
4667 int32_t iLength = szSourceStr.GetLength();
4668 if (iLength == 0) {
4669 args.GetReturnValue()->SetString("");
4670 return;
4671 }
4672
4673 iStart = std::min(
4674 iLength,
4675 std::max(1, static_cast<int32_t>(ValueToFloat(pThis, startValue.get()))));
4676 iCount =
4677 std::max(0, static_cast<int32_t>(ValueToFloat(pThis, endValue.get())));
4678
4679 iStart -= 1;
4680 args.GetReturnValue()->SetString(szSourceStr.Mid(iStart, iCount).AsStringC());
4696 } 4681 }
4697 4682
4698 // static 4683 // static
4699 void CXFA_FM2JSContext::Uuid(CFXJSE_Value* pThis, 4684 void CXFA_FM2JSContext::Uuid(CFXJSE_Value* pThis,
4700 const CFX_ByteStringC& szFuncName, 4685 const CFX_ByteStringC& szFuncName,
4701 CFXJSE_Arguments& args) { 4686 CFXJSE_Arguments& args) {
4702 int32_t argc = args.GetLength(); 4687 int32_t argc = args.GetLength();
4703 if ((argc == 0) || (argc == 1)) { 4688 if (argc < 0 || argc > 1) {
4704 int32_t iNum = 0;
4705 if (argc > 0) {
4706 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4707 iNum = (int32_t)ValueToFloat(pThis, argOne.get());
4708 }
4709 FX_GUID guid;
4710 FX_GUID_CreateV4(&guid);
4711 CFX_ByteString bsUId;
4712 FX_GUID_ToString(&guid, bsUId, iNum);
4713 args.GetReturnValue()->SetString(bsUId.AsStringC());
4714 } else {
4715 ToJSContext(pThis, nullptr) 4689 ToJSContext(pThis, nullptr)
4716 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Uuid"); 4690 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Uuid");
4691 return;
4717 } 4692 }
4693
4694 int32_t iNum = 0;
4695 if (argc > 0) {
4696 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4697 iNum = static_cast<int32_t>(ValueToFloat(pThis, argOne.get()));
4698 }
4699 FX_GUID guid;
4700 FX_GUID_CreateV4(&guid);
4701
4702 CFX_ByteString bsUId;
4703 FX_GUID_ToString(&guid, bsUId, iNum);
4704 args.GetReturnValue()->SetString(bsUId.AsStringC());
4718 } 4705 }
4719 4706
4720 // static 4707 // static
4721 void CXFA_FM2JSContext::Upper(CFXJSE_Value* pThis, 4708 void CXFA_FM2JSContext::Upper(CFXJSE_Value* pThis,
4722 const CFX_ByteStringC& szFuncName, 4709 const CFX_ByteStringC& szFuncName,
4723 CFXJSE_Arguments& args) { 4710 CFXJSE_Arguments& args) {
4724 int32_t argc = args.GetLength(); 4711 int32_t argc = args.GetLength();
4725 if ((argc > 0) && (argc < 3)) { 4712 if (argc < 1 || argc > 2) {
4726 CFX_ByteString argString;
4727 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4728 if (ValueIsNull(pThis, argOne.get())) {
4729 args.GetReturnValue()->SetNull();
4730 } else {
4731 ValueToUTF8String(argOne.get(), argString);
4732 CFX_WideTextBuf upperStringBuf;
4733 CFX_WideString wsArgString =
4734 CFX_WideString::FromUTF8(argString.AsStringC());
4735 const FX_WCHAR* pData = wsArgString.c_str();
4736 int32_t iLen = wsArgString.GetLength();
4737 int32_t i = 0;
4738 int32_t ch = 0;
4739 while (i < iLen) {
4740 ch = pData[i];
4741 if (ch >= 0x61 && ch <= 0x7A) {
4742 ch -= 32;
4743 } else if (ch >= 0xE0 && ch <= 0xFE) {
4744 ch -= 32;
4745 } else if (ch == 0x101 || ch == 0x103 || ch == 0x105) {
4746 ch -= 1;
4747 }
4748 upperStringBuf.AppendChar(ch);
4749 ++i;
4750 }
4751 upperStringBuf.AppendChar(0);
4752 args.GetReturnValue()->SetString(
4753 FX_UTF8Encode(upperStringBuf.GetBuffer(), upperStringBuf.GetLength())
4754 .AsStringC());
4755 }
4756 } else {
4757 ToJSContext(pThis, nullptr) 4713 ToJSContext(pThis, nullptr)
4758 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Upper"); 4714 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Upper");
4715 return;
4759 } 4716 }
4717
4718 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0);
4719 if (ValueIsNull(pThis, argOne.get())) {
4720 args.GetReturnValue()->SetNull();
4721 return;
4722 }
4723
4724 CFX_ByteString argString;
4725 ValueToUTF8String(argOne.get(), argString);
4726
4727 CFX_WideTextBuf upperStringBuf;
4728 CFX_WideString wsArgString = CFX_WideString::FromUTF8(argString.AsStringC());
4729 const FX_WCHAR* pData = wsArgString.c_str();
4730 int32_t i = 0;
4731 while (i < wsArgString.GetLength()) {
4732 int32_t ch = pData[i];
4733 if ((ch >= 0x61 && ch <= 0x7A) || (ch >= 0xE0 && ch <= 0xFE))
4734 ch -= 32;
4735 else if (ch == 0x101 || ch == 0x103 || ch == 0x105)
4736 ch -= 1;
4737
4738 upperStringBuf.AppendChar(ch);
4739 ++i;
4740 }
4741 upperStringBuf.AppendChar(0);
4742
4743 args.GetReturnValue()->SetString(
4744 FX_UTF8Encode(upperStringBuf.GetBuffer(), upperStringBuf.GetLength())
4745 .AsStringC());
4760 } 4746 }
4761 4747
4762 // static 4748 // static
4763 void CXFA_FM2JSContext::WordNum(CFXJSE_Value* pThis, 4749 void CXFA_FM2JSContext::WordNum(CFXJSE_Value* pThis,
4764 const CFX_ByteStringC& szFuncName, 4750 const CFX_ByteStringC& szFuncName,
4765 CFXJSE_Arguments& args) { 4751 CFXJSE_Arguments& args) {
4766 int32_t argc = args.GetLength(); 4752 int32_t argc = args.GetLength();
4767 if ((argc > 0) && (argc < 4)) { 4753 if (argc < 1 || argc > 3) {
4768 FX_BOOL bFlags = FALSE;
4769 FX_FLOAT fNumber = 0.0f;
4770 int32_t iIdentifier = 0;
4771 CFX_ByteString localeString;
4772 std::unique_ptr<CFXJSE_Value> numberValue = GetSimpleValue(pThis, args, 0);
4773 if (CFXJSE_Value::IsNull(numberValue.get())) {
4774 bFlags = TRUE;
4775 } else {
4776 fNumber = ValueToFloat(pThis, numberValue.get());
4777 }
4778 if (argc > 1) {
4779 std::unique_ptr<CFXJSE_Value> identifierValue =
4780 GetSimpleValue(pThis, args, 1);
4781 if (CFXJSE_Value::IsNull(identifierValue.get())) {
4782 bFlags = TRUE;
4783 } else {
4784 iIdentifier = (int32_t)ValueToFloat(pThis, identifierValue.get());
4785 }
4786 }
4787 if (argc > 2) {
4788 std::unique_ptr<CFXJSE_Value> localeValue =
4789 GetSimpleValue(pThis, args, 2);
4790 if (CFXJSE_Value::IsNull(localeValue.get())) {
4791 bFlags = TRUE;
4792 } else {
4793 ValueToUTF8String(localeValue.get(), localeString);
4794 }
4795 }
4796 if (!bFlags) {
4797 if ((fNumber < 0) || (fNumber > 922337203685477550)) {
4798 args.GetReturnValue()->SetString("*");
4799 } else {
4800 CFX_ByteTextBuf resultBuf;
4801 CFX_ByteString numberString;
4802 numberString.Format("%.2f", fNumber);
4803 WordUS(numberString.AsStringC(), iIdentifier, resultBuf);
4804 args.GetReturnValue()->SetString(resultBuf.AsStringC());
4805 }
4806 } else {
4807 args.GetReturnValue()->SetNull();
4808 }
4809 } else {
4810 ToJSContext(pThis, nullptr) 4754 ToJSContext(pThis, nullptr)
4811 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"WordNum"); 4755 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"WordNum");
4756 return;
4812 } 4757 }
4758
4759 std::unique_ptr<CFXJSE_Value> numberValue = GetSimpleValue(pThis, args, 0);
4760 if (CFXJSE_Value::IsNull(numberValue.get())) {
4761 args.GetReturnValue()->SetNull();
4762 return;
4763 }
4764 FX_FLOAT fNumber = ValueToFloat(pThis, numberValue.get());
4765
4766 int32_t iIdentifier = 0;
4767 if (argc > 1) {
4768 std::unique_ptr<CFXJSE_Value> identifierValue =
4769 GetSimpleValue(pThis, args, 1);
4770 if (CFXJSE_Value::IsNull(identifierValue.get())) {
4771 args.GetReturnValue()->SetNull();
4772 return;
4773 }
4774 iIdentifier =
4775 static_cast<int32_t>(ValueToFloat(pThis, identifierValue.get()));
4776 }
4777
4778 CFX_ByteString localeString;
4779 if (argc > 2) {
4780 std::unique_ptr<CFXJSE_Value> localeValue = GetSimpleValue(pThis, args, 2);
4781 if (CFXJSE_Value::IsNull(localeValue.get())) {
4782 args.GetReturnValue()->SetNull();
4783 return;
4784 }
4785 ValueToUTF8String(localeValue.get(), localeString);
4786 }
4787
4788 if (fNumber < 0 || fNumber > 922337203685477550) {
Tom Sepez 2016/06/08 17:24:08 nit 0.0f and 922337203685477550.0f
dsinclair 2016/06/08 19:56:25 Done.
4789 args.GetReturnValue()->SetString("*");
4790 return;
4791 }
4792
4793 CFX_ByteString numberString;
4794 numberString.Format("%.2f", fNumber);
4795
4796 CFX_ByteTextBuf resultBuf;
4797 WordUS(numberString.AsStringC(), iIdentifier, resultBuf);
4798 args.GetReturnValue()->SetString(resultBuf.AsStringC());
4813 } 4799 }
4814 4800
4815 // static 4801 // static
4816 void CXFA_FM2JSContext::TrillionUS(const CFX_ByteStringC& szData, 4802 void CXFA_FM2JSContext::TrillionUS(const CFX_ByteStringC& szData,
4817 CFX_ByteTextBuf& strBuf) { 4803 CFX_ByteTextBuf& strBuf) {
4818 CFX_ByteStringC pUnits[] = {"zero", "one", "two", "three", "four", 4804 CFX_ByteStringC pUnits[] = {"zero", "one", "two", "three", "four",
4819 "five", "six", "seven", "eight", "nine"}; 4805 "five", "six", "seven", "eight", "nine"};
4820 CFX_ByteStringC pCapUnits[] = {"Zero", "One", "Two", "Three", "Four", 4806 CFX_ByteStringC pCapUnits[] = {"Zero", "One", "Two", "Three", "Four",
4821 "Five", "Six", "Seven", "Eight", "Nine"}; 4807 "Five", "Six", "Seven", "Eight", "Nine"};
4822 CFX_ByteStringC pTens[] = {"Ten", "Eleven", "Twelve", "Thirteen", 4808 CFX_ByteStringC pTens[] = {"Ten", "Eleven", "Twelve", "Thirteen",
(...skipping 1811 matching lines...) Expand 10 before | Expand all | Expand 10 after
6634 CFX_WideString wsFormat; 6620 CFX_WideString wsFormat;
6635 pAppProvider->LoadString(iStringID, wsFormat); 6621 pAppProvider->LoadString(iStringID, wsFormat);
6636 CFX_WideString wsMessage; 6622 CFX_WideString wsMessage;
6637 va_list arg_ptr; 6623 va_list arg_ptr;
6638 va_start(arg_ptr, iStringID); 6624 va_start(arg_ptr, iStringID);
6639 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); 6625 wsMessage.FormatV(wsFormat.c_str(), arg_ptr);
6640 va_end(arg_ptr); 6626 va_end(arg_ptr);
6641 FXJSE_ThrowMessage( 6627 FXJSE_ThrowMessage(
6642 FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); 6628 FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC());
6643 } 6629 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698