gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog testsuite/actionscript.all/Stri...


From: Benjamin Wolsey
Subject: [Gnash-commit] gnash ChangeLog testsuite/actionscript.all/Stri...
Date: Mon, 17 Mar 2008 08:06:48 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Benjamin Wolsey <bwy>   08/03/17 08:06:48

Modified files:
        .              : ChangeLog 
        testsuite/actionscript.all: String.as 
        server/asobj   : string.cpp 
        server/vm      : ASHandlers.cpp 

Log message:
                * server/asobj/string.cpp: String.substr(): an undefined second
                  argument is the same as having only one argument.
            * server/vm/ASHandlers.cpp: action substring: make variable names
              consistent with mbsubstring; use C++ string methods and handle
              utf-8 properly for different versions.
            * testsuite/actionscript.all/String.as: update / add tests for 
substring
              and String.substr (now passing).

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5940&r2=1.5941
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/String.as?cvsroot=gnash&r1=1.47&r2=1.48
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/string.cpp?cvsroot=gnash&r1=1.58&r2=1.59
http://cvs.savannah.gnu.org/viewcvs/gnash/server/vm/ASHandlers.cpp?cvsroot=gnash&r1=1.215&r2=1.216

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.5940
retrieving revision 1.5941
diff -u -b -r1.5940 -r1.5941
--- ChangeLog   16 Mar 2008 15:51:49 -0000      1.5940
+++ ChangeLog   17 Mar 2008 08:06:46 -0000      1.5941
@@ -1,3 +1,13 @@
+2008-03-17 Benjamin Wolsey <address@hidden>
+
+       * server/asobj/string.cpp: String.substr(): an undefined second
+         argument is the same as having only one argument.
+    * server/vm/ASHandlers.cpp: action substring: make variable names
+      consistent with mbsubstring; use C++ string methods and handle
+      utf-8 properly for different versions.
+    * testsuite/actionscript.all/String.as: update / add tests for substring
+      and String.substr (now passing).
+
 2008-03-16 Benjamin Wolsey <address@hidden>
 
        * gui/Player.{h,cpp}: handle an empty url, fix misc-ming.all failures.

Index: testsuite/actionscript.all/String.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/String.as,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -b -r1.47 -r1.48
--- testsuite/actionscript.all/String.as        16 Mar 2008 15:51:49 -0000      
1.47
+++ testsuite/actionscript.all/String.as        17 Mar 2008 08:06:47 -0000      
1.48
@@ -17,7 +17,7 @@
 // Original author: Mike Carlson - June 19th, 2006
 
 
-rcsid="$Id: String.as,v 1.47 2008/03/16 15:51:49 bwy Exp $";
+rcsid="$Id: String.as,v 1.48 2008/03/17 08:06:47 bwy Exp $";
 #include "check.as"
 
 check_equals(typeof(String), 'function');
@@ -494,7 +494,8 @@
 check_equals( b, "f");
 
 teststr = "Heöllo";
-count = 0;
+count1 = 0;
+count2 = 0;
 
 for (i = -5; i < 10; i++)
 {
@@ -506,23 +507,28 @@
             getvariable
             push "i"
             getvariable
-            push "j" // size is bigger then string length,
+            push "j"
             getvariable
-                      // we expect the interpreter to adjust it
             substring
             setvariable
         };
         
-        b = teststr.substr( i >= 1 ? i - 1 : 0, j >= 0 ? j: teststr.length());
+        b = teststr.substr( i >= 1 ? i - 1 : 0, j >= 0 ? j : teststr.length);
+
+        // Test for undefined.
+        c = teststr.substr( i >= 1 ? i - 1 : 0, j >= 0 ? j : teststr.undef());
         
-        // There are ... tests
-        if (a == b) count++;
+        // There are 225 tests
+        if (a == b) count1++;
         else note(i + " : " + j + " -- " + a + ":" + b);
+
+        if (b == c) count2++;
+
     }
 }
 
-// For SWF5 this because of substr...
-xcheck_equals (count, 225);
+check_equals (count1, 225); // String.substr / substring consistency
+check_equals (count2, 225); // undefined value same as no value passed (or 
length of string)
 
 #endif
 
@@ -740,7 +746,7 @@
 check_equals(r, "s:");
 
 #if OUTPUT_VERSION < 6
- check_totals(202);
+ check_totals(203);
 #else
- check_totals(232);
+ check_totals(233);
 #endif

Index: server/asobj/string.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/string.cpp,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -b -r1.58 -r1.59
--- server/asobj/string.cpp     7 Mar 2008 19:33:40 -0000       1.58
+++ server/asobj/string.cpp     17 Mar 2008 08:06:47 -0000      1.59
@@ -217,17 +217,16 @@
 
 
 static size_t
