gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r10667: More implementation and test


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r10667: More implementation and testing of TextSnapshot. Rename some types and
Date: Fri, 06 Mar 2009 10:57:27 +0100
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 10667
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Fri 2009-03-06 10:57:27 +0100
message:
  More implementation and testing of TextSnapshot. Rename some types and
  make style more consistent.
modified:
  libcore/asobj/TextSnapshot_as.cpp
  libcore/asobj/TextSnapshot_as.h
  libcore/debugger.cpp
  libcore/parser/action_buffer.cpp
  libcore/vm/ASHandlers.cpp
  libcore/vm/ASHandlers.h
  libcore/vm/fn_call.h
  testsuite/actionscript.all/TextSnapshot.as
  testsuite/misc-ming.all/TextSnapshotTest.c
    ------------------------------------------------------------
    revno: 10659.1.14
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Thu 2009-03-05 17:00:37 +0100
    message:
      Drop typedef from fn_call.h.
    modified:
      libcore/vm/fn_call.h
    ------------------------------------------------------------
    revno: 10659.1.15
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Thu 2009-03-05 17:57:54 +0100
    message:
      Rename and re-scope some types.
    modified:
      libcore/debugger.cpp
      libcore/parser/action_buffer.cpp
      libcore/vm/ASHandlers.cpp
      libcore/vm/ASHandlers.h
    ------------------------------------------------------------
    revno: 10659.1.16
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2009-03-06 07:44:40 +0100
    message:
      Implement TextSnapshot.findText().
    modified:
      libcore/asobj/TextSnapshot_as.cpp
      libcore/asobj/TextSnapshot_as.h
      testsuite/actionscript.all/TextSnapshot.as
    ------------------------------------------------------------
    revno: 10659.1.17
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2009-03-06 07:57:05 +0100
    message:
      Corrections to findText implementation.
    modified:
      libcore/asobj/TextSnapshot_as.cpp
      testsuite/misc-ming.all/TextSnapshotTest.c
=== modified file 'libcore/asobj/TextSnapshot_as.cpp'
--- a/libcore/asobj/TextSnapshot_as.cpp 2009-03-05 15:30:33 +0000
+++ b/libcore/asobj/TextSnapshot_as.cpp 2009-03-06 06:57:05 +0000
@@ -31,6 +31,7 @@
 #include "generic_character.h"
 #include "DisplayList.h"
 #include "MovieClip.h"
+#include "StringPredicates.h"
 
 #include <algorithm>
 
@@ -133,6 +134,31 @@
 
 }
 
+boost::int32_t
+TextSnapshot_as::findText(boost::int32_t start, const std::string& text,
+        bool ignoreCase) const
+{
+
+    if (start < 0 || text.empty()) return -1;
+
+    std::string snapshot;
+    makeString(snapshot);
+
+    const std::string::size_type len = snapshot.size();
+
+    // Don't try to search if start is past the end of the string.
+    if (len < static_cast<size_t>(start)) return -1;
+
+    if (ignoreCase) {
+        std::string::const_iterator it = std::search(snapshot.begin() + start,
+                snapshot.end(), text.begin(), text.end(), boost::is_iequal());
+        return (it == snapshot.end()) ? -1 : it - snapshot.begin();
+    }
+
+    std::string::size_type pos = snapshot.find(text, start);
+    return (pos == std::string::npos) ? -1 : pos;
+
+}
 
 void
 TextSnapshot_as::init(as_object& global)
@@ -193,9 +219,30 @@
     log_unimpl (__FUNCTION__);
     return as_value();
 }
