📄 swfdec_as_types.c
字号:
if (*end == 'e') { /* 'e' */ *start++ = *end++; /* + or - */ *start++ = *end++; /* skip 0s */ while (*end == '0') end++; /* add rest */ while (*end != 0) *start++ = *end++; } /* end string */ *start = 0; return swfdec_as_context_get_string (context, s); } }}/** * swfdec_as_value_to_string: * @context: a #SwfdecAsContext * @value: value to be expressed as string * * Converts @value to a string according to the rules of Flash. This might * cause calling back into the script engine if the @value is an object. In * that case, the object's valueOf function is called. * <warning>Never use this function for debugging purposes.</warning> * * Returns: a garbage-collected string representing @value. The value will * never be %NULL. **/const char *swfdec_as_value_to_string (SwfdecAsContext *context, const SwfdecAsValue *value){ g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (context), SWFDEC_AS_STR_EMPTY); g_return_val_if_fail (SWFDEC_IS_AS_VALUE (value), SWFDEC_AS_STR_EMPTY); switch (value->type) { case SWFDEC_AS_TYPE_STRING: return SWFDEC_AS_VALUE_GET_STRING (value); case SWFDEC_AS_TYPE_UNDEFINED: if (context->version > 6) return SWFDEC_AS_STR_undefined; else return SWFDEC_AS_STR_EMPTY; case SWFDEC_AS_TYPE_BOOLEAN: return SWFDEC_AS_VALUE_GET_BOOLEAN (value) ? SWFDEC_AS_STR_true : SWFDEC_AS_STR_false; case SWFDEC_AS_TYPE_NULL: return SWFDEC_AS_STR_null; case SWFDEC_AS_TYPE_NUMBER: return swfdec_as_double_to_string (context, SWFDEC_AS_VALUE_GET_NUMBER (value)); case SWFDEC_AS_TYPE_OBJECT: { SwfdecAsObject *object = SWFDEC_AS_VALUE_GET_OBJECT (value); if (SWFDEC_IS_MOVIE (object)) { char *str = swfdec_movie_get_path (SWFDEC_MOVIE (object)); const char *ret = swfdec_as_context_get_string (context, str); g_free (str); return ret; } else { SwfdecAsValue ret; swfdec_as_object_call (object, SWFDEC_AS_STR_toString, 0, NULL, &ret); if (SWFDEC_AS_VALUE_IS_STRING (&ret)) return SWFDEC_AS_VALUE_GET_STRING (&ret); else if (SWFDEC_IS_AS_SUPER (SWFDEC_AS_VALUE_GET_OBJECT (value))) return SWFDEC_AS_STR__type_Object_; else if (SWFDEC_IS_AS_FUNCTION (SWFDEC_AS_VALUE_GET_OBJECT (value))) return SWFDEC_AS_STR__type_Function_; else return SWFDEC_AS_STR__type_Object_; } } default: g_assert_not_reached (); return SWFDEC_AS_STR_EMPTY; }}/** * swfdec_as_value_to_debug: * @value: a #SwfdecAsValue * * Converts the given @value to a string in a safe way. It will not call into * the scripting engine. Its intended use is for output in debuggers. * * Returns: a newly allocated string. Free with g_free(). **/char *swfdec_as_value_to_debug (const SwfdecAsValue *value){ g_return_val_if_fail (SWFDEC_IS_AS_VALUE (value), NULL); switch (value->type) { case SWFDEC_AS_TYPE_STRING: return g_shell_quote (SWFDEC_AS_VALUE_GET_STRING (value)); case SWFDEC_AS_TYPE_UNDEFINED: return g_strdup ("undefined"); case SWFDEC_AS_TYPE_BOOLEAN: return g_strdup (SWFDEC_AS_VALUE_GET_BOOLEAN (value) ? "true" : "false"); case SWFDEC_AS_TYPE_NULL: return g_strdup ("null"); case SWFDEC_AS_TYPE_NUMBER: return g_strdup_printf ("%g", SWFDEC_AS_VALUE_GET_NUMBER (value)); case SWFDEC_AS_TYPE_OBJECT: return swfdec_as_object_get_debug (SWFDEC_AS_VALUE_GET_OBJECT (value)); default: g_assert_not_reached (); return NULL; }}/** * swfdec_as_value_to_number: * @context: a #SwfdecAsContext * @value: a #SwfdecAsValue used by context * * Converts the value to a number according to Flash's conversion routines and * the current Flash version. This conversion routine is similar, but not equal * to ECMAScript. For objects, it can call back into the script engine by * calling the object's valueOf function. * * Returns: a double value. It can be NaN or +-Infinity. It will not be -0.0. **/doubleswfdec_as_value_to_number (SwfdecAsContext *context, const SwfdecAsValue *value){ SwfdecAsValue tmp; g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (context), 0.0); g_return_val_if_fail (SWFDEC_IS_AS_VALUE (value), 0.0); tmp = *value; swfdec_as_value_to_primitive (&tmp); switch (tmp.type) { case SWFDEC_AS_TYPE_UNDEFINED: case SWFDEC_AS_TYPE_NULL: return (context->version >= 7) ? NAN : 0.0; case SWFDEC_AS_TYPE_BOOLEAN: return SWFDEC_AS_VALUE_GET_BOOLEAN (&tmp) ? 1 : 0; case SWFDEC_AS_TYPE_NUMBER: return SWFDEC_AS_VALUE_GET_NUMBER (&tmp); case SWFDEC_AS_TYPE_STRING: { const char *s; char *end; double d; s = SWFDEC_AS_VALUE_GET_STRING (&tmp); if (s == SWFDEC_AS_STR_EMPTY) return NAN; d = g_ascii_strtod (s, &end); if (*end == '\0') return d == -0.0 ? 0.0 : d; else return NAN; } case SWFDEC_AS_TYPE_OBJECT: return NAN; default: g_assert_not_reached (); return NAN; }}/** * swfdec_as_value_to_integer: * @context: a #SwfdecAsContext * @value: value to convert * * Converts the given value to an integer. This is done similar to the * conversion used by swfdec_as_value_to_number(). * * Returns: An Integer that can be represented in 32 bits. **/intswfdec_as_value_to_integer (SwfdecAsContext *context, const SwfdecAsValue *value){ double d; d = swfdec_as_value_to_number (context, value); if (!isfinite (d)) return 0; if (d < 0) { d = fmod (-d, 4294967296.0); return - (guint) d; } else { d = fmod (d, 4294967296.0); return (guint) d; }}/** * swfdec_as_value_to_object: * @context: a #SwfdecAsContext * @value: value to convert * * Converts a given value to its representation as an object. The object * representation for primitive types is a wrapper object of the corresponding * class (Number for numbers, String for strings, Boolean for bools). If the * value does not have an object representing it, such as undefined and null * values, %NULL is returned. * * Returns: object representing @value or %NULL. **/SwfdecAsObject *swfdec_as_value_to_object (SwfdecAsContext *context, const SwfdecAsValue *value){ SwfdecAsFunction *fun; SwfdecAsValue val; const char *s; g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (context), NULL); g_return_val_if_fail (SWFDEC_IS_AS_VALUE (value), NULL); switch (value->type) { case SWFDEC_AS_TYPE_UNDEFINED: case SWFDEC_AS_TYPE_NULL: return NULL; case SWFDEC_AS_TYPE_NUMBER: s = SWFDEC_AS_STR_Number; break; case SWFDEC_AS_TYPE_STRING: s = SWFDEC_AS_STR_String; break; case SWFDEC_AS_TYPE_BOOLEAN: s = SWFDEC_AS_STR_Boolean; break; case SWFDEC_AS_TYPE_OBJECT: return SWFDEC_AS_VALUE_GET_OBJECT (value); default: g_assert_not_reached (); return NULL; } swfdec_as_object_get_variable (context->global, s, &val); if (!SWFDEC_AS_VALUE_IS_OBJECT (&val) || !SWFDEC_IS_AS_FUNCTION (fun = (SwfdecAsFunction *) SWFDEC_AS_VALUE_GET_OBJECT (&val))) return NULL; swfdec_as_object_create (fun, 1, value); swfdec_as_context_run (context); value = swfdec_as_stack_pop (context); if (SWFDEC_AS_VALUE_IS_OBJECT (value)) { return SWFDEC_AS_VALUE_GET_OBJECT (value); } else { SWFDEC_ERROR ("did not construct an object"); return NULL; }}/*** swfdec_as_value_to_boolean:* @context: a #SwfdecAsContext* @value: value to convert** Converts the given value to a boolean according to Flash's rules. Note that* these rules changed significantly for strings between Flash 6 and 7.** Returns: either %TRUE or %FALSE.**/gbooleanswfdec_as_value_to_boolean (SwfdecAsContext *context, const SwfdecAsValue *value){ g_return_val_if_fail (SWFDEC_IS_AS_CONTEXT (context), FALSE); g_return_val_if_fail (SWFDEC_IS_AS_VALUE (value), FALSE); /* FIXME: what do we do when called in flash 4? */ switch (value->type) { case SWFDEC_AS_TYPE_UNDEFINED: case SWFDEC_AS_TYPE_NULL: return FALSE; case SWFDEC_AS_TYPE_BOOLEAN: return SWFDEC_AS_VALUE_GET_BOOLEAN (value); case SWFDEC_AS_TYPE_NUMBER: { double d = SWFDEC_AS_VALUE_GET_NUMBER (value); return d != 0.0 && !isnan (d); } case SWFDEC_AS_TYPE_STRING: if (context->version <= 6) { double d = swfdec_as_value_to_number (context, value); return d != 0.0 && !isnan (d); } else { return SWFDEC_AS_VALUE_GET_STRING (value) != SWFDEC_AS_STR_EMPTY; } case SWFDEC_AS_TYPE_OBJECT: return TRUE; default: g_assert_not_reached (); return FALSE; }}/*** swfdec_as_value_to_primitive:* @value: value to convert** Tries to convert the given @value inline to its primitive value. Primitive * values are values that are not objects. If the value is an object, the * object's valueOf function is called. If the result of that function is still * an object, it is returned nonetheless.**/voidswfdec_as_value_to_primitive (SwfdecAsValue *value){ g_return_if_fail (SWFDEC_IS_AS_VALUE (value)); if (SWFDEC_AS_VALUE_IS_OBJECT (value) && !SWFDEC_IS_MOVIE (SWFDEC_AS_VALUE_GET_OBJECT (value))) { swfdec_as_object_call (SWFDEC_AS_VALUE_GET_OBJECT (value), SWFDEC_AS_STR_valueOf, 0, NULL, value); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -