gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog server/asobj/Global.cpp testsui...


From: Benjamin Wolsey
Subject: [Gnash-commit] gnash ChangeLog server/asobj/Global.cpp testsui...
Date: Wed, 30 Jan 2008 17:21:30 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Benjamin Wolsey <bwy>   08/01/30 17:21:29

Modified files:
        .              : ChangeLog 
        server/asobj   : Global.cpp 
        testsuite/actionscript.all: Global.as 

Log message:
                * testsuite/actionscript.all/Global.as: add tests showing fussy
                  behaviour with parseInt and octal numbers.
                * server/asobj/Global.cpp: use string::iterator instead of 
copying
                  strings, remove dead or inactive code, parse octal numbers
                  properly (compatibly, anyway). 

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5526&r2=1.5527
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/Global.cpp?cvsroot=gnash&r1=1.87&r2=1.88
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/Global.as?cvsroot=gnash&r1=1.39&r2=1.40

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.5526
retrieving revision 1.5527
diff -u -b -r1.5526 -r1.5527
--- ChangeLog   30 Jan 2008 16:07:49 -0000      1.5526
+++ ChangeLog   30 Jan 2008 17:21:28 -0000      1.5527
@@ -1,3 +1,11 @@
+2008-01-30 Benjamin Wolsey <address@hidden>
+
+       * testsuite/actionscript.all/Global.as: add tests showing fussy
+         behaviour with parseInt and octal numbers.
+       * server/asobj/Global.cpp: use string::iterator instead of copying
+         strings, remove dead or inactive code, parse octal numbers
+         properly (compatibly, anyway). 
+
 2008-01-30 Sandro Santilli <address@hidden>
 
        * gui/Player.cpp (load_movie): use the pseudo root url
@@ -16,6 +24,12 @@
 
 2008-01-30 Benjamin Wolsey <address@hidden>
 
+       * server/asobj/System.cpp: consts
+       * server/asobj: (various) drop 'using namespace std;' where it's not    
  
+         even used.
+       
+2008-01-30 Benjamin Wolsey <address@hidden>
+
        * server/vm/VM.cpp: let System.cpp decide what to do with the system
          language string.
        * server/asobj/System.cpp: restrict System.capabilites.language codes