-as_value textsnapshot_findText(const fn_call& /*fn*/) {
-    log_unimpl (__FUNCTION__);
-    return as_value();
+
+as_value
+textsnapshot_findText(const fn_call& fn)
+{
+    boost::intrusive_ptr<TextSnapshot_as> ts =
+        ensureType<TextSnapshot_as>(fn.this_ptr);
+    
+    if (!ts->valid()) return as_value();
+
+    if (fn.nargs != 3) {
+        IF_VERBOSE_ASCODING_ERRORS(
+            log_aserror("TextSnapshot.findText() requires 3 arguments");
+        );
+        return as_value();
+    }
+
+    boost::int32_t start = fn.arg(0).to_int();
+    const std::string& text = fn.arg(1).to_string();
+
+    /// Yes, the pp is case-insensitive by default. We don't write
+    /// functions like that here.
+    bool ignoreCase = !fn.arg(2).to_bool();
+
+    return ts->findText(start, text, ignoreCase);
 }
 
 as_value
@@ -206,10 +253,9 @@
     
     if (!ts->valid()) return as_value();
 
-    if (fn.nargs)
-    {
+    if (fn.nargs) {
         IF_VERBOSE_ASCODING_ERRORS(
-            log_aserror("TextSnapshot.getCount takes no arguments");
+            log_aserror("TextSnapshot.getCount() takes no arguments");
         );
         return as_value();
     }

=== modified file 'libcore/asobj/TextSnapshot_as.h'
--- a/libcore/asobj/TextSnapshot_as.h   2009-03-05 15:30:33 +0000
+++ b/libcore/asobj/TextSnapshot_as.h   2009-03-06 06:44:40 +0000
@@ -46,6 +46,9 @@
     const std::string getText(boost::int32_t start, boost::int32_t end,
             bool nl) const;
 
+    boost::int32_t findText(boost::int32_t start, const std::string& text,
+            bool ignoreCase) const;
+
     static void init(as_object& global);
 
     static void construct(const std::string& snapshot);

=== modified file 'libcore/debugger.cpp'
--- a/libcore/debugger.cpp      2009-01-22 20:10:39 +0000
+++ b/libcore/debugger.cpp      2009-03-05 16:57:54 +0000
@@ -325,7 +325,7 @@
 Debugger::disassemble(const unsigned char *data)
 {
 //    GNASH_REPORT_FUNCTION;
-    as_arg_t fmt = ARG_HEX;
+    ArgumentType = ARG_HEX;
     ActionType action_id = static_cast<ActionType>(data[0]);
     int val = 0;
     string str;

=== modified file 'libcore/parser/action_buffer.cpp'
--- a/libcore/parser/action_buffer.cpp  2009-01-22 20:10:39 +0000
+++ b/libcore/parser/action_buffer.cpp  2009-03-05 16:57:54 +0000
@@ -174,7 +174,7 @@
 
     assert (maxBufferLength > 0);
 
-    as_arg_t fmt = ARG_HEX;
+    ArgumentType fmt = ARG_HEX;
     ActionType action_id = static_cast<ActionType>(instruction_data[0]);
 
     std::stringstream ss;

=== modified file 'libcore/vm/ASHandlers.cpp'
--- a/libcore/vm/ASHandlers.cpp 2009-02-10 15:38:43 +0000
+++ b/libcore/vm/ASHandlers.cpp 2009-03-05 16:57:54 +0000
@@ -118,7 +118,7 @@
 {
 }
 
-ActionHandler::ActionHandler(ActionType type, action_callback_t func)
+ActionHandler::ActionHandler(ActionType type, ActionCallback func)
     :
     _type(type),
     _callback(func),
@@ -128,7 +128,7 @@
 }
 
 ActionHandler::ActionHandler(ActionType type, std::string name,
-                             action_callback_t func)
+                             ActionCallback func)
     :
     _type(type),
     _name(name),
@@ -139,7 +139,7 @@
 }
 
 ActionHandler::ActionHandler(ActionType type, std::string name,
-                             action_callback_t func, as_arg_t format)
+                             ActionCallback func, ArgumentType format)
     :
     _type(type),
     _name(name),

=== modified file 'libcore/vm/ASHandlers.h'
--- a/libcore/vm/ASHandlers.h   2009-01-22 20:10:39 +0000
+++ b/libcore/vm/ASHandlers.h   2009-03-05 16:57:54 +0000
@@ -33,7 +33,7 @@
 
 namespace SWF { // gnash::SWF
 
-typedef enum {
+enum ArgumentType {
     ARG_NONE = 0,
     ARG_STR,
     // default hex dump, in case the format is unknown or unsupported
@@ -44,27 +44,27 @@
     ARG_PUSH_DATA,
     ARG_DECL_DICT,
     ARG_FUNCTION2
-} as_arg_t;
+};
 
-typedef enum {
+enum as_encoding_guess_t {
     ENCGUESS_UNICODE = 0,
     ENCGUESS_JIS = 1,
     ENCGUESS_OTHER = 2
-} as_encoding_guess_t;
+};
 
-// @@strk@@ should we move this to .cpp file ? it's only
-// use is within SWFHandlers, anyway...
-typedef void (*action_callback_t)(ActionExec& thread);
 
 class ActionHandler
 {
+    typedef void (*ActionCallback)(ActionExec& thread);
+
 public:
+
     ActionHandler();
-    ActionHandler(ActionType type, action_callback_t func);
-    ActionHandler(ActionType type, std::string name, 
-                  action_callback_t func);
-    ActionHandler(ActionType type, std::string name, 
-                  action_callback_t func, as_arg_t format);
+    ActionHandler(ActionType type, ActionCallback func);
+    ActionHandler(ActionType type, std::string name, 
+                  ActionCallback func);
+    ActionHandler(ActionType type, std::string name, 
+                  ActionCallback func, ArgumentType format);
 
     /// Execute the action
     void execute(ActionExec& thread) const;
@@ -72,13 +72,14 @@
     void toggleDebug(bool state) const { _debug = state; }
     ActionType getType()   const { return _type; }
     std::string getName()   const { return _name; }
-    as_arg_t getArgFormat() const { return _arg_format; }
+    ArgumentType getArgFormat() const { return _arg_format; }
+
 private:
-    ActionType       _type;
-    std::string       _name;
-    action_callback_t _callback;
-    mutable bool      _debug;
-    as_arg_t          _arg_format;
+    ActionType _type;
+    std::string _name;
+    ActionCallback _callback;
+    mutable bool _debug;
+    ArgumentType _arg_format;
 };
 
 /// A singleton containing the supported SWF Action handlers.

=== modified file 'libcore/vm/fn_call.h'
--- a/libcore/vm/fn_call.h      2009-03-02 12:12:15 +0000
+++ b/libcore/vm/fn_call.h      2009-03-05 16:00:37 +0000
@@ -207,10 +207,6 @@
 
 };
 
