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 FXJSE_Value_Set(args.GetReturnValue(), returnValue.get()); | |
3047 | |
Tom Sepez
2016/06/07 20:36:19
nit: blank line not really needed here. I'd put i
dsinclair
2016/06/07 20:51:48
Done.
| |
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()) || | |
Tom Sepez
2016/06/07 20:36:19
me not like the redundant calls to Is*() here. I
dsinclair
2016/06/07 20:51:48
This currently isn't great but until we move rgVal
| |
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())) { | |
Tom Sepez
2016/06/07 20:36:19
Is this just cut n' paste?
dsinclair
2016/06/07 20:51:48
I moved the early return up, out-dented and then f
| |
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); | |
Tom Sepez
2016/06/07 20:36:19
same here?
dsinclair
2016/06/07 20:51:48
ditto, early returns and cleanup.
| |
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 chTemp += (ch - '0') * (!iCount ? 16 : 1); |
Tom Sepez
2016/06/07 20:36:19
this is stupid. Premultiply icount by 16 and add
dsinclair
2016/06/07 20:51:48
Acknowledged.
| |
3507 if (ch <= 'F' && ch >= 'A') { | 3514 } else if (ch <= 'F' && ch >= 'A') { |
3508 if (!iCount) { | 3515 chTemp += (ch - 'A' + 10) * (!iCount ? 16 : 1); |
3509 chTemp += (ch - 'A' + 10) * 16; | 3516 } else if (ch <= 'f' && ch >= 'a') { |
3510 } else { | 3517 chTemp += (ch - 'a' + 10) * (!iCount ? 16 : 1); |
3511 chTemp += (ch - 'A' + 10); | 3518 } else { |
3512 } | 3519 wsResultBuf.Clear(); |
3513 } else if (ch <= 'f' && ch >= 'a') { | 3520 return; |
3514 if (!iCount) { | |
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 } | 3521 } |
3526 wsResultBuf.AppendChar(chTemp); | 3522 ++iCount; |
3527 } else { | |
3528 wsResultBuf.AppendChar(ch); | |
3529 } | 3523 } |
3524 wsResultBuf.AppendChar(chTemp); | |
3530 ++i; | 3525 ++i; |
3531 } | 3526 } |
3532 wsResultBuf.AppendChar(0); | 3527 wsResultBuf.AppendChar(0); |
3528 | |
3533 szResultString.Clear(); | 3529 szResultString.Clear(); |
3534 szResultString << FX_UTF8Encode(wsResultBuf.GetBuffer(), | 3530 szResultString << FX_UTF8Encode(wsResultBuf.GetBuffer(), |
3535 wsResultBuf.GetLength()) | 3531 wsResultBuf.GetLength()) |
3536 .AsStringC(); | 3532 .AsStringC(); |
3537 } | 3533 } |
3538 | 3534 |
3539 // static | 3535 // static |
3540 void CXFA_FM2JSContext::DecodeHTML(const CFX_ByteStringC& szHTMLString, | 3536 void CXFA_FM2JSContext::DecodeHTML(const CFX_ByteStringC& szHTMLString, |
3541 CFX_ByteTextBuf& szResultString) { | 3537 CFX_ByteTextBuf& szResultString) { |
3542 CFX_WideString wsHTMLString = CFX_WideString::FromUTF8(szHTMLString); | 3538 CFX_WideString wsHTMLString = CFX_WideString::FromUTF8(szHTMLString); |
3543 FX_WCHAR strString[9]; | 3539 FX_WCHAR strString[9]; |
3544 int32_t iStrIndex = 0; | 3540 int32_t iStrIndex = 0; |
3545 int32_t iLen = wsHTMLString.GetLength(); | 3541 int32_t iLen = wsHTMLString.GetLength(); |
3546 int32_t i = 0; | 3542 int32_t i = 0; |
3547 int32_t iCode = 0; | 3543 int32_t iCode = 0; |
3548 FX_WCHAR ch = 0; | |
3549 const FX_WCHAR* pData = wsHTMLString.c_str(); | 3544 const FX_WCHAR* pData = wsHTMLString.c_str(); |
3550 CFX_WideTextBuf wsResultBuf; | 3545 CFX_WideTextBuf wsResultBuf; |
3551 while (i < iLen) { | 3546 while (i < iLen) { |
3552 ch = pData[i]; | 3547 FX_WCHAR ch = pData[i]; |
3553 if (ch == '&') { | 3548 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); | 3549 wsResultBuf.AppendChar(ch); |
3595 ++i; | 3550 ++i; |
3596 continue; | 3551 continue; |
3597 } | 3552 } |
3553 | |
3554 ++i; | |
3555 ch = pData[i]; | |
3556 if (ch == '#') { | |
3557 ++i; | |
3558 ch = pData[i]; | |
3559 if (ch != 'x' && ch != 'X') { | |
3560 wsResultBuf.Clear(); | |
3561 return; | |
3562 } | |
3563 | |
3564 ++i; | |
3565 ch = pData[i]; | |
3566 if ((ch >= '0' && ch <= '9') || (ch <= 'f' && ch >= 'a') || | |
3567 (ch <= 'F' && ch >= 'A')) { | |
3568 while (ch != ';' && i < iLen) { | |
3569 if (ch >= '0' && ch <= '9') { | |
3570 iCode += ch - '0'; | |
3571 } else if (ch <= 'f' && ch >= 'a') { | |
3572 iCode += ch - 'a' + 10; | |
3573 } else if (ch <= 'F' && ch >= 'A') { | |
3574 iCode += ch - 'A' + 10; | |
3575 } else { | |
3576 wsResultBuf.Clear(); | |
3577 return; | |
3578 } | |
3579 ++i; | |
3580 iCode *= 16; | |
Tom Sepez
2016/06/07 20:36:19
Maybe as a follow-up when you consolidate these:
dsinclair
2016/06/07 20:51:48
Added todo.
| |
3581 ch = pData[i]; | |
3582 } | |
3583 iCode /= 16; | |
Tom Sepez
2016/06/07 20:36:20
then you wont' have to post-divide and can avoid o
dsinclair
2016/06/07 20:51:48
Acknowledged.
| |
3584 } | |
3585 } else { | |
3586 while (ch != ';' && i < iLen) { | |
3587 strString[iStrIndex++] = ch; | |
3588 ++i; | |
3589 ch = pData[i]; | |
3590 } | |
3591 strString[iStrIndex] = 0; | |
3592 } | |
3598 uint32_t iData = 0; | 3593 uint32_t iData = 0; |
3599 if (HTMLSTR2Code(strString, iData)) { | 3594 if (HTMLSTR2Code(strString, iData)) { |
3600 wsResultBuf.AppendChar((FX_WCHAR)iData); | 3595 wsResultBuf.AppendChar((FX_WCHAR)iData); |
3601 } else { | 3596 } else { |
3602 wsResultBuf.AppendChar(iCode); | 3597 wsResultBuf.AppendChar(iCode); |
3603 } | 3598 } |
3604 iStrIndex = 0; | 3599 iStrIndex = 0; |
3605 strString[iStrIndex] = 0; | 3600 strString[iStrIndex] = 0; |
3606 ++i; | 3601 ++i; |
3607 } | 3602 } |
3608 wsResultBuf.AppendChar(0); | 3603 wsResultBuf.AppendChar(0); |
3604 | |
3609 szResultString.Clear(); | 3605 szResultString.Clear(); |
3610 szResultString << FX_UTF8Encode(wsResultBuf.GetBuffer(), | 3606 szResultString << FX_UTF8Encode(wsResultBuf.GetBuffer(), |
3611 wsResultBuf.GetLength()) | 3607 wsResultBuf.GetLength()) |
3612 .AsStringC(); | 3608 .AsStringC(); |
3613 } | 3609 } |
3614 | 3610 |
3615 // static | 3611 // static |
3616 void CXFA_FM2JSContext::DecodeXML(const CFX_ByteStringC& szXMLString, | 3612 void CXFA_FM2JSContext::DecodeXML(const CFX_ByteStringC& szXMLString, |
3617 CFX_ByteTextBuf& szResultString) { | 3613 CFX_ByteTextBuf& szResultString) { |
3618 CFX_WideString wsXMLString = CFX_WideString::FromUTF8(szXMLString); | 3614 CFX_WideString wsXMLString = CFX_WideString::FromUTF8(szXMLString); |
3619 FX_WCHAR strString[9]; | 3615 FX_WCHAR strString[9]; |
3620 int32_t iStrIndex = 0; | 3616 int32_t iStrIndex = 0; |
3621 int32_t iLen = wsXMLString.GetLength(); | 3617 int32_t iLen = wsXMLString.GetLength(); |
3622 int32_t i = 0; | 3618 int32_t i = 0; |
3623 int32_t iCode = 0; | 3619 int32_t iCode = 0; |
3624 FX_WCHAR ch = 0; | 3620 FX_WCHAR ch = 0; |
3625 const FX_WCHAR* pData = wsXMLString.c_str(); | 3621 const FX_WCHAR* pData = wsXMLString.c_str(); |
3626 CFX_WideTextBuf wsXMLBuf; | 3622 CFX_WideTextBuf wsXMLBuf; |
3627 while (i < iLen) { | 3623 while (i < iLen) { |
3628 ch = pData[i]; | 3624 ch = pData[i]; |
3629 if (ch == '&') { | 3625 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); | 3626 wsXMLBuf.AppendChar(ch); |
3671 ++i; | 3627 ++i; |
3672 continue; | 3628 continue; |
3673 } | 3629 } |
3630 | |
3631 // TODO(dsinclair): This is very similar to DecodeHTML, can they be | |
3632 // combined? | |
3633 ++i; | |
3634 ch = pData[i]; | |
3635 if (ch == '#') { | |
3636 ++i; | |
3637 ch = pData[i]; | |
3638 if (ch != 'x' && ch != 'X') { | |
3639 wsXMLBuf.Clear(); | |
3640 return; | |
3641 } | |
3642 | |
3643 ++i; | |
3644 ch = pData[i]; | |
3645 if ((ch >= '0' && ch <= '9') || (ch <= 'f' && ch >= 'a') || | |
3646 (ch <= 'F' && ch >= 'A')) { | |
3647 while (ch != ';') { | |
3648 if (ch >= '0' && ch <= '9') { | |
3649 iCode += ch - '0'; | |
3650 } else if (ch <= 'f' && ch >= 'a') { | |
3651 iCode += ch - 'a' + 10; | |
3652 } else if (ch <= 'F' && ch >= 'A') { | |
3653 iCode += ch - 'A' + 10; | |
3654 } else { | |
3655 wsXMLBuf.Clear(); | |
3656 return; | |
3657 } | |
3658 ++i; | |
3659 iCode *= 16; | |
3660 ch = pData[i]; | |
3661 } | |
3662 iCode /= 16; | |
3663 } | |
3664 } else { | |
3665 while (ch != ';' && i < iLen) { | |
3666 strString[iStrIndex++] = ch; | |
3667 ++i; | |
3668 ch = pData[i]; | |
3669 } | |
3670 strString[iStrIndex] = 0; | |
3671 } | |
3672 | |
3674 const FX_WCHAR* const strName[] = {L"quot", L"amp", L"apos", L"lt", L"gt"}; | 3673 const FX_WCHAR* const strName[] = {L"quot", L"amp", L"apos", L"lt", L"gt"}; |
3675 int32_t iIndex = 0; | 3674 int32_t iIndex = 0; |
3676 while (iIndex < 5) { | 3675 while (iIndex < 5) { |
3677 if (FXSYS_memcmp(strString, strName[iIndex], | 3676 if (FXSYS_memcmp(strString, strName[iIndex], |
3678 FXSYS_wcslen(strName[iIndex])) == 0) { | 3677 FXSYS_wcslen(strName[iIndex])) == 0) { |
3679 break; | 3678 break; |
3680 } | 3679 } |
3681 ++iIndex; | 3680 ++iIndex; |
3682 } | 3681 } |
3683 switch (iIndex) { | 3682 switch (iIndex) { |
(...skipping 15 matching lines...) Expand all Loading... | |
3699 default: | 3698 default: |
3700 wsXMLBuf.AppendChar(iCode); | 3699 wsXMLBuf.AppendChar(iCode); |
3701 break; | 3700 break; |
3702 } | 3701 } |
3703 iStrIndex = 0; | 3702 iStrIndex = 0; |
3704 strString[iStrIndex] = 0; | 3703 strString[iStrIndex] = 0; |
3705 ++i; | 3704 ++i; |
3706 iCode = 0; | 3705 iCode = 0; |
3707 } | 3706 } |
3708 wsXMLBuf.AppendChar(0); | 3707 wsXMLBuf.AppendChar(0); |
3708 | |
3709 szResultString.Clear(); | 3709 szResultString.Clear(); |
3710 szResultString << FX_UTF8Encode(wsXMLBuf.GetBuffer(), wsXMLBuf.GetLength()) | 3710 szResultString << FX_UTF8Encode(wsXMLBuf.GetBuffer(), wsXMLBuf.GetLength()) |
3711 .AsStringC(); | 3711 .AsStringC(); |
3712 } | 3712 } |
3713 | 3713 |
3714 // static | 3714 // static |
3715 void CXFA_FM2JSContext::Encode(CFXJSE_Value* pThis, | 3715 void CXFA_FM2JSContext::Encode(CFXJSE_Value* pThis, |
3716 const CFX_ByteStringC& szFuncName, | 3716 const CFX_ByteStringC& szFuncName, |
3717 CFXJSE_Arguments& args) { | 3717 CFXJSE_Arguments& args) { |
3718 int32_t argc = args.GetLength(); | 3718 int32_t argc = args.GetLength(); |
(...skipping 2981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6700 CFX_WideString wsFormat; | 6700 CFX_WideString wsFormat; |
6701 pAppProvider->LoadString(iStringID, wsFormat); | 6701 pAppProvider->LoadString(iStringID, wsFormat); |
6702 CFX_WideString wsMessage; | 6702 CFX_WideString wsMessage; |
6703 va_list arg_ptr; | 6703 va_list arg_ptr; |
6704 va_start(arg_ptr, iStringID); | 6704 va_start(arg_ptr, iStringID); |
6705 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); | 6705 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); |
6706 va_end(arg_ptr); | 6706 va_end(arg_ptr); |
6707 FXJSE_ThrowMessage( | 6707 FXJSE_ThrowMessage( |
6708 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); | 6708 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); |
6709 } | 6709 } |
OLD | NEW |