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 2941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2952 delete parametersValue[i]; | 2952 delete parametersValue[i]; |
2953 FX_Free(parametersValue); | 2953 FX_Free(parametersValue); |
2954 | 2954 |
2955 FXJSE_Value_SetInteger(args.GetReturnValue(), bFlags); | 2955 FXJSE_Value_SetInteger(args.GetReturnValue(), bFlags); |
2956 } | 2956 } |
2957 | 2957 |
2958 // static | 2958 // static |
2959 void CXFA_FM2JSContext::Within(CFXJSE_Value* pThis, | 2959 void CXFA_FM2JSContext::Within(CFXJSE_Value* pThis, |
2960 const CFX_ByteStringC& szFuncName, | 2960 const CFX_ByteStringC& szFuncName, |
2961 CFXJSE_Arguments& args) { | 2961 CFXJSE_Arguments& args) { |
2962 if (args.GetLength() == 3) { | 2962 if (args.GetLength() != 3) { |
2963 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); | |
2964 if (FXJSE_Value_IsNull(argOne.get())) { | |
2965 FXJSE_Value_SetUndefined(args.GetReturnValue()); | |
2966 } else { | |
2967 std::unique_ptr<CFXJSE_Value> argLow = GetSimpleValue(pThis, args, 1); | |
2968 std::unique_ptr<CFXJSE_Value> argHeight = GetSimpleValue(pThis, args, 2); | |
2969 if (FXJSE_Value_IsNumber(argOne.get())) { | |
2970 FX_FLOAT oneNumber = ValueToFloat(pThis, argOne.get()); | |
2971 FX_FLOAT lowNumber = ValueToFloat(pThis, argLow.get()); | |
2972 FX_FLOAT heightNumber = ValueToFloat(pThis, argHeight.get()); | |
2973 FXJSE_Value_SetInteger( | |
2974 args.GetReturnValue(), | |
2975 ((oneNumber >= lowNumber) && (oneNumber <= heightNumber))); | |
2976 } else { | |
2977 CFX_ByteString oneString; | |
2978 CFX_ByteString lowString; | |
2979 CFX_ByteString heightString; | |
2980 ValueToUTF8String(argOne.get(), oneString); | |
2981 ValueToUTF8String(argLow.get(), lowString); | |
2982 ValueToUTF8String(argHeight.get(), heightString); | |
2983 FXJSE_Value_SetInteger( | |
2984 args.GetReturnValue(), | |
2985 ((oneString.Compare(lowString.AsStringC()) >= 0) && | |
2986 (oneString.Compare(heightString.AsStringC()) <= 0))); | |
2987 } | |
2988 } | |
2989 } else { | |
2990 ToJSContext(pThis, nullptr) | 2963 ToJSContext(pThis, nullptr) |
2991 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Within"); | 2964 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Within"); |
| 2965 return; |
2992 } | 2966 } |
| 2967 |
| 2968 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); |
| 2969 if (FXJSE_Value_IsNull(argOne.get())) { |
| 2970 FXJSE_Value_SetUndefined(args.GetReturnValue()); |
| 2971 return; |
| 2972 } |
| 2973 |
| 2974 std::unique_ptr<CFXJSE_Value> argLow = GetSimpleValue(pThis, args, 1); |
| 2975 std::unique_ptr<CFXJSE_Value> argHigh = GetSimpleValue(pThis, args, 2); |
| 2976 if (FXJSE_Value_IsNumber(argOne.get())) { |
| 2977 FX_FLOAT oneNumber = ValueToFloat(pThis, argOne.get()); |
| 2978 FX_FLOAT lowNumber = ValueToFloat(pThis, argLow.get()); |
| 2979 FX_FLOAT heightNumber = ValueToFloat(pThis, argHigh.get()); |
| 2980 FXJSE_Value_SetInteger( |
| 2981 args.GetReturnValue(), |
| 2982 ((oneNumber >= lowNumber) && (oneNumber <= heightNumber))); |
| 2983 return; |
| 2984 } |
| 2985 |
| 2986 CFX_ByteString oneString; |
| 2987 CFX_ByteString lowString; |
| 2988 CFX_ByteString heightString; |
| 2989 ValueToUTF8String(argOne.get(), oneString); |
| 2990 ValueToUTF8String(argLow.get(), lowString); |
| 2991 ValueToUTF8String(argHigh.get(), heightString); |
| 2992 FXJSE_Value_SetInteger(args.GetReturnValue(), |
| 2993 ((oneString.Compare(lowString.AsStringC()) >= 0) && |
| 2994 (oneString.Compare(heightString.AsStringC()) <= 0))); |
2993 } | 2995 } |
2994 | 2996 |
2995 // static | 2997 // static |
2996 void CXFA_FM2JSContext::If(CFXJSE_Value* pThis, | 2998 void CXFA_FM2JSContext::If(CFXJSE_Value* pThis, |
2997 const CFX_ByteStringC& szFuncName, | 2999 const CFX_ByteStringC& szFuncName, |
2998 CFXJSE_Arguments& args) { | 3000 CFXJSE_Arguments& args) { |
2999 if (args.GetLength() == 3) { | 3001 if (args.GetLength() != 3) { |
3000 std::unique_ptr<CFXJSE_Value> argCondition = GetSimpleValue(pThis, args, 0); | |
3001 std::unique_ptr<CFXJSE_Value> argFirstValue = | |
3002 GetSimpleValue(pThis, args, 1); | |
3003 std::unique_ptr<CFXJSE_Value> argSecondValue = | |
3004 GetSimpleValue(pThis, args, 2); | |
3005 FX_BOOL bCondition = FXJSE_Value_ToBoolean(argCondition.get()); | |
3006 FXJSE_Value_Set(args.GetReturnValue(), | |
3007 bCondition ? argFirstValue.get() : argSecondValue.get()); | |
3008 } else { | |
3009 ToJSContext(pThis, nullptr) | 3002 ToJSContext(pThis, nullptr) |
3010 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"If"); | 3003 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"If"); |
| 3004 return; |
3011 } | 3005 } |
| 3006 |
| 3007 FXJSE_Value_Set(args.GetReturnValue(), |
| 3008 FXJSE_Value_ToBoolean(GetSimpleValue(pThis, args, 0).get()) |
| 3009 ? GetSimpleValue(pThis, args, 1).get() |
| 3010 : GetSimpleValue(pThis, args, 2).get()); |
3012 } | 3011 } |
3013 | 3012 |
3014 // static | 3013 // static |
3015 void CXFA_FM2JSContext::Eval(CFXJSE_Value* pThis, | 3014 void CXFA_FM2JSContext::Eval(CFXJSE_Value* pThis, |
3016 const CFX_ByteStringC& szFuncName, | 3015 const CFX_ByteStringC& szFuncName, |
3017 CFXJSE_Arguments& args) { | 3016 CFXJSE_Arguments& args) { |
3018 CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr); | 3017 CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr); |
3019 if (args.GetLength() == 1) { | 3018 if (args.GetLength() != 1) { |
3020 v8::Isolate* pIsolate = pContext->GetScriptRuntime(); | |
3021 std::unique_ptr<CFXJSE_Value> scriptValue = GetSimpleValue(pThis, args, 0); | |
3022 CFX_ByteString utf8ScriptString; | |
3023 ValueToUTF8String(scriptValue.get(), utf8ScriptString); | |
3024 if (utf8ScriptString.IsEmpty()) { | |
3025 FXJSE_Value_SetNull(args.GetReturnValue()); | |
3026 } else { | |
3027 CFX_WideTextBuf wsJavaScriptBuf; | |
3028 CFX_WideString javaScript; | |
3029 CFX_WideString wsError; | |
3030 CXFA_FM2JSContext::Translate( | |
3031 CFX_WideString::FromUTF8(utf8ScriptString.AsStringC()).AsStringC(), | |
3032 wsJavaScriptBuf, wsError); | |
3033 CFXJSE_Context* pNewContext = | |
3034 FXJSE_Context_Create(pIsolate, nullptr, nullptr); | |
3035 std::unique_ptr<CFXJSE_Value> returnValue(new CFXJSE_Value(pIsolate)); | |
3036 javaScript = wsJavaScriptBuf.AsStringC(); | |
3037 FXJSE_ExecuteScript( | |
3038 pNewContext, | |
3039 FX_UTF8Encode(javaScript.c_str(), javaScript.GetLength()).c_str(), | |
3040 returnValue.get()); | |
3041 FXJSE_Value_Set(args.GetReturnValue(), returnValue.get()); | |
3042 FXJSE_Context_Release(pNewContext); | |
3043 } | |
3044 } else { | |
3045 pContext->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Eval"); | 3019 pContext->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Eval"); |
| 3020 return; |
3046 } | 3021 } |
| 3022 |
| 3023 v8::Isolate* pIsolate = pContext->GetScriptRuntime(); |
| 3024 std::unique_ptr<CFXJSE_Value> scriptValue = GetSimpleValue(pThis, args, 0); |
| 3025 CFX_ByteString utf8ScriptString; |
| 3026 ValueToUTF8String(scriptValue.get(), utf8ScriptString); |
| 3027 if (utf8ScriptString.IsEmpty()) { |
| 3028 FXJSE_Value_SetNull(args.GetReturnValue()); |
| 3029 return; |
| 3030 } |
| 3031 |
| 3032 CFX_WideTextBuf wsJavaScriptBuf; |
| 3033 CFX_WideString wsError; |
| 3034 CXFA_FM2JSContext::Translate( |
| 3035 CFX_WideString::FromUTF8(utf8ScriptString.AsStringC()).AsStringC(), |
| 3036 wsJavaScriptBuf, wsError); |
| 3037 CFXJSE_Context* pNewContext = |
| 3038 FXJSE_Context_Create(pIsolate, nullptr, nullptr); |
| 3039 |
| 3040 std::unique_ptr<CFXJSE_Value> returnValue(new CFXJSE_Value(pIsolate)); |
| 3041 CFX_WideString javaScript(wsJavaScriptBuf.AsStringC()); |
| 3042 FXJSE_ExecuteScript( |
| 3043 pNewContext, |
| 3044 FX_UTF8Encode(javaScript.c_str(), javaScript.GetLength()).c_str(), |
| 3045 returnValue.get()); |
| 3046 |
| 3047 FXJSE_Value_Set(args.GetReturnValue(), returnValue.get()); |
| 3048 FXJSE_Context_Release(pNewContext); |
3047 } | 3049 } |
3048 | 3050 |
3049 // static | 3051 // static |
3050 void CXFA_FM2JSContext::Ref(CFXJSE_Value* pThis, | 3052 void CXFA_FM2JSContext::Ref(CFXJSE_Value* pThis, |
3051 const CFX_ByteStringC& szFuncName, | 3053 const CFX_ByteStringC& szFuncName, |
3052 CFXJSE_Arguments& args) { | 3054 CFXJSE_Arguments& args) { |
3053 CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr); | 3055 CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr); |
3054 v8::Isolate* pIsolate = pContext->GetScriptRuntime(); | 3056 v8::Isolate* pIsolate = pContext->GetScriptRuntime(); |
3055 if (args.GetLength() == 1) { | 3057 if (args.GetLength() != 1) { |
3056 std::unique_ptr<CFXJSE_Value> argOne = args.GetValue(0); | 3058 pContext->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Ref"); |
3057 if (FXJSE_Value_IsNull(argOne.get())) { | 3059 return; |
3058 CFXJSE_Value* rgValues[3]; | 3060 } |
3059 for (int32_t i = 0; i < 3; i++) | |
3060 rgValues[i] = new CFXJSE_Value(pIsolate); | |
3061 | 3061 |
3062 FXJSE_Value_SetInteger(rgValues[0], 4); | 3062 std::unique_ptr<CFXJSE_Value> argOne = args.GetValue(0); |
3063 FXJSE_Value_SetNull(rgValues[1]); | 3063 if (!FXJSE_Value_IsArray(argOne.get()) && |
3064 FXJSE_Value_SetNull(rgValues[2]); | 3064 !FXJSE_Value_IsObject(argOne.get()) && |
3065 FXJSE_Value_SetArray(args.GetReturnValue(), 3, rgValues); | 3065 !FXJSE_Value_IsBoolean(argOne.get()) && |
| 3066 !FXJSE_Value_IsUTF8String(argOne.get()) && |
| 3067 !FXJSE_Value_IsNull(argOne.get()) && |
| 3068 !FXJSE_Value_IsNumber(argOne.get())) { |
| 3069 pContext->ThrowException(XFA_IDS_ARGUMENT_MISMATCH); |
| 3070 return; |
| 3071 } |
| 3072 |
| 3073 if (FXJSE_Value_IsBoolean(argOne.get()) || |
| 3074 FXJSE_Value_IsUTF8String(argOne.get()) || |
| 3075 FXJSE_Value_IsNumber(argOne.get())) { |
| 3076 FXJSE_Value_Set(args.GetReturnValue(), argOne.get()); |
| 3077 return; |
| 3078 } |
| 3079 |
| 3080 CFXJSE_Value* rgValues[3]; |
| 3081 for (int32_t i = 0; i < 3; i++) |
| 3082 rgValues[i] = new CFXJSE_Value(pIsolate); |
| 3083 |
| 3084 int intVal = 3; |
| 3085 if (FXJSE_Value_IsNull(argOne.get())) { |
| 3086 intVal = 4; |
| 3087 FXJSE_Value_SetNull(rgValues[2]); |
| 3088 } else if (FXJSE_Value_IsArray(argOne.get())) { |
| 3089 #ifndef NDEBUG |
| 3090 std::unique_ptr<CFXJSE_Value> lengthValue(new CFXJSE_Value(pIsolate)); |
| 3091 FXJSE_Value_GetObjectProp(argOne.get(), "length", lengthValue.get()); |
| 3092 ASSERT(FXJSE_Value_ToInteger(lengthValue.get()) >= 3); |
| 3093 #endif |
| 3094 |
| 3095 std::unique_ptr<CFXJSE_Value> propertyValue(new CFXJSE_Value(pIsolate)); |
| 3096 std::unique_ptr<CFXJSE_Value> jsObjectValue(new CFXJSE_Value(pIsolate)); |
| 3097 FXJSE_Value_GetObjectPropByIdx(argOne.get(), 1, propertyValue.get()); |
| 3098 FXJSE_Value_GetObjectPropByIdx(argOne.get(), 2, jsObjectValue.get()); |
| 3099 if (!FXJSE_Value_IsNull(propertyValue.get()) || |
| 3100 FXJSE_Value_IsNull(jsObjectValue.get())) { |
3066 for (int32_t i = 0; i < 3; i++) | 3101 for (int32_t i = 0; i < 3; i++) |
3067 delete rgValues[i]; | 3102 delete rgValues[i]; |
3068 | 3103 |
3069 } else if (FXJSE_Value_IsArray(argOne.get())) { | 3104 pContext->ThrowException(XFA_IDS_ARGUMENT_MISMATCH); |
3070 #ifndef NDEBUG | 3105 return; |
3071 std::unique_ptr<CFXJSE_Value> lengthValue(new CFXJSE_Value(pIsolate)); | 3106 } |
3072 FXJSE_Value_GetObjectProp(argOne.get(), "length", lengthValue.get()); | |
3073 ASSERT(FXJSE_Value_ToInteger(lengthValue.get()) >= 3); | |
3074 #endif | |
3075 std::unique_ptr<CFXJSE_Value> propertyValue(new CFXJSE_Value(pIsolate)); | |
3076 std::unique_ptr<CFXJSE_Value> jsObjectValue(new CFXJSE_Value(pIsolate)); | |
3077 FXJSE_Value_GetObjectPropByIdx(argOne.get(), 1, propertyValue.get()); | |
3078 FXJSE_Value_GetObjectPropByIdx(argOne.get(), 2, jsObjectValue.get()); | |
3079 if (FXJSE_Value_IsNull(jsObjectValue.get())) { | |
3080 pContext->ThrowException(XFA_IDS_ARGUMENT_MISMATCH); | |
3081 } else if (FXJSE_Value_IsNull(propertyValue.get()) && | |
3082 (!FXJSE_Value_IsNull(jsObjectValue.get()))) { | |
3083 CFXJSE_Value* rgValues[3]; | |
3084 for (int32_t i = 0; i < 3; i++) | |
3085 rgValues[i] = new CFXJSE_Value(pIsolate); | |
3086 | 3107 |
3087 FXJSE_Value_SetInteger(rgValues[0], 3); | 3108 FXJSE_Value_Set(rgValues[2], jsObjectValue.get()); |
3088 FXJSE_Value_SetNull(rgValues[1]); | 3109 } else if (FXJSE_Value_IsObject(argOne.get())) { |
3089 FXJSE_Value_Set(rgValues[2], jsObjectValue.get()); | 3110 FXJSE_Value_Set(rgValues[2], argOne.get()); |
3090 FXJSE_Value_SetArray(args.GetReturnValue(), 3, rgValues); | 3111 } |
3091 for (int32_t i = 0; i < 3; i++) | |
3092 delete rgValues[i]; | |
3093 | 3112 |
3094 } else { | 3113 FXJSE_Value_SetInteger(rgValues[0], intVal); |
3095 pContext->ThrowException(XFA_IDS_ARGUMENT_MISMATCH); | 3114 FXJSE_Value_SetNull(rgValues[1]); |
3096 } | 3115 FXJSE_Value_SetArray(args.GetReturnValue(), 3, rgValues); |
3097 } else if (FXJSE_Value_IsObject(argOne.get())) { | |
3098 CFXJSE_Value* rgValues[3]; | |
3099 for (int32_t i = 0; i < 3; i++) | |
3100 rgValues[i] = new CFXJSE_Value(pIsolate); | |
3101 | 3116 |
3102 FXJSE_Value_SetInteger(rgValues[0], 3); | 3117 for (int32_t i = 0; i < 3; i++) |
3103 FXJSE_Value_SetNull(rgValues[1]); | 3118 delete rgValues[i]; |
3104 FXJSE_Value_Set(rgValues[2], argOne.get()); | |
3105 FXJSE_Value_SetArray(args.GetReturnValue(), 3, rgValues); | |
3106 | |
3107 for (int32_t i = 0; i < 3; i++) | |
3108 delete rgValues[i]; | |
3109 } else if (FXJSE_Value_IsBoolean(argOne.get()) || | |
3110 FXJSE_Value_IsUTF8String(argOne.get()) || | |
3111 FXJSE_Value_IsNumber(argOne.get())) { | |
3112 FXJSE_Value_Set(args.GetReturnValue(), argOne.get()); | |
3113 } else { | |
3114 pContext->ThrowException(XFA_IDS_ARGUMENT_MISMATCH); | |
3115 } | |
3116 } else { | |
3117 pContext->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Ref"); | |
3118 } | |
3119 } | 3119 } |
3120 | 3120 |
3121 // static | 3121 // static |
3122 void CXFA_FM2JSContext::UnitType(CFXJSE_Value* pThis, | 3122 void CXFA_FM2JSContext::UnitType(CFXJSE_Value* pThis, |
3123 const CFX_ByteStringC& szFuncName, | 3123 const CFX_ByteStringC& szFuncName, |
3124 CFXJSE_Arguments& args) { | 3124 CFXJSE_Arguments& args) { |
3125 if (args.GetLength() == 1) { | 3125 if (args.GetLength() != 1) { |
3126 std::unique_ptr<CFXJSE_Value> unitspanValue = | |
3127 GetSimpleValue(pThis, args, 0); | |
3128 if (FXJSE_Value_IsNull(unitspanValue.get())) { | |
3129 FXJSE_Value_SetNull(args.GetReturnValue()); | |
3130 return; | |
3131 } | |
3132 CFX_ByteString unitspanString; | |
3133 ValueToUTF8String(unitspanValue.get(), unitspanString); | |
3134 if (unitspanString.IsEmpty()) { | |
3135 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "in"); | |
3136 } else { | |
3137 enum XFA_FM2JS_VALUETYPE_ParserStatus { | |
3138 VALUETYPE_START, | |
3139 VALUETYPE_HAVEINVALIDCHAR, | |
3140 VALUETYPE_HAVEDIGIT, | |
3141 VALUETYPE_HAVEDIGITWHITE, | |
3142 VALUETYPE_ISCM, | |
3143 VALUETYPE_ISMM, | |
3144 VALUETYPE_ISPT, | |
3145 VALUETYPE_ISMP, | |
3146 VALUETYPE_ISIN, | |
3147 }; | |
3148 unitspanString.MakeLower(); | |
3149 CFX_WideString wsTypeString = | |
3150 CFX_WideString::FromUTF8(unitspanString.AsStringC()); | |
3151 const FX_WCHAR* pData = wsTypeString.c_str(); | |
3152 int32_t u = 0; | |
3153 int32_t uLen = wsTypeString.GetLength(); | |
3154 while (IsWhitespace(pData[u])) | |
3155 u++; | |
3156 | |
3157 XFA_FM2JS_VALUETYPE_ParserStatus eParserStatus = VALUETYPE_START; | |
3158 FX_WCHAR typeChar; | |
3159 while (u < uLen) { | |
3160 typeChar = pData[u]; | |
3161 if (IsWhitespace(typeChar)) { | |
3162 if (eParserStatus == VALUETYPE_HAVEDIGIT || | |
3163 eParserStatus == VALUETYPE_HAVEDIGITWHITE) { | |
3164 eParserStatus = VALUETYPE_HAVEDIGITWHITE; | |
3165 } else { | |
3166 eParserStatus = VALUETYPE_ISIN; | |
3167 break; | |
3168 } | |
3169 } else if ((typeChar >= '0' && typeChar <= '9') || typeChar == '-' || | |
3170 typeChar == '.') { | |
3171 if (eParserStatus == VALUETYPE_HAVEDIGITWHITE) { | |
3172 eParserStatus = VALUETYPE_ISIN; | |
3173 break; | |
3174 } else { | |
3175 eParserStatus = VALUETYPE_HAVEDIGIT; | |
3176 } | |
3177 } else if ((typeChar == 'c' || typeChar == 'p') && (u + 1 < uLen)) { | |
3178 FX_WCHAR nextChar = pData[u + 1]; | |
3179 if ((eParserStatus == VALUETYPE_START || | |
3180 eParserStatus == VALUETYPE_HAVEDIGIT || | |
3181 eParserStatus == VALUETYPE_HAVEDIGITWHITE) && | |
3182 (nextChar > '9' || nextChar < '0') && nextChar != '.' && | |
3183 nextChar != '-') { | |
3184 eParserStatus = (typeChar == 'c') ? VALUETYPE_ISCM : VALUETYPE_ISPT; | |
3185 break; | |
3186 } else { | |
3187 eParserStatus = VALUETYPE_HAVEINVALIDCHAR; | |
3188 } | |
3189 } else if (typeChar == 'm' && (u + 1 < uLen)) { | |
3190 FX_WCHAR nextChar = pData[u + 1]; | |
3191 if ((eParserStatus == VALUETYPE_START || | |
3192 eParserStatus == VALUETYPE_HAVEDIGIT || | |
3193 eParserStatus == VALUETYPE_HAVEDIGITWHITE) && | |
3194 (nextChar > '9' || nextChar < '0') && nextChar != '.' && | |
3195 nextChar != '-') { | |
3196 eParserStatus = VALUETYPE_ISMM; | |
3197 if (nextChar == 'p' || | |
3198 ((u + 5 < uLen) && pData[u + 1] == 'i' && pData[u + 2] == 'l' && | |
3199 pData[u + 3] == 'l' && pData[u + 4] == 'i' && | |
3200 pData[u + 5] == 'p')) { | |
3201 eParserStatus = VALUETYPE_ISMP; | |
3202 } | |
3203 break; | |
3204 } | |
3205 } else { | |
3206 eParserStatus = VALUETYPE_HAVEINVALIDCHAR; | |
3207 } | |
3208 u++; | |
3209 } | |
3210 switch (eParserStatus) { | |
3211 case VALUETYPE_ISCM: | |
3212 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "cm"); | |
3213 break; | |
3214 case VALUETYPE_ISMM: | |
3215 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "mm"); | |
3216 break; | |
3217 case VALUETYPE_ISPT: | |
3218 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "pt"); | |
3219 break; | |
3220 case VALUETYPE_ISMP: | |
3221 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "mp"); | |
3222 break; | |
3223 default: | |
3224 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "in"); | |
3225 break; | |
3226 } | |
3227 } | |
3228 } else { | |
3229 ToJSContext(pThis, nullptr) | 3126 ToJSContext(pThis, nullptr) |
3230 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"UnitType"); | 3127 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"UnitType"); |
| 3128 return; |
| 3129 } |
| 3130 |
| 3131 std::unique_ptr<CFXJSE_Value> unitspanValue = GetSimpleValue(pThis, args, 0); |
| 3132 if (FXJSE_Value_IsNull(unitspanValue.get())) { |
| 3133 FXJSE_Value_SetNull(args.GetReturnValue()); |
| 3134 return; |
| 3135 } |
| 3136 |
| 3137 CFX_ByteString unitspanString; |
| 3138 ValueToUTF8String(unitspanValue.get(), unitspanString); |
| 3139 if (unitspanString.IsEmpty()) { |
| 3140 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "in"); |
| 3141 return; |
| 3142 } |
| 3143 |
| 3144 enum XFA_FM2JS_VALUETYPE_ParserStatus { |
| 3145 VALUETYPE_START, |
| 3146 VALUETYPE_HAVEINVALIDCHAR, |
| 3147 VALUETYPE_HAVEDIGIT, |
| 3148 VALUETYPE_HAVEDIGITWHITE, |
| 3149 VALUETYPE_ISCM, |
| 3150 VALUETYPE_ISMM, |
| 3151 VALUETYPE_ISPT, |
| 3152 VALUETYPE_ISMP, |
| 3153 VALUETYPE_ISIN, |
| 3154 }; |
| 3155 unitspanString.MakeLower(); |
| 3156 CFX_WideString wsTypeString = |
| 3157 CFX_WideString::FromUTF8(unitspanString.AsStringC()); |
| 3158 const FX_WCHAR* pData = wsTypeString.c_str(); |
| 3159 int32_t u = 0; |
| 3160 int32_t uLen = wsTypeString.GetLength(); |
| 3161 while (IsWhitespace(pData[u])) |
| 3162 u++; |
| 3163 |
| 3164 XFA_FM2JS_VALUETYPE_ParserStatus eParserStatus = VALUETYPE_START; |
| 3165 FX_WCHAR typeChar; |
| 3166 // TODO(dsinclair): Cleanup this parser, figure out what the various checks |
| 3167 // are for. |
| 3168 while (u < uLen) { |
| 3169 typeChar = pData[u]; |
| 3170 if (IsWhitespace(typeChar)) { |
| 3171 if (eParserStatus != VALUETYPE_HAVEDIGIT && |
| 3172 eParserStatus != VALUETYPE_HAVEDIGITWHITE) { |
| 3173 eParserStatus = VALUETYPE_ISIN; |
| 3174 break; |
| 3175 } |
| 3176 eParserStatus = VALUETYPE_HAVEDIGITWHITE; |
| 3177 } else if ((typeChar >= '0' && typeChar <= '9') || typeChar == '-' || |
| 3178 typeChar == '.') { |
| 3179 if (eParserStatus == VALUETYPE_HAVEDIGITWHITE) { |
| 3180 eParserStatus = VALUETYPE_ISIN; |
| 3181 break; |
| 3182 } |
| 3183 eParserStatus = VALUETYPE_HAVEDIGIT; |
| 3184 } else if ((typeChar == 'c' || typeChar == 'p') && (u + 1 < uLen)) { |
| 3185 FX_WCHAR nextChar = pData[u + 1]; |
| 3186 if ((eParserStatus == VALUETYPE_START || |
| 3187 eParserStatus == VALUETYPE_HAVEDIGIT || |
| 3188 eParserStatus == VALUETYPE_HAVEDIGITWHITE) && |
| 3189 (nextChar > '9' || nextChar < '0') && nextChar != '.' && |
| 3190 nextChar != '-') { |
| 3191 eParserStatus = (typeChar == 'c') ? VALUETYPE_ISCM : VALUETYPE_ISPT; |
| 3192 break; |
| 3193 } |
| 3194 eParserStatus = VALUETYPE_HAVEINVALIDCHAR; |
| 3195 } else if (typeChar == 'm' && (u + 1 < uLen)) { |
| 3196 FX_WCHAR nextChar = pData[u + 1]; |
| 3197 if ((eParserStatus == VALUETYPE_START || |
| 3198 eParserStatus == VALUETYPE_HAVEDIGIT || |
| 3199 eParserStatus == VALUETYPE_HAVEDIGITWHITE) && |
| 3200 (nextChar > '9' || nextChar < '0') && nextChar != '.' && |
| 3201 nextChar != '-') { |
| 3202 eParserStatus = VALUETYPE_ISMM; |
| 3203 if (nextChar == 'p' || ((u + 5 < uLen) && pData[u + 1] == 'i' && |
| 3204 pData[u + 2] == 'l' && pData[u + 3] == 'l' && |
| 3205 pData[u + 4] == 'i' && pData[u + 5] == 'p')) { |
| 3206 eParserStatus = VALUETYPE_ISMP; |
| 3207 } |
| 3208 break; |
| 3209 } |
| 3210 } else { |
| 3211 eParserStatus = VALUETYPE_HAVEINVALIDCHAR; |
| 3212 } |
| 3213 u++; |
| 3214 } |
| 3215 switch (eParserStatus) { |
| 3216 case VALUETYPE_ISCM: |
| 3217 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "cm"); |
| 3218 break; |
| 3219 case VALUETYPE_ISMM: |
| 3220 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "mm"); |
| 3221 break; |
| 3222 case VALUETYPE_ISPT: |
| 3223 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "pt"); |
| 3224 break; |
| 3225 case VALUETYPE_ISMP: |
| 3226 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "mp"); |
| 3227 break; |
| 3228 default: |
| 3229 FXJSE_Value_SetUTF8String(args.GetReturnValue(), "in"); |
| 3230 break; |
3231 } | 3231 } |
3232 } | 3232 } |
3233 | 3233 |
3234 // static | 3234 // static |
3235 void CXFA_FM2JSContext::UnitValue(CFXJSE_Value* pThis, | 3235 void CXFA_FM2JSContext::UnitValue(CFXJSE_Value* pThis, |
3236 const CFX_ByteStringC& szFuncName, | 3236 const CFX_ByteStringC& szFuncName, |
3237 CFXJSE_Arguments& args) { | 3237 CFXJSE_Arguments& args) { |
3238 int32_t argc = args.GetLength(); | 3238 int32_t argc = args.GetLength(); |
3239 if ((argc == 1) || (argc == 2)) { | 3239 if (argc < 1 || argc > 2) { |
3240 std::unique_ptr<CFXJSE_Value> unitspanValue = | |
3241 GetSimpleValue(pThis, args, 0); | |
3242 CFX_ByteString unitspanString; | |
3243 FX_DOUBLE dFirstNumber = 0; | |
3244 CFX_ByteString strFirstUnit; | |
3245 CFX_ByteString strUnit; | |
3246 if (FXJSE_Value_IsNull(unitspanValue.get())) { | |
3247 FXJSE_Value_SetNull(args.GetReturnValue()); | |
3248 } else { | |
3249 ValueToUTF8String(unitspanValue.get(), unitspanString); | |
3250 const FX_CHAR* pData = unitspanString.c_str(); | |
3251 if (pData) { | |
3252 int32_t u = 0; | |
3253 while (IsWhitespace(pData[u])) | |
3254 ++u; | |
3255 | |
3256 while (u < unitspanString.GetLength()) { | |
3257 if ((pData[u] > '9' || pData[u] < '0') && pData[u] != '.' && | |
3258 pData[u] != '-') { | |
3259 break; | |
3260 } | |
3261 ++u; | |
3262 } | |
3263 FX_CHAR* pTemp = nullptr; | |
3264 dFirstNumber = strtod(pData, &pTemp); | |
3265 while (IsWhitespace(pData[u])) | |
3266 ++u; | |
3267 | |
3268 int32_t uLen = unitspanString.GetLength(); | |
3269 while (u < uLen) { | |
3270 if (pData[u] == ' ') { | |
3271 break; | |
3272 } | |
3273 strFirstUnit += pData[u]; | |
3274 ++u; | |
3275 } | |
3276 strFirstUnit.MakeLower(); | |
3277 if (argc == 2) { | |
3278 std::unique_ptr<CFXJSE_Value> unitValue = | |
3279 GetSimpleValue(pThis, args, 1); | |
3280 CFX_ByteString unitTempString; | |
3281 ValueToUTF8String(unitValue.get(), unitTempString); | |
3282 const FX_CHAR* pChar = unitTempString.c_str(); | |
3283 int32_t uVal = 0; | |
3284 while (IsWhitespace(pChar[uVal])) | |
3285 ++uVal; | |
3286 | |
3287 while (uVal < unitTempString.GetLength()) { | |
3288 if ((pChar[uVal] > '9' || pChar[uVal] < '0') && | |
3289 pChar[uVal] != '.') { | |
3290 break; | |
3291 } | |
3292 ++uVal; | |
3293 } | |
3294 while (IsWhitespace(pChar[uVal])) | |
3295 ++uVal; | |
3296 | |
3297 int32_t uValLen = unitTempString.GetLength(); | |
3298 while (uVal < uValLen) { | |
3299 if (pChar[uVal] == ' ') { | |
3300 break; | |
3301 } | |
3302 strUnit += pChar[uVal]; | |
3303 ++uVal; | |
3304 } | |
3305 strUnit.MakeLower(); | |
3306 } else { | |
3307 strUnit = strFirstUnit; | |
3308 } | |
3309 FX_DOUBLE dResult = 0; | |
3310 if (strFirstUnit == "in" || strFirstUnit == "inches") { | |
3311 if (strUnit == "mm" || strUnit == "millimeters") { | |
3312 dResult = dFirstNumber * 25.4; | |
3313 } else if (strUnit == "cm" || strUnit == "centimeters") { | |
3314 dResult = dFirstNumber * 2.54; | |
3315 } else if (strUnit == "pt" || strUnit == "points") { | |
3316 dResult = dFirstNumber / 72; | |
3317 } else if (strUnit == "mp" || strUnit == "millipoints") { | |
3318 dResult = dFirstNumber / 72000; | |
3319 } else { | |
3320 dResult = dFirstNumber; | |
3321 } | |
3322 } else if (strFirstUnit == "mm" || strFirstUnit == "millimeters") { | |
3323 if (strUnit == "mm" || strUnit == "millimeters") { | |
3324 dResult = dFirstNumber; | |
3325 } else if (strUnit == "cm" || strUnit == "centimeters") { | |
3326 dResult = dFirstNumber / 10; | |
3327 } else if (strUnit == "pt" || strUnit == "points") { | |
3328 dResult = dFirstNumber / 25.4 / 72; | |
3329 } else if (strUnit == "mp" || strUnit == "millipoints") { | |
3330 dResult = dFirstNumber / 25.4 / 72000; | |
3331 } else { | |
3332 dResult = dFirstNumber / 25.4; | |
3333 } | |
3334 } else if (strFirstUnit == "cm" || strFirstUnit == "centimeters") { | |
3335 if (strUnit == "mm" || strUnit == "millimeters") { | |
3336 dResult = dFirstNumber * 10; | |
3337 } else if (strUnit == "cm" || strUnit == "centimeters") { | |
3338 dResult = dFirstNumber; | |
3339 } else if (strUnit == "pt" || strUnit == "points") { | |
3340 dResult = dFirstNumber / 2.54 / 72; | |
3341 } else if (strUnit == "mp" || strUnit == "millipoints") { | |
3342 dResult = dFirstNumber / 2.54 / 72000; | |
3343 } else { | |
3344 dResult = dFirstNumber / 2.54; | |
3345 } | |
3346 } else if (strFirstUnit == "pt" || strFirstUnit == "points") { | |
3347 if (strUnit == "mm" || strUnit == "millimeters") { | |
3348 dResult = dFirstNumber / 72 * 25.4; | |
3349 } else if (strUnit == "cm" || strUnit == "centimeters") { | |
3350 dResult = dFirstNumber / 72 * 2.54; | |
3351 } else if (strUnit == "pt" || strUnit == "points") { | |
3352 dResult = dFirstNumber; | |
3353 } else if (strUnit == "mp" || strUnit == "millipoints") { | |
3354 dResult = dFirstNumber * 1000; | |
3355 } else { | |
3356 dResult = dFirstNumber / 72; | |
3357 } | |
3358 } else if (strFirstUnit == "mp" || strFirstUnit == "millipoints") { | |
3359 if (strUnit == "mm" || strUnit == "millimeters") { | |
3360 dResult = dFirstNumber / 72000 * 25.4; | |
3361 } else if (strUnit == "cm" || strUnit == "centimeters") { | |
3362 dResult = dFirstNumber / 72000 * 2.54; | |
3363 } else if (strUnit == "pt" || strUnit == "points") { | |
3364 dResult = dFirstNumber / 1000; | |
3365 } else if (strUnit == "mp" || strUnit == "millipoints") { | |
3366 dResult = dFirstNumber; | |
3367 } else { | |
3368 dResult = dFirstNumber / 72000; | |
3369 } | |
3370 } | |
3371 FXJSE_Value_SetDouble(args.GetReturnValue(), dResult); | |
3372 } else { | |
3373 FXJSE_Value_SetInteger(args.GetReturnValue(), 0); | |
3374 } | |
3375 } | |
3376 } else { | |
3377 ToJSContext(pThis, nullptr) | 3240 ToJSContext(pThis, nullptr) |
3378 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"UnitValue"); | 3241 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"UnitValue"); |
| 3242 return; |
3379 } | 3243 } |
| 3244 |
| 3245 std::unique_ptr<CFXJSE_Value> unitspanValue = GetSimpleValue(pThis, args, 0); |
| 3246 if (FXJSE_Value_IsNull(unitspanValue.get())) { |
| 3247 FXJSE_Value_SetNull(args.GetReturnValue()); |
| 3248 return; |
| 3249 } |
| 3250 |
| 3251 CFX_ByteString unitspanString; |
| 3252 ValueToUTF8String(unitspanValue.get(), unitspanString); |
| 3253 const FX_CHAR* pData = unitspanString.c_str(); |
| 3254 if (!pData) { |
| 3255 FXJSE_Value_SetInteger(args.GetReturnValue(), 0); |
| 3256 return; |
| 3257 } |
| 3258 |
| 3259 int32_t u = 0; |
| 3260 while (IsWhitespace(pData[u])) |
| 3261 ++u; |
| 3262 |
| 3263 while (u < unitspanString.GetLength()) { |
| 3264 if ((pData[u] > '9' || pData[u] < '0') && pData[u] != '.' && |
| 3265 pData[u] != '-') { |
| 3266 break; |
| 3267 } |
| 3268 ++u; |
| 3269 } |
| 3270 |
| 3271 FX_CHAR* pTemp = nullptr; |
| 3272 FX_DOUBLE dFirstNumber = strtod(pData, &pTemp); |
| 3273 while (IsWhitespace(pData[u])) |
| 3274 ++u; |
| 3275 |
| 3276 int32_t uLen = unitspanString.GetLength(); |
| 3277 CFX_ByteString strFirstUnit; |
| 3278 while (u < uLen) { |
| 3279 if (pData[u] == ' ') |
| 3280 break; |
| 3281 |
| 3282 strFirstUnit += pData[u]; |
| 3283 ++u; |
| 3284 } |
| 3285 strFirstUnit.MakeLower(); |
| 3286 |
| 3287 CFX_ByteString strUnit; |
| 3288 if (argc > 1) { |
| 3289 std::unique_ptr<CFXJSE_Value> unitValue = GetSimpleValue(pThis, args, 1); |
| 3290 CFX_ByteString unitTempString; |
| 3291 ValueToUTF8String(unitValue.get(), unitTempString); |
| 3292 const FX_CHAR* pChar = unitTempString.c_str(); |
| 3293 int32_t uVal = 0; |
| 3294 while (IsWhitespace(pChar[uVal])) |
| 3295 ++uVal; |
| 3296 |
| 3297 while (uVal < unitTempString.GetLength()) { |
| 3298 if ((pChar[uVal] > '9' || pChar[uVal] < '0') && pChar[uVal] != '.') { |
| 3299 break; |
| 3300 } |
| 3301 ++uVal; |
| 3302 } |
| 3303 while (IsWhitespace(pChar[uVal])) |
| 3304 ++uVal; |
| 3305 |
| 3306 int32_t uValLen = unitTempString.GetLength(); |
| 3307 while (uVal < uValLen) { |
| 3308 if (pChar[uVal] == ' ') |
| 3309 break; |
| 3310 |
| 3311 strUnit += pChar[uVal]; |
| 3312 ++uVal; |
| 3313 } |
| 3314 strUnit.MakeLower(); |
| 3315 } else { |
| 3316 strUnit = strFirstUnit; |
| 3317 } |
| 3318 |
| 3319 FX_DOUBLE dResult = 0; |
| 3320 if (strFirstUnit == "in" || strFirstUnit == "inches") { |
| 3321 if (strUnit == "mm" || strUnit == "millimeters") |
| 3322 dResult = dFirstNumber * 25.4; |
| 3323 else if (strUnit == "cm" || strUnit == "centimeters") |
| 3324 dResult = dFirstNumber * 2.54; |
| 3325 else if (strUnit == "pt" || strUnit == "points") |
| 3326 dResult = dFirstNumber / 72; |
| 3327 else if (strUnit == "mp" || strUnit == "millipoints") |
| 3328 dResult = dFirstNumber / 72000; |
| 3329 else |
| 3330 dResult = dFirstNumber; |
| 3331 } else if (strFirstUnit == "mm" || strFirstUnit == "millimeters") { |
| 3332 if (strUnit == "mm" || strUnit == "millimeters") |
| 3333 dResult = dFirstNumber; |
| 3334 else if (strUnit == "cm" || strUnit == "centimeters") |
| 3335 dResult = dFirstNumber / 10; |
| 3336 else if (strUnit == "pt" || strUnit == "points") |
| 3337 dResult = dFirstNumber / 25.4 / 72; |
| 3338 else if (strUnit == "mp" || strUnit == "millipoints") |
| 3339 dResult = dFirstNumber / 25.4 / 72000; |
| 3340 else |
| 3341 dResult = dFirstNumber / 25.4; |
| 3342 } else if (strFirstUnit == "cm" || strFirstUnit == "centimeters") { |
| 3343 if (strUnit == "mm" || strUnit == "millimeters") |
| 3344 dResult = dFirstNumber * 10; |
| 3345 else if (strUnit == "cm" || strUnit == "centimeters") |
| 3346 dResult = dFirstNumber; |
| 3347 else if (strUnit == "pt" || strUnit == "points") |
| 3348 dResult = dFirstNumber / 2.54 / 72; |
| 3349 else if (strUnit == "mp" || strUnit == "millipoints") |
| 3350 dResult = dFirstNumber / 2.54 / 72000; |
| 3351 else |
| 3352 dResult = dFirstNumber / 2.54; |
| 3353 } else if (strFirstUnit == "pt" || strFirstUnit == "points") { |
| 3354 if (strUnit == "mm" || strUnit == "millimeters") |
| 3355 dResult = dFirstNumber / 72 * 25.4; |
| 3356 else if (strUnit == "cm" || strUnit == "centimeters") |
| 3357 dResult = dFirstNumber / 72 * 2.54; |
| 3358 else if (strUnit == "pt" || strUnit == "points") |
| 3359 dResult = dFirstNumber; |
| 3360 else if (strUnit == "mp" || strUnit == "millipoints") |
| 3361 dResult = dFirstNumber * 1000; |
| 3362 else |
| 3363 dResult = dFirstNumber / 72; |
| 3364 } else if (strFirstUnit == "mp" || strFirstUnit == "millipoints") { |
| 3365 if (strUnit == "mm" || strUnit == "millimeters") |
| 3366 dResult = dFirstNumber / 72000 * 25.4; |
| 3367 else if (strUnit == "cm" || strUnit == "centimeters") |
| 3368 dResult = dFirstNumber / 72000 * 2.54; |
| 3369 else if (strUnit == "pt" || strUnit == "points") |
| 3370 dResult = dFirstNumber / 1000; |
| 3371 else if (strUnit == "mp" || strUnit == "millipoints") |
| 3372 dResult = dFirstNumber; |
| 3373 else |
| 3374 dResult = dFirstNumber / 72000; |
| 3375 } |
| 3376 FXJSE_Value_SetDouble(args.GetReturnValue(), dResult); |
3380 } | 3377 } |
3381 | 3378 |
3382 // static | 3379 // static |
3383 void CXFA_FM2JSContext::At(CFXJSE_Value* pThis, | 3380 void CXFA_FM2JSContext::At(CFXJSE_Value* pThis, |
3384 const CFX_ByteStringC& szFuncName, | 3381 const CFX_ByteStringC& szFuncName, |
3385 CFXJSE_Arguments& args) { | 3382 CFXJSE_Arguments& args) { |
3386 if (args.GetLength() == 2) { | 3383 if (args.GetLength() != 2) { |
3387 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); | |
3388 std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1); | |
3389 if (ValueIsNull(pThis, argOne.get()) || ValueIsNull(pThis, argTwo.get())) { | |
3390 FXJSE_Value_SetNull(args.GetReturnValue()); | |
3391 } else { | |
3392 CFX_ByteString stringTwo; | |
3393 ValueToUTF8String(argTwo.get(), stringTwo); | |
3394 if (stringTwo.IsEmpty()) { | |
3395 FXJSE_Value_SetInteger(args.GetReturnValue(), 1); | |
3396 } else { | |
3397 CFX_ByteString stringOne; | |
3398 ValueToUTF8String(argOne.get(), stringOne); | |
3399 FX_STRSIZE iPosition = stringOne.Find(stringTwo.AsStringC()); | |
3400 FXJSE_Value_SetInteger(args.GetReturnValue(), iPosition + 1); | |
3401 } | |
3402 } | |
3403 } else { | |
3404 ToJSContext(pThis, nullptr) | 3384 ToJSContext(pThis, nullptr) |
3405 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"At"); | 3385 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"At"); |
| 3386 return; |
3406 } | 3387 } |
| 3388 |
| 3389 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); |
| 3390 std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1); |
| 3391 if (ValueIsNull(pThis, argOne.get()) || ValueIsNull(pThis, argTwo.get())) { |
| 3392 FXJSE_Value_SetNull(args.GetReturnValue()); |
| 3393 return; |
| 3394 } |
| 3395 |
| 3396 CFX_ByteString stringTwo; |
| 3397 ValueToUTF8String(argTwo.get(), stringTwo); |
| 3398 if (stringTwo.IsEmpty()) { |
| 3399 FXJSE_Value_SetInteger(args.GetReturnValue(), 1); |
| 3400 return; |
| 3401 } |
| 3402 |
| 3403 CFX_ByteString stringOne; |
| 3404 ValueToUTF8String(argOne.get(), stringOne); |
| 3405 FX_STRSIZE iPosition = stringOne.Find(stringTwo.AsStringC()); |
| 3406 FXJSE_Value_SetInteger(args.GetReturnValue(), iPosition + 1); |
3407 } | 3407 } |
3408 | 3408 |
3409 // static | 3409 // static |
3410 void CXFA_FM2JSContext::Concat(CFXJSE_Value* pThis, | 3410 void CXFA_FM2JSContext::Concat(CFXJSE_Value* pThis, |
3411 const CFX_ByteStringC& szFuncName, | 3411 const CFX_ByteStringC& szFuncName, |
3412 CFXJSE_Arguments& args) { | 3412 CFXJSE_Arguments& args) { |
3413 int32_t argc = args.GetLength(); | 3413 int32_t argc = args.GetLength(); |
3414 if (argc > 0) { | 3414 if (argc < 1) { |
3415 CFX_ByteString resultString; | |
3416 FX_BOOL bAllNull = TRUE; | |
3417 | |
3418 for (int32_t i = 0; i < argc; i++) { | |
3419 std::unique_ptr<CFXJSE_Value> value = GetSimpleValue(pThis, args, i); | |
3420 if (!ValueIsNull(pThis, value.get())) { | |
3421 CFX_ByteString valueStr; | |
3422 ValueToUTF8String(value.get(), valueStr); | |
3423 resultString += valueStr; | |
3424 bAllNull = FALSE; | |
3425 } | |
3426 } | |
3427 | |
3428 if (bAllNull) { | |
3429 FXJSE_Value_SetNull(args.GetReturnValue()); | |
3430 } else { | |
3431 FXJSE_Value_SetUTF8String(args.GetReturnValue(), | |
3432 resultString.AsStringC()); | |
3433 } | |
3434 } else { | |
3435 ToJSContext(pThis, nullptr) | 3415 ToJSContext(pThis, nullptr) |
3436 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Concat"); | 3416 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Concat"); |
| 3417 return; |
3437 } | 3418 } |
| 3419 |
| 3420 CFX_ByteString resultString; |
| 3421 FX_BOOL bAllNull = TRUE; |
| 3422 for (int32_t i = 0; i < argc; i++) { |
| 3423 std::unique_ptr<CFXJSE_Value> value = GetSimpleValue(pThis, args, i); |
| 3424 if (ValueIsNull(pThis, value.get())) |
| 3425 continue; |
| 3426 |
| 3427 bAllNull = FALSE; |
| 3428 |
| 3429 CFX_ByteString valueStr; |
| 3430 ValueToUTF8String(value.get(), valueStr); |
| 3431 resultString += valueStr; |
| 3432 } |
| 3433 |
| 3434 if (bAllNull) { |
| 3435 FXJSE_Value_SetNull(args.GetReturnValue()); |
| 3436 return; |
| 3437 } |
| 3438 |
| 3439 FXJSE_Value_SetUTF8String(args.GetReturnValue(), resultString.AsStringC()); |
3438 } | 3440 } |
3439 | 3441 |
3440 // static | 3442 // static |
3441 void CXFA_FM2JSContext::Decode(CFXJSE_Value* pThis, | 3443 void CXFA_FM2JSContext::Decode(CFXJSE_Value* pThis, |
3442 const CFX_ByteStringC& szFuncName, | 3444 const CFX_ByteStringC& szFuncName, |
3443 CFXJSE_Arguments& args) { | 3445 CFXJSE_Arguments& args) { |
3444 int32_t argc = args.GetLength(); | 3446 int32_t argc = args.GetLength(); |
| 3447 if (argc < 1 || argc > 2) { |
| 3448 ToJSContext(pThis, nullptr) |
| 3449 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Decode"); |
| 3450 return; |
| 3451 } |
| 3452 |
3445 if (argc == 1) { | 3453 if (argc == 1) { |
3446 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); | 3454 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); |
3447 if (ValueIsNull(pThis, argOne.get())) { | 3455 if (ValueIsNull(pThis, argOne.get())) { |
3448 FXJSE_Value_SetNull(args.GetReturnValue()); | 3456 FXJSE_Value_SetNull(args.GetReturnValue()); |
3449 } else { | 3457 return; |
3450 CFX_ByteString toDecodeString; | |
3451 ValueToUTF8String(argOne.get(), toDecodeString); | |
3452 CFX_ByteTextBuf resultBuf; | |
3453 DecodeURL(toDecodeString.AsStringC(), resultBuf); | |
3454 FXJSE_Value_SetUTF8String(args.GetReturnValue(), resultBuf.AsStringC()); | |
3455 } | 3458 } |
3456 } else if (argc == 2) { | 3459 |
3457 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); | 3460 CFX_ByteString toDecodeString; |
3458 std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1); | 3461 ValueToUTF8String(argOne.get(), toDecodeString); |
3459 if (ValueIsNull(pThis, argOne.get()) || ValueIsNull(pThis, argTwo.get())) { | 3462 CFX_ByteTextBuf resultBuf; |
3460 FXJSE_Value_SetNull(args.GetReturnValue()); | 3463 DecodeURL(toDecodeString.AsStringC(), resultBuf); |
3461 } else { | 3464 FXJSE_Value_SetUTF8String(args.GetReturnValue(), resultBuf.AsStringC()); |
3462 CFX_ByteString toDecodeString; | 3465 return; |
3463 ValueToUTF8String(argOne.get(), toDecodeString); | |
3464 CFX_ByteString identifyString; | |
3465 ValueToUTF8String(argTwo.get(), identifyString); | |
3466 CFX_ByteTextBuf resultBuf; | |
3467 if (identifyString.EqualNoCase("html")) { | |
3468 DecodeHTML(toDecodeString.AsStringC(), resultBuf); | |
3469 } else if (identifyString.EqualNoCase("xml")) { | |
3470 DecodeXML(toDecodeString.AsStringC(), resultBuf); | |
3471 } else { | |
3472 DecodeURL(toDecodeString.AsStringC(), resultBuf); | |
3473 } | |
3474 FXJSE_Value_SetUTF8String(args.GetReturnValue(), resultBuf.AsStringC()); | |
3475 } | |
3476 } else { | |
3477 ToJSContext(pThis, nullptr) | |
3478 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Decode"); | |
3479 } | 3466 } |
| 3467 |
| 3468 std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); |
| 3469 std::unique_ptr<CFXJSE_Value> argTwo = GetSimpleValue(pThis, args, 1); |
| 3470 if (ValueIsNull(pThis, argOne.get()) || ValueIsNull(pThis, argTwo.get())) { |
| 3471 FXJSE_Value_SetNull(args.GetReturnValue()); |
| 3472 return; |
| 3473 } |
| 3474 |
| 3475 CFX_ByteString toDecodeString; |
| 3476 ValueToUTF8String(argOne.get(), toDecodeString); |
| 3477 |
| 3478 CFX_ByteString identifyString; |
| 3479 ValueToUTF8String(argTwo.get(), identifyString); |
| 3480 |
| 3481 CFX_ByteTextBuf resultBuf; |
| 3482 if (identifyString.EqualNoCase("html")) |
| 3483 DecodeHTML(toDecodeString.AsStringC(), resultBuf); |
| 3484 else if (identifyString.EqualNoCase("xml")) |
| 3485 DecodeXML(toDecodeString.AsStringC(), resultBuf); |
| 3486 else |
| 3487 DecodeURL(toDecodeString.AsStringC(), resultBuf); |
| 3488 |
| 3489 FXJSE_Value_SetUTF8String(args.GetReturnValue(), resultBuf.AsStringC()); |
3480 } | 3490 } |
3481 | 3491 |
3482 // static | 3492 // static |
3483 void CXFA_FM2JSContext::DecodeURL(const CFX_ByteStringC& szURLString, | 3493 void CXFA_FM2JSContext::DecodeURL(const CFX_ByteStringC& szURLString, |
3484 CFX_ByteTextBuf& szResultString) { | 3494 CFX_ByteTextBuf& szResultString) { |
3485 CFX_WideString wsURLString = CFX_WideString::FromUTF8(szURLString); | 3495 CFX_WideString wsURLString = CFX_WideString::FromUTF8(szURLString); |
3486 const FX_WCHAR* pData = wsURLString.c_str(); | 3496 const FX_WCHAR* pData = wsURLString.c_str(); |
3487 int32_t iLen = wsURLString.GetLength(); | |
3488 int32_t i = 0; | 3497 int32_t i = 0; |
3489 FX_WCHAR ch = 0; | |
3490 FX_WCHAR chTemp = 0; | |
3491 CFX_WideTextBuf wsResultBuf; | 3498 CFX_WideTextBuf wsResultBuf; |
3492 while (i < iLen) { | 3499 while (i < wsURLString.GetLength()) { |
3493 ch = pData[i]; | 3500 FX_WCHAR ch = pData[i]; |
3494 if ('%' == ch) { | 3501 if ('%' != ch) { |
3495 chTemp = 0; | 3502 wsResultBuf.AppendChar(ch); |
3496 int32_t iCount = 0; | 3503 ++i; |
3497 while (iCount < 2) { | 3504 continue; |
3498 ++i; | 3505 } |
3499 ch = pData[i]; | 3506 |
3500 if (ch <= '9' && ch >= '0') { | 3507 FX_WCHAR chTemp = 0; |
3501 if (!iCount) { | 3508 int32_t iCount = 0; |
3502 chTemp += (ch - '0') * 16; | 3509 while (iCount < 2) { |
3503 } else { | 3510 ++i; |
3504 chTemp += (ch - '0'); | 3511 ch = pData[i]; |
3505 } | 3512 if (ch <= '9' && ch >= '0') { |
3506 } else { | 3513 // TODO(dsinclair): Premultiply and add rather then scale. |
3507 if (ch <= 'F' && ch >= 'A') { | 3514 chTemp += (ch - '0') * (!iCount ? 16 : 1); |
3508 if (!iCount) { | 3515 } else if (ch <= 'F' && ch >= 'A') { |
3509 chTemp += (ch - 'A' + 10) * 16; | 3516 chTemp += (ch - 'A' + 10) * (!iCount ? 16 : 1); |
3510 } else { | 3517 } else if (ch <= 'f' && ch >= 'a') { |
3511 chTemp += (ch - 'A' + 10); | 3518 chTemp += (ch - 'a' + 10) * (!iCount ? 16 : 1); |
3512 } | 3519 } else { |
3513 } else if (ch <= 'f' && ch >= 'a') { | 3520 wsResultBuf.Clear(); |
3514 if (!iCount) { | 3521 return; |
3515 chTemp += (ch - 'a' + 10) * 16; | |
3516 } else { | |
3517 chTemp += (ch - 'a' + 10); | |
3518 } | |
3519 } else { | |
3520 wsResultBuf.Clear(); | |
3521 return; | |
3522 } | |
3523 } | |
3524 ++iCount; | |
3525 } | 3522 } |
3526 wsResultBuf.AppendChar(chTemp); | 3523 ++iCount; |
3527 } else { | |
3528 wsResultBuf.AppendChar(ch); | |
3529 } | 3524 } |
| 3525 wsResultBuf.AppendChar(chTemp); |
3530 ++i; | 3526 ++i; |
3531 } | 3527 } |
3532 wsResultBuf.AppendChar(0); | 3528 wsResultBuf.AppendChar(0); |
| 3529 |
3533 szResultString.Clear(); | 3530 szResultString.Clear(); |
3534 szResultString << FX_UTF8Encode(wsResultBuf.GetBuffer(), | 3531 szResultString << FX_UTF8Encode(wsResultBuf.GetBuffer(), |
3535 wsResultBuf.GetLength()) | 3532 wsResultBuf.GetLength()) |
3536 .AsStringC(); | 3533 .AsStringC(); |
3537 } | 3534 } |
3538 | 3535 |
3539 // static | 3536 // static |
3540 void CXFA_FM2JSContext::DecodeHTML(const CFX_ByteStringC& szHTMLString, | 3537 void CXFA_FM2JSContext::DecodeHTML(const CFX_ByteStringC& szHTMLString, |
3541 CFX_ByteTextBuf& szResultString) { | 3538 CFX_ByteTextBuf& szResultString) { |
3542 CFX_WideString wsHTMLString = CFX_WideString::FromUTF8(szHTMLString); | 3539 CFX_WideString wsHTMLString = CFX_WideString::FromUTF8(szHTMLString); |
3543 FX_WCHAR strString[9]; | 3540 FX_WCHAR strString[9]; |
3544 int32_t iStrIndex = 0; | 3541 int32_t iStrIndex = 0; |
3545 int32_t iLen = wsHTMLString.GetLength(); | 3542 int32_t iLen = wsHTMLString.GetLength(); |
3546 int32_t i = 0; | 3543 int32_t i = 0; |
3547 int32_t iCode = 0; | 3544 int32_t iCode = 0; |
3548 FX_WCHAR ch = 0; | |
3549 const FX_WCHAR* pData = wsHTMLString.c_str(); | 3545 const FX_WCHAR* pData = wsHTMLString.c_str(); |
3550 CFX_WideTextBuf wsResultBuf; | 3546 CFX_WideTextBuf wsResultBuf; |
3551 while (i < iLen) { | 3547 while (i < iLen) { |
3552 ch = pData[i]; | 3548 FX_WCHAR ch = pData[i]; |
3553 if (ch == '&') { | 3549 if (ch != '&') { |
3554 ++i; | |
3555 ch = pData[i]; | |
3556 if (ch == '#') { | |
3557 ++i; | |
3558 ch = pData[i]; | |
3559 if (ch == 'x' || ch == 'X') { | |
3560 ++i; | |
3561 ch = pData[i]; | |
3562 if ((ch >= '0' && ch <= '9') || (ch <= 'f' && ch >= 'a') || | |
3563 (ch <= 'F' && ch >= 'A')) { | |
3564 while (ch != ';' && i < iLen) { | |
3565 if (ch >= '0' && ch <= '9') { | |
3566 iCode += ch - '0'; | |
3567 } else if (ch <= 'f' && ch >= 'a') { | |
3568 iCode += ch - 'a' + 10; | |
3569 } else if (ch <= 'F' && ch >= 'A') { | |
3570 iCode += ch - 'A' + 10; | |
3571 } else { | |
3572 wsResultBuf.Clear(); | |
3573 return; | |
3574 } | |
3575 ++i; | |
3576 iCode *= 16; | |
3577 ch = pData[i]; | |
3578 } | |
3579 iCode /= 16; | |
3580 } | |
3581 } else { | |
3582 wsResultBuf.Clear(); | |
3583 return; | |
3584 } | |
3585 } else { | |
3586 while (ch != ';' && i < iLen) { | |
3587 strString[iStrIndex++] = ch; | |
3588 ++i; | |
3589 ch = pData[i]; | |
3590 } | |
3591 strString[iStrIndex] = 0; | |
3592 } | |
3593 } else { | |
3594 wsResultBuf.AppendChar(ch); | 3550 wsResultBuf.AppendChar(ch); |
3595 ++i; | 3551 ++i; |
3596 continue; | 3552 continue; |
3597 } | 3553 } |
| 3554 |
| 3555 ++i; |
| 3556 ch = pData[i]; |
| 3557 if (ch == '#') { |
| 3558 ++i; |
| 3559 ch = pData[i]; |
| 3560 if (ch != 'x' && ch != 'X') { |
| 3561 wsResultBuf.Clear(); |
| 3562 return; |
| 3563 } |
| 3564 |
| 3565 ++i; |
| 3566 ch = pData[i]; |
| 3567 if ((ch >= '0' && ch <= '9') || (ch <= 'f' && ch >= 'a') || |
| 3568 (ch <= 'F' && ch >= 'A')) { |
| 3569 while (ch != ';' && i < iLen) { |
| 3570 if (ch >= '0' && ch <= '9') { |
| 3571 iCode += ch - '0'; |
| 3572 } else if (ch <= 'f' && ch >= 'a') { |
| 3573 iCode += ch - 'a' + 10; |
| 3574 } else if (ch <= 'F' && ch >= 'A') { |
| 3575 iCode += ch - 'A' + 10; |
| 3576 } else { |
| 3577 wsResultBuf.Clear(); |
| 3578 return; |
| 3579 } |
| 3580 ++i; |
| 3581 // TODO(dsinclair): Postmultiply seems wrong, start at zero |
| 3582 // and pre-multiply then can remove the post divide. |
| 3583 iCode *= 16; |
| 3584 ch = pData[i]; |
| 3585 } |
| 3586 iCode /= 16; |
| 3587 } |
| 3588 } else { |
| 3589 while (ch != ';' && i < iLen) { |
| 3590 strString[iStrIndex++] = ch; |
| 3591 ++i; |
| 3592 ch = pData[i]; |
| 3593 } |
| 3594 strString[iStrIndex] = 0; |
| 3595 } |
3598 uint32_t iData = 0; | 3596 uint32_t iData = 0; |
3599 if (HTMLSTR2Code(strString, iData)) { | 3597 if (HTMLSTR2Code(strString, iData)) { |
3600 wsResultBuf.AppendChar((FX_WCHAR)iData); | 3598 wsResultBuf.AppendChar((FX_WCHAR)iData); |
3601 } else { | 3599 } else { |
3602 wsResultBuf.AppendChar(iCode); | 3600 wsResultBuf.AppendChar(iCode); |
3603 } | 3601 } |
3604 iStrIndex = 0; | 3602 iStrIndex = 0; |
3605 strString[iStrIndex] = 0; | 3603 strString[iStrIndex] = 0; |
3606 ++i; | 3604 ++i; |
3607 } | 3605 } |
3608 wsResultBuf.AppendChar(0); | 3606 wsResultBuf.AppendChar(0); |
| 3607 |
3609 szResultString.Clear(); | 3608 szResultString.Clear(); |
3610 szResultString << FX_UTF8Encode(wsResultBuf.GetBuffer(), | 3609 szResultString << FX_UTF8Encode(wsResultBuf.GetBuffer(), |
3611 wsResultBuf.GetLength()) | 3610 wsResultBuf.GetLength()) |
3612 .AsStringC(); | 3611 .AsStringC(); |
3613 } | 3612 } |
3614 | 3613 |
3615 // static | 3614 // static |
3616 void CXFA_FM2JSContext::DecodeXML(const CFX_ByteStringC& szXMLString, | 3615 void CXFA_FM2JSContext::DecodeXML(const CFX_ByteStringC& szXMLString, |
3617 CFX_ByteTextBuf& szResultString) { | 3616 CFX_ByteTextBuf& szResultString) { |
3618 CFX_WideString wsXMLString = CFX_WideString::FromUTF8(szXMLString); | 3617 CFX_WideString wsXMLString = CFX_WideString::FromUTF8(szXMLString); |
3619 FX_WCHAR strString[9]; | 3618 FX_WCHAR strString[9]; |
3620 int32_t iStrIndex = 0; | 3619 int32_t iStrIndex = 0; |
3621 int32_t iLen = wsXMLString.GetLength(); | 3620 int32_t iLen = wsXMLString.GetLength(); |
3622 int32_t i = 0; | 3621 int32_t i = 0; |
3623 int32_t iCode = 0; | 3622 int32_t iCode = 0; |
3624 FX_WCHAR ch = 0; | 3623 FX_WCHAR ch = 0; |
3625 const FX_WCHAR* pData = wsXMLString.c_str(); | 3624 const FX_WCHAR* pData = wsXMLString.c_str(); |
3626 CFX_WideTextBuf wsXMLBuf; | 3625 CFX_WideTextBuf wsXMLBuf; |
3627 while (i < iLen) { | 3626 while (i < iLen) { |
3628 ch = pData[i]; | 3627 ch = pData[i]; |
3629 if (ch == '&') { | 3628 if (ch != '&') { |
3630 ++i; | |
3631 ch = pData[i]; | |
3632 if (ch == '#') { | |
3633 ++i; | |
3634 ch = pData[i]; | |
3635 if (ch == 'x' || ch == 'X') { | |
3636 ++i; | |
3637 ch = pData[i]; | |
3638 if ((ch >= '0' && ch <= '9') || (ch <= 'f' && ch >= 'a') || | |
3639 (ch <= 'F' && ch >= 'A')) { | |
3640 while (ch != ';') { | |
3641 if (ch >= '0' && ch <= '9') { | |
3642 iCode += ch - '0'; | |
3643 } else if (ch <= 'f' && ch >= 'a') { | |
3644 iCode += ch - 'a' + 10; | |
3645 } else if (ch <= 'F' && ch >= 'A') { | |
3646 iCode += ch - 'A' + 10; | |
3647 } else { | |
3648 wsXMLBuf.Clear(); | |
3649 return; | |
3650 } | |
3651 ++i; | |
3652 iCode *= 16; | |
3653 ch = pData[i]; | |
3654 } | |
3655 iCode /= 16; | |
3656 } | |
3657 } else { | |
3658 wsXMLBuf.Clear(); | |
3659 return; | |
3660 } | |
3661 } else { | |
3662 while (ch != ';' && i < iLen) { | |
3663 strString[iStrIndex++] = ch; | |
3664 ++i; | |
3665 ch = pData[i]; | |
3666 } | |
3667 strString[iStrIndex] = 0; | |
3668 } | |
3669 } else { | |
3670 wsXMLBuf.AppendChar(ch); | 3629 wsXMLBuf.AppendChar(ch); |
3671 ++i; | 3630 ++i; |
3672 continue; | 3631 continue; |
3673 } | 3632 } |
| 3633 |
| 3634 // TODO(dsinclair): This is very similar to DecodeHTML, can they be |
| 3635 // combined? |
| 3636 ++i; |
| 3637 ch = pData[i]; |
| 3638 if (ch == '#') { |
| 3639 ++i; |
| 3640 ch = pData[i]; |
| 3641 if (ch != 'x' && ch != 'X') { |
| 3642 wsXMLBuf.Clear(); |
| 3643 return; |
| 3644 } |
| 3645 |
| 3646 ++i; |
| 3647 ch = pData[i]; |
| 3648 if ((ch >= '0' && ch <= '9') || (ch <= 'f' && ch >= 'a') || |
| 3649 (ch <= 'F' && ch >= 'A')) { |
| 3650 while (ch != ';') { |
| 3651 if (ch >= '0' && ch <= '9') { |
| 3652 iCode += ch - '0'; |
| 3653 } else if (ch <= 'f' && ch >= 'a') { |
| 3654 iCode += ch - 'a' + 10; |
| 3655 } else if (ch <= 'F' && ch >= 'A') { |
| 3656 iCode += ch - 'A' + 10; |
| 3657 } else { |
| 3658 wsXMLBuf.Clear(); |
| 3659 return; |
| 3660 } |
| 3661 ++i; |
| 3662 iCode *= 16; |
| 3663 ch = pData[i]; |
| 3664 } |
| 3665 iCode /= 16; |
| 3666 } |
| 3667 } else { |
| 3668 while (ch != ';' && i < iLen) { |
| 3669 strString[iStrIndex++] = ch; |
| 3670 ++i; |
| 3671 ch = pData[i]; |
| 3672 } |
| 3673 strString[iStrIndex] = 0; |
| 3674 } |
| 3675 |
3674 const FX_WCHAR* const strName[] = {L"quot", L"amp", L"apos", L"lt", L"gt"}; | 3676 const FX_WCHAR* const strName[] = {L"quot", L"amp", L"apos", L"lt", L"gt"}; |
3675 int32_t iIndex = 0; | 3677 int32_t iIndex = 0; |
3676 while (iIndex < 5) { | 3678 while (iIndex < 5) { |
3677 if (FXSYS_memcmp(strString, strName[iIndex], | 3679 if (FXSYS_memcmp(strString, strName[iIndex], |
3678 FXSYS_wcslen(strName[iIndex])) == 0) { | 3680 FXSYS_wcslen(strName[iIndex])) == 0) { |
3679 break; | 3681 break; |
3680 } | 3682 } |
3681 ++iIndex; | 3683 ++iIndex; |
3682 } | 3684 } |
3683 switch (iIndex) { | 3685 switch (iIndex) { |
(...skipping 15 matching lines...) Expand all Loading... |
3699 default: | 3701 default: |
3700 wsXMLBuf.AppendChar(iCode); | 3702 wsXMLBuf.AppendChar(iCode); |
3701 break; | 3703 break; |
3702 } | 3704 } |
3703 iStrIndex = 0; | 3705 iStrIndex = 0; |
3704 strString[iStrIndex] = 0; | 3706 strString[iStrIndex] = 0; |
3705 ++i; | 3707 ++i; |
3706 iCode = 0; | 3708 iCode = 0; |
3707 } | 3709 } |
3708 wsXMLBuf.AppendChar(0); | 3710 wsXMLBuf.AppendChar(0); |
| 3711 |
3709 szResultString.Clear(); | 3712 szResultString.Clear(); |
3710 szResultString << FX_UTF8Encode(wsXMLBuf.GetBuffer(), wsXMLBuf.GetLength()) | 3713 szResultString << FX_UTF8Encode(wsXMLBuf.GetBuffer(), wsXMLBuf.GetLength()) |
3711 .AsStringC(); | 3714 .AsStringC(); |
3712 } | 3715 } |
3713 | 3716 |
3714 // static | 3717 // static |
3715 void CXFA_FM2JSContext::Encode(CFXJSE_Value* pThis, | 3718 void CXFA_FM2JSContext::Encode(CFXJSE_Value* pThis, |
3716 const CFX_ByteStringC& szFuncName, | 3719 const CFX_ByteStringC& szFuncName, |
3717 CFXJSE_Arguments& args) { | 3720 CFXJSE_Arguments& args) { |
3718 int32_t argc = args.GetLength(); | 3721 int32_t argc = args.GetLength(); |
(...skipping 2981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6700 CFX_WideString wsFormat; | 6703 CFX_WideString wsFormat; |
6701 pAppProvider->LoadString(iStringID, wsFormat); | 6704 pAppProvider->LoadString(iStringID, wsFormat); |
6702 CFX_WideString wsMessage; | 6705 CFX_WideString wsMessage; |
6703 va_list arg_ptr; | 6706 va_list arg_ptr; |
6704 va_start(arg_ptr, iStringID); | 6707 va_start(arg_ptr, iStringID); |
6705 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); | 6708 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); |
6706 va_end(arg_ptr); | 6709 va_end(arg_ptr); |
6707 FXJSE_ThrowMessage( | 6710 FXJSE_ThrowMessage( |
6708 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); | 6711 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); |
6709 } | 6712 } |
OLD | NEW |