[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r11597: Naive implementation of Text
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r11597: Naive implementation of TextField.replaceText. Enough to XPASS 4 swfdec testcases and a bunch of custom ones added to TextField.as. Does utf8, should take care of registered text variables but isn't tested. |
Date: |
Tue, 03 Nov 2009 23:43:22 +0100 |
User-agent: |
Bazaar (1.16.1) |
------------------------------------------------------------
revno: 11597
committer: Sandro Santilli <address@hidden>
branch nick: trunk
timestamp: Tue 2009-11-03 23:43:22 +0100
message:
Naive implementation of TextField.replaceText. Enough to XPASS 4 swfdec
testcases and a bunch of custom ones added to TextField.as. Does utf8, should
take care of registered text variables but isn't tested.
modified:
libcore/TextField.cpp
testsuite/actionscript.all/TextField.as
testsuite/swfdec/PASSING
=== modified file 'libcore/TextField.cpp'
--- a/libcore/TextField.cpp 2009-10-26 08:41:46 +0000
+++ b/libcore/TextField.cpp 2009-11-03 22:43:22 +0000
@@ -3647,10 +3647,78 @@
as_value
textfield_replaceText(const fn_call& fn)
{
+ using std::string;
+ using std::wstring;
+
boost::intrusive_ptr<TextField> text = ensure<ThisIs<TextField> >(fn);
- UNUSED(text);
-
- LOG_ONCE(log_unimpl("TextField.replaceText()"));
+
+ if ( fn.nargs < 3 )
+ {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror(_("TextField.replaceText() called with less than 3 args"));
+ )
+ return as_value();
+ }
+
+ int userEnd = fn.arg(1).to_int();
+ if ( userEnd < 0 )
+ {
+ IF_VERBOSE_ASCODING_ERRORS(
+ std::stringstream ss; fn.dump_args(ss);
+ log_aserror("TextField.replaceText(%s): negative endIndex"
+ " - doing nothing", ss.str());
+ );
+ return as_value();
+ }
+
+ wstring::size_type start = fn.arg(0).to_int();
+ wstring::size_type end = userEnd;
+
+ int version = getSWFVersion(*text);
+
+ // TODO: check if it's possible for SWF6 to use this function
+ // and if it is whether to_string should be to_string_versioned
+ // (affects the way undefined values are considered)
+ const wstring& replacement =
+ utf8::decodeCanonicalString(fn.arg(2).to_string(), version);
+
+ // TODO: drop this round uf8 encoding and decoding by exposing
+ // a TextField::getTextValue ?
+ const wstring& subject =
+ utf8::decodeCanonicalString(text->get_text_value(), version);
+
+ if ( start > subject.length() )
+ {
+ IF_VERBOSE_ASCODING_ERRORS(
+ std::stringstream ss; fn.dump_args(ss);
+ log_aserror("TextField.replaceText(%s): beginIndex out of range"
+ " - doing nothing", ss.str());
+ );
+ return as_value();
+ }
+
+
+ // TODO: use STL proper
+ wstring newstring;
+ if ( start ) newstring = subject.substr(0, start);
+ newstring.append(replacement);
+
+ if ( end > subject.length() )
+ {
+ //log_aserror...
+ IF_VERBOSE_ASCODING_ERRORS(
+ std::stringstream ss; fn.dump_args(ss);
+ log_aserror("TextField.replaceText(%s): endIndex out of range"
+ " - taking as end of string", ss.str());
+ );
+ }
+ else
+ {
+ newstring.append(subject.substr(end));
+ }
+
+ // TODO: check if we should really be updating registered variables
+ text->setTextValue(newstring);
return as_value();
}
=== modified file 'testsuite/actionscript.all/TextField.as'
--- a/testsuite/actionscript.all/TextField.as 2009-11-03 20:46:19 +0000
+++ b/testsuite/actionscript.all/TextField.as 2009-11-03 22:43:22 +0000
@@ -1101,6 +1101,47 @@
check_equals(Selection.getEndIndex(), 5);
//------------------------------------------------------------
+// Test TextField.replaceText
+//------------------------------------------------------------
+
+#if OUTPUT_VERSION > 6
+createTextField ("t", 0, 0, 0, 200, 150);
+check_equals(t.text, '');
+r = t.replaceText();
+check_equals(typeof(r), 'undefined');
+check_equals(t.text, '');
+r = t.replaceText(0, 0);
+check_equals(typeof(r), 'undefined');
+check_equals(t.text, '');
+r = t.replaceText(0, 0, 'a');
+check_equals(typeof(r), 'undefined');
+check_equals(t.text, 'a');
+r = t.replaceText(0, 0, 'b');
+check_equals(t.text, 'ba');
+t.replaceText(-1, 0, 'c');
+check_equals(t.text, 'ba');
+t.replaceText(0, 5, 'd');
+check_equals(t.text, 'd');
+t.replaceText(-1, 5, 'e');
+check_equals(t.text, 'd');
+t.replaceText(1, 5, 'f');
+check_equals(t.text, 'df');
+t.replaceText(0, 5, 'ϦeϦ');
+check_equals(t.text, 'ϦeϦ');
+t.replaceText(1, 1, 'h');
+check_equals(t.text, 'ϦheϦ');
+t.replaceText(4, 4, 'h');
+check_equals(t.text, 'ϦheϦh');
+t.replaceText(4, 4, undef);
+check_equals(t.text, 'ϦheϦundefinedh');
+t.replaceText(3, 10, 't');
+check_equals(t.text, 'Ϧhetnedh');
+t.replaceText(3, -1, 'y');
+check_equals(t.text, 'Ϧhetnedh');
+// TODO: check registered variables
+#endif
+
+//------------------------------------------------------------
// Test properties
//------------------------------------------------------------
@@ -1235,9 +1276,9 @@
#if OUTPUT_VERSION == 6
check_totals(520);
#elif OUTPUT_VERSION == 7
- check_totals(526);
+ check_totals(544);
#elif OUTPUT_VERSION == 8
- check_totals(527);
+ check_totals(545);
#endif
#endif
=== modified file 'testsuite/swfdec/PASSING'
--- a/testsuite/swfdec/PASSING 2009-10-26 08:58:13 +0000
+++ b/testsuite/swfdec/PASSING 2009-11-03 22:43:22 +0000
@@ -310,6 +310,8 @@
crash-0.5.90-empty-action.swf:c564ca09c4bc71fb89b042bc07d247eb
crash-0.6.2-replaceText-5.swf:f9a3132918e7d3daaca3bb8122b8b847
crash-0.6.2-replaceText-6.swf:26a8a906a7ab6dc2411d0c72d84cbdfa
+crash-0.6.2-replaceText-7.swf:da9ccc92ab99681f702edc62d143edf7
+crash-0.6.2-replaceText-8.swf:569cae4f87d6748fb8e10ef807bc43a5
crash-0.6.2-try-and-exception-on-dispose-5.swf:8f84852b71f51a23f9e13ddfdfc2a2c5
crash-0.6.2-try-and-exception-on-dispose-6.swf:d38fff4fefc1cdce2acd57e86fdce995
crash-0.6.2-try-and-exception-on-dispose-7.swf:25f0b3acc112898018b1636cc1817cc9
@@ -352,6 +354,8 @@
crash-0.7.1-uncompressed-half-samples-8.swf:8043058b7c22459d2f8ef3f69884cf04
crash-0.7.2-TextField-replace-infloop-5.swf:f36e906743e23c4918becdb34d6c08cf
crash-0.7.2-TextField-replace-infloop-6.swf:a75b13bb89ab3f2fc673ba2af3fa856f
+crash-0.7.2-TextField-replace-infloop-7.swf:0ad8fff952c056d4cbbf2baeb449c1b7
+crash-0.7.2-TextField-replace-infloop-8.swf:9d5677d123c2b1b2ef48730214341404
crash-0.7.5-draw-on-disposed-bitmap-5.swf:073596b26cce990e4a32088da6c19f4c
crash-0.7.5-draw-on-disposed-bitmap-6.swf:63105692441eb2330261237f05b02d32
crash-0.7.5-draw-on-disposed-bitmap-7.swf:b1b51478084d0c203e9c1b19ea1c8552
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r11597: Naive implementation of TextField.replaceText. Enough to XPASS 4 swfdec testcases and a bunch of custom ones added to TextField.as. Does utf8, should take care of registered text variables but isn't tested.,
Sandro Santilli <=