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