Index: server/asobj/Global.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/Global.cpp,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -b -r1.87 -r1.88
--- server/asobj/Global.cpp     21 Jan 2008 20:55:55 -0000      1.87
+++ server/asobj/Global.cpp     30 Jan 2008 17:21:29 -0000      1.88
@@ -17,7 +17,7 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-/* $Id: Global.cpp,v 1.87 2008/01/21 20:55:55 rsavoye Exp $ */
+/* $Id: Global.cpp,v 1.88 2008/01/30 17:21:29 bwy Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "gnashconfig.h"
@@ -201,70 +201,34 @@
             log_aserror(_("%s has more than two arguments"), __FUNCTION__);
     )
 
-#if 0 // seems useless, will be done later
-    // Make sure our argument is the correct type
-    if (fn.nargs > 1)
-    {
-       fn.arg(1).convert_to_number(env);
-    }
-#endif
-
     const std::string& expr = fn.arg(0).to_string();
 
-    int base = 10; // the default base
-    
-    // Set up some variables
-    const string digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+    int base = 10;
+    const std::string digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+    bool bNegative = false;
 
-    // TODO: does all this copying make any sense ?
-    //       Use a std::string::iterator instead ?
-    boost::scoped_array<char> input_buffer ( new char[expr.size()+1] );
-    char *input = input_buffer.get();
-    strcpy(input, expr.c_str());
-    bool bNegative;
+    std::string::const_iterator it = expr.begin();
 
     // Skip leading whitespace
-    while( input[0] == ' ' || input[0] == '\n' || input[0] == '\t' || input[0] 
== '\r' )
+    while(*it == ' ' || *it == '\n' || *it == '\t' || *it == '\r')
     {
-        input++;
+        ++it;
     }
 
-    if (input[0] == '-')
+    // Is the first non-whitespace character a minus?
+    if (*it == '-')
        {
            bNegative = true;
-           input++;
+       ++it;
        }
-    else
-       bNegative = false;
-
-    // Convert the string to uppercase
-    for (int i=strlen(input)-1; i >= 0; i--)
-       input[i] = toupper(input[i]);
 
     // if we were sent a second argument, that's our base
     if (fn.nargs > 1)
        {
            // to_number returns a double. atoi() would be better
            base = (int)(fn.arg(1).to_number());
-       }
-    // if the string starts with "0x" then a hex digit
-    else if (strlen(input) > 2 && input[0] == '0' && input[1] == 'X'
-            && (isdigit(input[2]) || (input[2] >= 'A' && input[2] <= 'F')))
-       {
-           base = 16;  // the base is 16
-           input = input + 2; // skip the leading "0x"
-       }
-    // if the string starts with "0" then an octal digit
-    else if (strlen(input) > 1 && input[0] == '0' &&
-            (input[1] >= '0' && input[1] <= '7'))
-       {
-           base = 8;
-           input++; // skip the leading '0'
-       }
-    else
-       // default base is 10
-       assert(base == 10);
 
+       // Bases from 2 to 36 are valid, otherwise return NaN
     if (base < 2 || base > 36)
        {
            as_value rv;
@@ -272,33 +236,71 @@
            return rv;
        }
 
-    int numdigits = 0;
+    }
+
+    // If the string starts with '0x':
+    else if (expr.end() - it >= 2 &&
+               (*it == '0' && toupper(*(it + 1)) == 'X' ))
+    {
+        // the base is 16
+       base = 16;
+        // Move to the digit after the 'x'
+       it += 2; 
+    }
 
-    // Start at the beginning, see how many valid digits we have
-    // in the base we're dealing with
-    while (numdigits < int(strlen(input)) 
-          && int(digits.find(input[numdigits])) < base
-          && digits.find(input[numdigits]) != std::string::npos)
-       numdigits++;
+    // Octal if the string starts with "0" then an octal digit, but
+    // *only* if there is no whitespace before it; in that case decimal.
+    else if (it - expr.begin() == (bNegative ? 1 : 0))
+    {
+        if (expr.end() - it >= 2 && 
+               *it == '0' && isdigit(*(it + 1)))
+        {
+            // And if there are any chars other than 0-7, it's *still* a
+            // base 10 number...
+            // At least we know where we are in the string, so can use
+            // string methods.
+           if (expr.find_first_not_of("01234567", (bNegative ? 1 : 0)) !=
+               std::string::npos)
+           {
+               base = 10;
+           }
+           else base = 8;
 
-    // If we didn't get any digits, we should return NaN
-    if (numdigits == 0)
+           // Point the iterator to the first digit after the '0'.
+           ++it;
+
+        }
+    }
+
+    // Check to see if the first digit is valid, otherwise 
+    // return NaN.
+    int digit = digits.find(toupper(*it));
+
+    if (digit >= base)
        {
            as_value rv;
            rv.set_nan();
            return rv;
        }
 
-    int result = 0;
-    for (int i=0;i<numdigits;i++)
+    // The first digit was valid, so continue from the present position
+    // until we reach the end of the string or an invalid character,
+    // adding valid characters to our result.
+    // Which characters are invalid depends on the base. 
+    int result = digit;
+    ++it;
+    
+    while (it != expr.end() && (digit = digits.find(toupper(*it))) < base
+               && digit >= 0)
        {
-           result = result * base + digits.find(input[i]);
+           result = result * base + digit;
+           ++it;
        }
 
     if (bNegative)
        result = -result;
     
-    // Now return the parsed string
+    // Now return the parsed string as an integer.
     return as_value(result);
 }
 

Index: testsuite/actionscript.all/Global.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/Global.as,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -b -r1.39 -r1.40
--- testsuite/actionscript.all/Global.as        14 Jan 2008 20:50:46 -0000      
1.39
+++ testsuite/actionscript.all/Global.as        30 Jan 2008 17:21:29 -0000      
1.40
@@ -1,5 +1,5 @@
 // 
-//   Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
+//   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@
 // compile this test case with Ming makeswf, and then
 // execute it like this gnash -1 -r 0 -v out.swf
 
-rcsid="$Id: Global.as,v 1.39 2008/01/14 20:50:46 strk Exp $";
+rcsid="$Id: Global.as,v 1.40 2008/01/30 17:21:29 bwy Exp $";
 
 #include "check.as"
 
@@ -69,10 +69,18 @@
 check ( parseInt('-1.234') == -1 );
 // Test parseint with hex
 check ( parseInt('0x111') == 273 );
+check ( isNaN(parseInt('0xw')));
 // Test parseint with octal
-xcheck_equals (parseInt('   0352'), 352 );
-// a '0' prefix turns the number into an octal one ?
-xcheck (parseInt('   0352') != 0352 );
+check_equals (parseInt('0352'), 234 );
+check_equals (parseInt('-0352'), -234);
+// Evidently only numbers with no whitespace in front and
+// no digits higher than 7 are octal. These all decimal:
+check_equals (parseInt('07658'), 7658);
+check_equals (parseInt('   0352'), 352 );
+check_equals (parseInt('        -0352'), -352);
+check_equals (parseInt('03529A'), 3529);
+check_equals (parseInt('0352A'), 352);
+check_equals (parseInt('0352 '), 352);
 // Test parseint with 36 base
 check ( parseInt('2GA',36) == (10+16*36+2*36*36) );
 // Test parseint with base 17 - the 'H' is not part of base 17, only the first 
two digits are valid
@@ -269,15 +277,15 @@
 //------------------------------------------------------------
 
 #if OUTPUT_VERSION == 5
-       check_totals(50); // SWF5
+       check_totals(57); // SWF5
 #else
 # if OUTPUT_VERSION == 6
-       check_totals(84); // SWF6
+       check_totals(91); // SWF6
 # else
 #  if OUTPUT_VERSION == 7
-       check_totals(66); // SWF7
+       check_totals(73); // SWF7
 #  else
-       check_totals(53); // SWF8+
+       check_totals(60); // SWF8+
 #  endif
 # endif
 #endif




reply via email to

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