Benjamin Otte
2007-Jun-28 10:43 UTC
[Swfdec] Branch 'as' - 3 commits - libswfdec/swfdec_as_string.c libswfdec/swfdec_as_strings.c test/trace
libswfdec/swfdec_as_string.c | 25 +++++++++++++++++++++++++ libswfdec/swfdec_as_strings.c | 1 + test/trace/Makefile.am | 7 +++++++ test/trace/string-indexof-5.swf |binary test/trace/string-indexof-5.swf.trace | 19 +++++++++++++++++++ test/trace/string-indexof-6.swf |binary test/trace/string-indexof-6.swf.trace | 19 +++++++++++++++++++ test/trace/string-indexof-7.swf |binary test/trace/string-indexof-7.swf.trace | 19 +++++++++++++++++++ test/trace/string-indexof.as | 23 +++++++++++++++++++++++ 10 files changed, 113 insertions(+) New commits: diff-tree 873e9bf85e325fdb7cad66d9d7eecb1dd1ce26d5 (from parents) Merge: 7f298fef1fdf95fbc9c5754f2ffc63acc8895cd8 c7622a13456a723bef13fd0a1b80a4060758af70 Author: Benjamin Otte <otte at gnome.org> Date: Thu Jun 28 12:41:18 2007 +0200 Merge branch 'as' of ssh://company at git.freedesktop.org/git/swfdec into as diff-tree 7f298fef1fdf95fbc9c5754f2ffc63acc8895cd8 (from 09d2f3639447e1d6fa87f5d52c8abcbe55f4f10a) Author: Andreas Henriksson <andreas at fatal.se> Date: Thu Jun 28 12:34:31 2007 +0200 add String.indexOf() diff --git a/libswfdec/swfdec_as_string.c b/libswfdec/swfdec_as_string.c index 5ce98c9..8515c7c 100644 --- a/libswfdec/swfdec_as_string.c +++ b/libswfdec/swfdec_as_string.c @@ -68,6 +68,30 @@ swfdec_as_str_nth_char (const char *s, g } static void +swfdec_as_string_indexOf (SwfdecAsContext *cx, SwfdecAsObject *object, + guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret) +{ + SwfdecAsString *string = SWFDEC_AS_STRING (object); + int offset=0, len, i=-1; + const char *s, *t = NULL; + + s = swfdec_as_value_to_string (object->context, &argv[0]); + if (argc == 2) + offset = swfdec_as_value_to_integer (object->context, &argv[1]); + if (offset < 0) + offset = 0; + len = g_utf8_strlen (string->string, -1); + if (offset < len) { + t = strstr (g_utf8_offset_to_pointer (string->string, offset), s); + } + if (t != NULL) { + i = g_utf8_pointer_to_offset (string->string, t); + } + + SWFDEC_AS_VALUE_SET_INT (ret, i); +} + +static void swfdec_as_string_charAt (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc, SwfdecAsValue *argv, SwfdecAsValue *ret) { @@ -671,6 +695,7 @@ swfdec_as_string_init_context (SwfdecAsC SWFDEC_AS_VALUE_SET_OBJECT (&val, string); swfdec_as_object_set_variable (proto, SWFDEC_AS_STR_constructor, &val); swfdec_as_object_add_function (proto, SWFDEC_AS_STR_charAt, SWFDEC_TYPE_AS_STRING, swfdec_as_string_charAt, 1); + swfdec_as_object_add_function (proto, SWFDEC_AS_STR_indexOf, SWFDEC_TYPE_AS_STRING, swfdec_as_string_indexOf, 1); swfdec_as_object_add_function (proto, SWFDEC_AS_STR_charCodeAt, SWFDEC_TYPE_AS_STRING, swfdec_as_string_charCodeAt, 1); swfdec_as_object_add_function (proto, SWFDEC_AS_STR_substr, SWFDEC_TYPE_AS_STRING, swfdec_as_string_substr, 1); swfdec_as_object_add_function (proto, SWFDEC_AS_STR_substring, SWFDEC_TYPE_AS_STRING, swfdec_as_string_substring, 1); diff --git a/libswfdec/swfdec_as_strings.c b/libswfdec/swfdec_as_strings.c index 7a846f5..f7d3d6b 100644 --- a/libswfdec/swfdec_as_strings.c +++ b/libswfdec/swfdec_as_strings.c @@ -221,6 +221,7 @@ const char swfdec_as_strings[] = SWFDEC_AS_CONSTANT_STRING ("time") SWFDEC_AS_CONSTANT_STRING ("bytesLoaded") SWFDEC_AS_CONSTANT_STRING ("bytesTotal") + SWFDEC_AS_CONSTANT_STRING ("indexOf") /* add more here */ ; diff-tree 09d2f3639447e1d6fa87f5d52c8abcbe55f4f10a (from 81472f980827d624a88339abd8db0e40c8aaf453) Author: Andreas Henriksson <andreas at fatal.se> Date: Thu Jun 28 12:33:21 2007 +0200 add test for String.indexOf() diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am index 222665c..4132702 100644 --- a/test/trace/Makefile.am +++ b/test/trace/Makefile.am @@ -650,6 +650,13 @@ EXTRA_DIST = \ string-convert-6.swf.trace \ string-convert-7.swf \ string-convert-7.swf.trace \ + string-indexof.as \ + string-indexof-5.swf \ + string-indexof-5.swf.trace \ + string-indexof-6.swf \ + string-indexof-6.swf.trace \ + string-indexof-7.swf \ + string-indexof-7.swf.trace \ string-split.as \ string-split-5.swf \ string-split-5.swf.trace \ diff --git a/test/trace/string-indexof-5.swf b/test/trace/string-indexof-5.swf new file mode 100644 index 0000000..a8fccc1 Binary files /dev/null and b/test/trace/string-indexof-5.swf differ diff --git a/test/trace/string-indexof-5.swf.trace b/test/trace/string-indexof-5.swf.trace new file mode 100644 index 0000000..0d2806e --- /dev/null +++ b/test/trace/string-indexof-5.swf.trace @@ -0,0 +1,19 @@ +Check String.indexOf +>>> ABCDEFGHIabcdefghiABCDEFGHIabcdefghi +36 +12 +15 +-1 +-1 +-1 +35 +17 +>>> ????????????t????tGHIabcdefghiABCDEFGHIabcdefghi +40 +16 +19 +-1 +-1 +39 +39 +21 diff --git a/test/trace/string-indexof-6.swf b/test/trace/string-indexof-6.swf new file mode 100644 index 0000000..0192218 Binary files /dev/null and b/test/trace/string-indexof-6.swf differ diff --git a/test/trace/string-indexof-6.swf.trace b/test/trace/string-indexof-6.swf.trace new file mode 100644 index 0000000..5292ad6 --- /dev/null +++ b/test/trace/string-indexof-6.swf.trace @@ -0,0 +1,19 @@ +Check String.indexOf +>>> ABCDEFGHIabcdefghiABCDEFGHIabcdefghi +36 +12 +15 +-1 +-1 +-1 +35 +17 +>>> ??????t??tGHIabcdefghiABCDEFGHIabcdefghi +36 +12 +15 +-1 +-1 +-1 +35 +17 diff --git a/test/trace/string-indexof-7.swf b/test/trace/string-indexof-7.swf new file mode 100644 index 0000000..2a11f9e Binary files /dev/null and b/test/trace/string-indexof-7.swf differ diff --git a/test/trace/string-indexof-7.swf.trace b/test/trace/string-indexof-7.swf.trace new file mode 100644 index 0000000..5292ad6 --- /dev/null +++ b/test/trace/string-indexof-7.swf.trace @@ -0,0 +1,19 @@ +Check String.indexOf +>>> ABCDEFGHIabcdefghiABCDEFGHIabcdefghi +36 +12 +15 +-1 +-1 +-1 +35 +17 +>>> ??????t??tGHIabcdefghiABCDEFGHIabcdefghi +36 +12 +15 +-1 +-1 +-1 +35 +17 diff --git a/test/trace/string-indexof.as b/test/trace/string-indexof.as new file mode 100644 index 0000000..4f4a3d4 --- /dev/null +++ b/test/trace/string-indexof.as @@ -0,0 +1,23 @@ +// makeswf -v 7 -s 200x150 -r 1 -o string-indexof.swf string-indexof.as + +trace ("Check String.indexOf"); + +strings = [ "ABCDEFGHIabcdefghiABCDEFGHIabcdefghi", + "??????t??tGHIabcdefghiABCDEFGHIabcdefghi" +]; + +for (i = 0; i < strings.length; i++) { + foobar = strings[i]; + trace (">>> " + foobar); + trace (foobar.length); + trace (foobar.indexOf ("def")); + trace (foobar.indexOf ("ghi", 3)); + trace (foobar.indexOf ("no-such-string")); + trace (foobar.indexOf ("ABC", 30)); + trace (foobar.indexOf ("i", 36)); + trace (foobar.indexOf ("i", 35)); + trace (foobar.indexOf ("i", -15)); +} + +loadMovie("FSCommand:quit", ""); +
Apparently Analagous Threads
- 7 commits - libswfdec/swfdec_as_context.c libswfdec/swfdec_as_interpret.c libswfdec/swfdec_as_object.h libswfdec/swfdec_as_string.c test/trace
- 4 commits - libswfdec/swfdec_as_array.c libswfdec/swfdec_as_boolean.c libswfdec/swfdec_as_function.c libswfdec/swfdec_as_number.c libswfdec/swfdec_as_object.c libswfdec/swfdec_as_string.c libswfdec/swfdec_color_as.c test/trace
- 23 commits - doc/.gitignore doc/Makefile.am doc/swfdec-docs.sgml doc/swfdec-sections.txt libswfdec-gtk/swfdec-gtk.h libswfdec-gtk/swfdec_gtk_keys.c libswfdec-gtk/swfdec_gtk_keys.h libswfdec-gtk/swfdec_gtk_widget.c libswfdec/Makefile.am
- Branch 'as' - 13 commits - libswfdec/swfdec_as_context.c libswfdec/swfdec_as_context.h libswfdec/swfdec_as_frame.c libswfdec/swfdec_as_frame.h libswfdec/swfdec_as_interpret.c libswfdec/swfdec_as_object.c libswfdec/swfdec_as_object.h
- 8 commits - libswfdec/Makefile.am libswfdec/swfdec_as_string.c libswfdec/swfdec_as_string.h libswfdec/swfdec_as_strings.c libswfdec/swfdec_initialize.as libswfdec/swfdec_initialize.h libswfdec/swfdec_load_object.c libswfdec/swfdec_loadvars_as.c test/trace