[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash testsuite/actionscript.allMakefile.am ser...
From: |
Michael Carlson |
Subject: |
[Gnash-commit] gnash testsuite/actionscript.allMakefile.am ser... |
Date: |
Tue, 20 Jun 2006 02:05:22 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Michael Carlson <corfe> 06/06/20 02:05:22
Modified files:
testsuite/actionscript.all: Makefile.am
server : string.cpp
. : ChangeLog
Added files:
testsuite/actionscript.all: String.as
Log message:
Eliminate wasteful if/else and string_method function in string class
and implement several string functions
Add initial String tests
Build String.swf with other tests
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/Makefile.am?cvsroot=gnash&r1=1.23&r2=1.24
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/String.as?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/server/string.cpp?cvsroot=gnash&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.414&r2=1.415
Patches:
Index: testsuite/actionscript.all/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/Makefile.am,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- testsuite/actionscript.all/Makefile.am 9 May 2006 10:31:36 -0000
1.23
+++ testsuite/actionscript.all/Makefile.am 20 Jun 2006 02:05:22 -0000
1.24
@@ -79,6 +79,7 @@
Selection.swf \
SharedObject.swf \
Stage.swf \
+ String.swf \
System.swf \
TextSnapshot.swf \
Video.swf \
Index: server/string.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/string.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- server/string.cpp 20 May 2006 23:49:33 -0000 1.7
+++ server/string.cpp 20 Jun 2006 02:05:22 -0000 1.8
@@ -45,64 +45,67 @@
#include "fn_call.h"
namespace gnash {
- void string_method(const fn_call& fn, const tu_stringi& method_name,
const tu_string& this_string)
- // Executes the string method named by method_name.
+
+ struct tu_string_as_object : public gnash::as_object
{
- if (method_name == "charCodeAt")
+ tu_string m_string;
+ };
+
+ // 1st param: start_index, 2nd param: length (NOT end_index)
+ void string_sub_str(const fn_call& fn)
{
- int index = (int) fn.arg(0).to_number();
- if (index >= 0 && index < this_string.utf8_length())
+ tu_string this_string = ((tu_string_as_object*)
fn.this_ptr)->m_string;
+ // Pull a slice out of this_string.
+ int start = 0;
+ int utf8_len = this_string.utf8_length();
+ int end = utf8_len;
+ if (fn.nargs >= 1)
{
-
fn.result->set_double(this_string.utf8_char_at(index));
- return;
- }
-
- double temp = 0.0; // This variable will let us
divide by zero without a compiler warning
- fn.result->set_double(temp/temp); // this
division by zero creates a NaN value
- return;
+ start = (int) fn.arg(0).to_number();
+ if (start < 0) start = utf8_len + start;
+ start = iclamp(start, 0, utf8_len);
}
- else if (method_name == "charAt")
- {
- int index = (int) fn.arg(0).to_number();
- if (index >= 0 && index < this_string.utf8_length())
+ if (fn.nargs >= 2)
{
- tu_string result;
- result += this_string.utf8_char_at(index);
- fn.result->set_tu_string(result);
+ end = (int) fn.arg(1).to_number() + start;
+ end = iclamp(end, start, utf8_len);
}
- fn.result->set_string("");
+ fn.result->set_tu_string(this_string.utf8_substring(start,
end));
return;
}
- else if (method_name == "fromCharCode")
- {
- // Takes a variable number of args. Each arg
- // is a numeric character code. Construct the
- // string from the character codes.
-
- tu_string result;
- for (int i = 0; i < fn.nargs; i++)
+ // 1st param: start_index, 2nd param: end_index
+ void string_sub_string(const fn_call& fn)
{
- uint32 c = (uint32) fn.arg(i).to_number();
- result.append_wide_char(c);
- }
-
- fn.result->set_tu_string(result);
- return;
- }
- else if (method_name == "toUpperCase")
+ tu_string this_string = ((tu_string_as_object*)
fn.this_ptr)->m_string;
+ // Pull a slice out of this_string.
+ int start = 0;
+ int utf8_len = this_string.utf8_length();
+ int end = utf8_len;
+ if (fn.nargs >= 1)
{
- fn.result->set_tu_string(this_string.utf8_to_upper());
- return;
+ start = (int) fn.arg(0).to_number();
+ start = iclamp(start, 0, utf8_len);
}
- else if (method_name == "toLowerCase")
+ if (fn.nargs >= 2)
{
- fn.result->set_tu_string(this_string.utf8_to_lower());
+ end = (int) fn.arg(1).to_number();
+ end = iclamp(end, 0, utf8_len);
+ }
+
+ if (end < start) swap(&start, &end); // dumb, but that's
what the docs say
+ assert(end >= start);
+
+ fn.result->set_tu_string(this_string.utf8_substring(start,
end));
return;
}
- else if (method_name == "indexOf")
+
+ void string_index_of(const fn_call& fn)
{
+ tu_string_as_object* this_string_ptr = (tu_string_as_object*)
fn.this_ptr;
+ assert(this_string_ptr);
+
if (fn.nargs < 1)
{
fn.result->set_double(-1);
@@ -115,7 +118,7 @@
{
start_index = (int)
fn.arg(1).to_number();
}
- const char* str = this_string.c_str();
+ const char* str = this_string_ptr->m_string.c_str();
const char* p = strstr(
str + start_index, // FIXME: not
UTF-8 correct!
fn.arg(0).to_string());
@@ -129,91 +132,84 @@
return;
}
}
- else if (method_name == "substring")
+
+
+ void string_from_char_code(const fn_call& fn)
{
- // Pull a slice out of this_string.
- int start = 0;
- int utf8_len = this_string.utf8_length();
- int end = utf8_len;
- if (fn.nargs >= 1)
+ tu_string_as_object* this_string_ptr = (tu_string_as_object*)
fn.this_ptr;
+ assert(this_string_ptr);
+
+ tu_string result;
+
+ for (int i = 0; i < fn.nargs; i++)
{
- start = (int) fn.arg(0).to_number();
- start = iclamp(start, 0, utf8_len);
+ uint32 c = (uint32) fn.arg(i).to_number();
+ result.append_wide_char(c);
}
- if (fn.nargs >= 2)
- {
- end = (int) fn.arg(1).to_number();
- end = iclamp(end, 0, utf8_len);
+
+ fn.result->set_tu_string(result);
}
- if (end < start) swap(&start, &end); // dumb, but
that's what the docs say
- assert(end >= start);
-
fn.result->set_tu_string(this_string.utf8_substring(start, end));
+ void string_char_code_at(const fn_call& fn)
+ {
+ tu_string_as_object* this_string_ptr = (tu_string_as_object*)
fn.this_ptr;
+ assert(this_string_ptr);
+
+ assert(fn.nargs == 1);
+
+ int index = (int) fn.arg(0).to_number();
+ if (index >= 0 && index <
this_string_ptr->m_string.utf8_length())
+ {
+
fn.result->set_double(this_string_ptr->m_string.utf8_char_at(index));
return;
}
- // concat()
- // lastIndexOf()
- // length property
- // slice()
- // split()
- // substr()
- fn.result->set_undefined();
+ double temp = 0.0; // This variable will let us divide by
zero without a compiler warning
+ fn.result->set_double(temp/temp); // this division by
zero creates a NaN value
+ return;
}
-
- struct tu_string_as_object : public gnash::as_object
+ void string_char_at(const fn_call& fn)
{
- tu_string m_string;
- };
+ tu_string_as_object* this_string_ptr = (tu_string_as_object*)
fn.this_ptr;
+ assert(this_string_ptr);
+ assert(fn.nargs == 1);
- void string_last_index_of(const fn_call& fn)
+ int index = (int) fn.arg(0).to_number();
+ if (index >= 0 && index <
this_string_ptr->m_string.utf8_length())
{
- tu_string_as_object* this_string_ptr = (tu_string_as_object*)
fn.this_ptr;
- assert(this_string_ptr);
+ tu_string result;
+ result += this_string_ptr->m_string.utf8_char_at(index);
+ fn.result->set_tu_string(result);
+ return;
+ }
- // tulrich: Ugh! The caller has done hash.get() on
- // the method name to find the method, and now we're
- // going to construct a new method name and run it
- // through a big if-else.
- //
- // TODO do this more efficiently.
- string_method(fn, tu_stringi("lastIndexOf"),
this_string_ptr->m_string);
+ double temp = 0.0; // This variable will let us divide by
zero without a compiler warning
+ fn.result->set_double(temp/temp); // this division by
zero creates a NaN value
+ return;
}
- void string_from_char_code(const fn_call& fn)
+ void string_to_upper_case(const fn_call& fn)
{
tu_string_as_object* this_string_ptr = (tu_string_as_object*)
fn.this_ptr;
assert(this_string_ptr);
- // tulrich: Ugh! The caller has done hash.get() on
- // the method name to find the method, and now we're
- // going to construct a new method name and run it
- // through a big if-else.
- //
- // TODO do this more efficiently.
- string_method(fn, tu_stringi("fromCharCode"),
this_string_ptr->m_string);
+
fn.result->set_tu_string(this_string_ptr->m_string.utf8_to_upper());
+ return;
}
-
- void string_char_code_at(const fn_call& fn)
+ void string_to_lower_case(const fn_call& fn)
{
tu_string_as_object* this_string_ptr = (tu_string_as_object*)
fn.this_ptr;
assert(this_string_ptr);
- // tulrich: Ugh! The caller has done hash.get() on
- // the method name to find the method, and now we're
- // going to construct a new method name and run it
- // through a big if-else.
- //
- // TODO do this more efficiently.
- string_method(fn, tu_stringi("charCodeAt"),
this_string_ptr->m_string);
+
fn.result->set_tu_string(this_string_ptr->m_string.utf8_to_lower());
+ return;
}
-
void string_to_string(const fn_call& fn)
{
tu_string_as_object* this_string_ptr = (tu_string_as_object*)
fn.this_ptr;
@@ -233,10 +229,20 @@
}
// TODO fill in the rest
+ // concat()
+ // length property
+ // slice()
+ // split()
+ // lastIndexOf()
+ str->set_member("substr", &string_sub_str);
+ str->set_member("substring", &string_sub_string);
+ str->set_member("indexOf", &string_index_of);
str->set_member("toString", &string_to_string);
str->set_member("fromCharCode", &string_from_char_code);
+ str->set_member("charAt", &string_char_at);
str->set_member("charCodeAt", &string_char_code_at);
- str->set_member("lastIndexOf", &string_last_index_of);
+ str->set_member("toUpperCase", &string_to_upper_case);
+ str->set_member("toLowerCase", &string_to_lower_case);
fn.result->set_as_object(str.get_ptr());
}
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.414
retrieving revision 1.415
diff -u -b -r1.414 -r1.415
--- ChangeLog 19 Jun 2006 16:11:26 -0000 1.414
+++ ChangeLog 20 Jun 2006 02:05:22 -0000 1.415
@@ -1,3 +1,10 @@
+2006-06-19 Michael Carlson <address@hidden>
+
+ * server/string.cpp: Eliminate wasteful if/else and
+ string_method function, implement several string functions
+ * testsuite/actionscript.all/string.as: Initial String tests
+ * testsuite/actionscript.all/Makefile.am: Build string.swf
+
2006-06-19 Vitaly Alexeev <address@hidden>
* server/movie_def_impl.h: fixed bug #16882
Index: testsuite/actionscript.all/String.as
===================================================================
RCS file: testsuite/actionscript.all/String.as
diff -N testsuite/actionscript.all/String.as
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/actionscript.all/String.as 20 Jun 2006 02:05:22 -0000
1.1
@@ -0,0 +1,33 @@
+// Mike Carlson's test program for actionscript strings
+// June 19th, 2006
+
+#include "check.as"
+
+var a;
+a = new String("wallawallawashinGTON");
+check_equals ( a.charCodeAt(0), 119 );
+check_equals ( a.charCodeAt(1), 97 );
+check_equals ( a.charCodeAt(2), 108 );
+check_equals ( a.charCodeAt(3), 108 );
+check_equals ( a.charCodeAt(4), 97 );
+check_equals ( a.charAt(0), "w" );
+check_equals ( a.charAt(1), "a" );
+check_equals ( a.charAt(2), "l" );
+check_equals ( a.charAt(3), "l" );
+check_equals ( a.charAt(4), "a" );
+check_equals ( a.indexOf("lawa"), 3 );
+check_equals ( a.indexOf("lawas"), 8 );
+check_equals ( a.indexOf("hinG"), 13 );
+check_equals ( a.indexOf("hing"), -1 );
+var b = a.fromCharCode(97,98,99,100);
+check_equals ( b, "abcd" );
+check_equals ( a.toUpperCase(), "WALLAWALLAWASHINGTON" );
+check_equals ( a.toLowerCase(), "wallawallawashington" );
+a = new String("abcdefghijklmnopqrstuvwxyz");
+check_equals ( a.substr(5,2), "fg" );
+check_equals ( a.substr(5,7), "fghijkl" );
+check_equals ( a.substr(-1,1), "z" );
+check_equals ( a.substr(-2,3), "yz" );
+check_equals ( a.substr(-3,2), "xy" );
+check_equals ( a.substring(5,2), "cde" );
+check_equals ( a.substring(5,7), "fg" );
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash testsuite/actionscript.allMakefile.am ser...,
Michael Carlson <=