-/// Signature of a builtin function callable from ActionScript
-typedef as_value (*as_c_function_ptr)(const fn_call& fn);
-
-
 } // namespace gnash
 
 

=== modified file 'testsuite/actionscript.all/TextSnapshot.as'
--- a/testsuite/actionscript.all/TextSnapshot.as        2009-03-05 15:30:33 
+0000
+++ b/testsuite/actionscript.all/TextSnapshot.as        2009-03-06 06:44:40 
+0000
@@ -116,31 +116,31 @@
  check_equals(typeof(ts.findText(1, "a")), "undefined");
 
  // Test with no text.
- xcheck_equals(typeof(ts.findText(1, "a", true)), "number");
- xcheck_equals(typeof(ts.findText(1, "a", 1)), "number");
- xcheck_equals(typeof(ts.findText(1, "a", new Date())), "number");
- xcheck_equals(typeof(ts.findText("6", "a", new Date())), "number");
- xcheck_equals(typeof(ts.findText("b", "a", new Date())), "number");
- xcheck_equals(typeof(ts.findText(-1, "a", new Date())), "number");
- xcheck_equals(typeof(ts.findText(Infinity, "a", new Date())), "number");
+ check_equals(typeof(ts.findText(1, "a", true)), "number");
+ check_equals(typeof(ts.findText(1, "a", 1)), "number");
+ check_equals(typeof(ts.findText(1, "a", new Date())), "number");
+ check_equals(typeof(ts.findText("6", "a", new Date())), "number");
+ check_equals(typeof(ts.findText("b", "a", new Date())), "number");
+ check_equals(typeof(ts.findText(-1, "a", new Date())), "number");
+ check_equals(typeof(ts.findText(Infinity, "a", new Date())), "number");
  check_equals(typeof(ts.findText(-1, "a", new Date(), "e")), "undefined");
  check_equals(typeof(ts.findText(Infinity, "a", new Date(), 3)), "undefined");
 
- xcheck_equals(ts.findText(1, "a", true), -1);
- xcheck_equals(ts.findText(1, "a", 1), -1);
- xcheck_equals(ts.findText(1, "a", new Date()), -1);
- xcheck_equals(ts.findText("6", "a", false), -1);
- xcheck_equals(ts.findText("b", "a", true), -1);
- xcheck_equals(ts.findText(-1, "a", new Date()), -1);
- xcheck_equals(ts.findText(Infinity, "a", new Date()), -1);
+ check_equals(ts.findText(1, "a", true), -1);
+ check_equals(ts.findText(1, "a", 1), -1);
+ check_equals(ts.findText(1, "a", new Date()), -1);
+ check_equals(ts.findText("6", "a", false), -1);
+ check_equals(ts.findText("b", "a", true), -1);
+ check_equals(ts.findText(-1, "a", new Date()), -1);
+ check_equals(ts.findText(Infinity, "a", new Date()), -1);
 
  // Shouldn't work with dynamic text.
  _root.createTextField("tf", 10, 30, 30, 100, 100);
  _root.tf.text = "ghjkab";
  ts = _root.getTextSnapshot();
  check_equals(ts.getCount(), 0);
- xcheck_equals(ts.findText(1, "a", true), -1);
- xcheck_equals(ts.findText(1, "a", false), -1);
+ check_equals(ts.findText(1, "a", true), -1);
+ check_equals(ts.findText(1, "a", false), -1);
 
  // getSelected
 

=== modified file 'testsuite/misc-ming.all/TextSnapshotTest.c'
--- a/testsuite/misc-ming.all/TextSnapshotTest.c        2009-03-05 15:30:33 
+0000
+++ b/testsuite/misc-ming.all/TextSnapshotTest.c        2009-03-06 06:57:05 
+0000
@@ -143,6 +143,19 @@
   check_equals(mo, "ts.getText(0, 100, true)", 
           "'First text\nZweites Textfeld\nSome more "
                  "static text here... abcdefgh'");
+  
+  xcheck_equals(mo, "ts.getText(0, 14, true)", "'First text\nZwei'");
+
+  check_equals(mo, "ts.findText(0, '', false)", "-1");
+  check_equals(mo, "ts.findText(0, 'f', false)", "0");
+  check_equals(mo, "ts.findText(0, 'f', true)", "22");
+  check_equals(mo, "ts.findText(1, 'Rst', false)", "2");
+  check_equals(mo, "ts.findText(3, 'RSt', false)", "-1");
+  check_equals(mo, "ts.findText(100, 'h', false)", "-1");
+  check_equals(mo, "ts.findText(64, 'h', false)", "-1");
+  check_equals(mo, "ts.findText(-5, 'Zwei', true)", "-1");
+  check_equals(mo, "ts.findText(-5, 'gh', true)", "-1");
+
 
   add_actions(mo, "ts.setSelected(0, 30, true);");
 


reply via email to

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