-valid_index(const std::wstring& subject, int index)
+validIndex(const std::wstring& subject, int index)
 {
-    int myIndex = index;
 
-    if (myIndex < 0) {
-        myIndex = subject.size() + myIndex;
+    if (index < 0) {
+        index = subject.size() + index;
     }
 
-    myIndex = iclamp(myIndex, 0, subject.size());
+    index = iclamp(index, 0, subject.size());
 
-    return myIndex;
+    return index;
 }
 
 // 1st param: start_index, 2nd param: end_index
@@ -243,14 +242,13 @@
 
     ENSURE_FN_ARGS(1, 2, as_value());
 
-    size_t start = valid_index(wstr, fn.arg(0).to_int());
+    size_t start = validIndex(wstr, fn.arg(0).to_int());
 
-    size_t len = wstr.length();
+    size_t end = wstr.length();
 
-    size_t end = len;
     if (fn.nargs >= 2)
     {
-       end = valid_index(wstr, fn.arg(1).to_int());
+       end = validIndex(wstr, fn.arg(1).to_int());
 
     } 
 
@@ -259,7 +257,7 @@
             return as_value("");
     }
 
-    size_t retlen = end-start;
+    size_t retlen = end - start;
 
     log_debug("start: "SIZET_FMT", end: "SIZET_FMT", retlen: "SIZET_FMT, 
start, end, retlen);
 
@@ -307,7 +305,7 @@
 
     if (fn.nargs >= 2)
     {
-       int max_in = fn.arg(1).to_number<int>();
+       int max_in = fn.arg(1).to_int();
        if ( SWFVersion < 6 && max_in < 1 )
        {
                return as_value(array.get());
@@ -372,7 +370,7 @@
     int start = str.size();
 
     if (fn.nargs >= 2) {
-        start = fn.arg(1).to_number<int>();
+        start = fn.arg(1).to_int();
     }
     
     if (start < 0) {
@@ -388,23 +386,27 @@
     return as_value(found - toFind.size() + 1);
 }
 
-// 1st param: start_index, 2nd param: length (NOT end_index)
+// String.substr(start[, length]).
+// If the second value is absent or undefined, the remainder of the string from
+// <start> is returned.
+// If start is more than string length or length is 0, empty string is 
returned.
+// If length is negative, the substring is taken from the *end* of the string.
 static as_value
 string_sub_str(const fn_call& fn)
 {
     boost::intrusive_ptr<string_as_object> obj = 
ensureType<string_as_object>(fn.this_ptr);
 
     int version = VM::get().getSWFVersion();
-    // Make a copy.
+
     std::wstring wstr = utf8::decodeCanonicalString(obj->str(), version);
 
     ENSURE_FN_ARGS(1, 2, obj->str());
 
-    int start = valid_index(wstr, fn.arg(0).to_int());
+    int start = validIndex(wstr, fn.arg(0).to_int());
 
-    int num = wstr.size();
+    int num = wstr.length();
 
-    if (fn.nargs >= 2)
+    if (fn.nargs >= 2 && !fn.arg(1).is_undefined())
     {
         num = fn.arg(1).to_int();
        if ( num < 0 )
@@ -412,7 +414,7 @@
                if ( -num <= start ) num = 0;
                else
                {
-                       num = wstr.size() + num;
+                           num = wstr.length() + num;
                        if ( num < 0 ) return as_value("");
                }
        }
@@ -423,7 +425,7 @@
 
 // string.substring(start[, end])
 // If *either* value is less than 0, 0 is used.
-// The values are swapped if end is smaller than start.
+// The values are *then* swapped if end is before start.
 // Valid values for the start position are up to string 
 // length - 1.
 static as_value
@@ -437,7 +439,7 @@
 
     ENSURE_FN_ARGS(1, 2, obj->str());
 
-    int start = fn.arg(0).to_number<int>();
+    int start = fn.arg(0).to_int();
     int end = wstr.size();
 
     if (start < 0) {
@@ -449,7 +451,7 @@
     }
 
     if (fn.nargs >= 2) {
-        int num = fn.arg(1).to_number<int>();
+        int num = fn.arg(1).to_int();
 
         if (num < 0) {
             num = 0;

Index: server/vm/ASHandlers.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/vm/ASHandlers.cpp,v
retrieving revision 1.215
retrieving revision 1.216
diff -u -b -r1.215 -r1.216
--- server/vm/ASHandlers.cpp    15 Mar 2008 17:02:51 -0000      1.215
+++ server/vm/ASHandlers.cpp    17 Mar 2008 08:06:48 -0000      1.216
@@ -880,16 +880,18 @@
 void
 SWFHandlers::ActionSubString(ActionExec& thread)
 {
-    //GNASH_REPORT_FUNCTION;
+
+    // substring("string",  base,  size) 
+    // SWF4 function, deprecated in favour of String.substring.
+    // 1-based (String object methods are 0-based).
+
     as_environment& env = thread.env;
-    thread.ensureStack(3); // size, base, string
+    thread.ensureStack(3); // string, start, size
 
-    as_value& size_val = env.top(0);
-    as_value& base_val = env.top(1);
-    as_value& string_val = env.top(2);
+    const as_value& strval = env.top(2);
 
     // input checks
-    if ( string_val.is_undefined() || string_val.is_null() )
+    if ( strval.is_undefined() || strval.is_null() )
     {
        log_error(_("Undefined or null string passed to ActionSubString, "
                "returning undefined"));
@@ -898,11 +900,14 @@
        return;
     }
 
-    int size = unsigned(size_val.to_number());
+    int size = env.top(0).to_int();
+    int start = env.top(1).to_int();
 
-    int        base = int(base_val.to_number()); // TODO: use to_int ?
+    // We don't need to_string_versioned because undefined values have
+    // already been dealt with.
     int version = env.get_version();
-    const std::string& str = string_val.to_string_versioned(version);
+    const std::wstring wstr = utf8::decodeCanonicalString(
+                                strval.to_string(), version);
 
     if ( size < 0 )
     {
@@ -910,25 +915,27 @@
        log_aserror(_("Negative size passed to ActionSubString, "
                "taking as whole length"));
        );
-       size = str.length();
+           size = wstr.length();
     }
 
-    // TODO: if 'base' or 'size' do not evaluate to numbers return
+    // TODO: if 'start' or 'size' do not evaluate to numbers return
     //       the empty string (how do we check if they evaluate ??)
 
-    if ( base < 1 )
+    if ( start < 1 )
     {
        IF_VERBOSE_ASCODING_ERRORS (
-       log_aserror(_("Base is less then 1 in ActionSubString, "
+               log_aserror(_("Start is less then 1 in ActionSubString, "
                "setting to 1."));
        );
-       base=1;
+           start = 1;
     }
 
-    else if ( unsigned(base) > str.length() )
+    // If start is longer than the string length, return empty
+    // string
+    else if (static_cast<unsigned int>(start) > wstr.length() )
     {
        IF_VERBOSE_ASCODING_ERRORS (
-       log_aserror(_("base goes beyond input string in ActionSubString, "
+               log_aserror(_("Start goes beyond input string in 
ActionSubString, "
                "returning the empty string."));
        );
        env.drop(2);
@@ -936,37 +943,33 @@
        return;
     }
 
-    // Base is 1-based, we'll use 0-based from now on...
-    base -= 1;
+    if (size == 0)
+    {
+        env.drop(2);
+        env.top(0).set_string("");
+        return;
+    }
+
+    // Adjust the start for our own use.
+    --start;
 
-    if ( unsigned(base+size) > str.length() )
+    if (static_cast<unsigned int>(start + size) > wstr.length())
     {
        IF_VERBOSE_ASCODING_ERRORS (
-       log_aserror(_("base+size goes beyond input string in ActionSubString, "
+               log_aserror(_("start + size goes beyond input string in 
ActionSubString, "
                "adjusting size"));
        );
-       size = str.length()-base;
+           size = wstr.length() - start;
     }
 
 
-    assert(base >= 0);
-    assert(unsigned(base) < str.length() );
+    assert(start >= 0);
+    assert(static_cast<unsigned int>(start) < wstr.length() );
     assert(size >= 0);
 
-    //log_debug(_("string: %s, size: %d, base: %d"), str.c_str(), size, base);
-
-    // Keep base within range.
-    //base = iclamp(base, 0, str.length());
-
-    // Truncate if necessary.
-    //size = imin(str.length() - base, size);
-
-    // TODO: unsafe: use string::substr instead !
-    std::string        new_string = str.c_str() + base; // XXX
-    new_string.resize(size);
-
     env.drop(2);
-    env.top(0).set_string(new_string);
+    env.top(0).set_string(utf8::encodeCanonicalString(
+                                    wstr.substr(start, size), version));
 }
 
 void
@@ -1769,7 +1772,7 @@
         start = 1;
     }
 
-    else if ( unsigned(start) > length )
+    else if ( start > length )
     {
        IF_VERBOSE_ASCODING_ERRORS (
        log_aserror(_("base goes beyond input string in ActionMbSubString, "




reply via email to

[Prev in Thread] Current Thread [Next in Thread]