Skip to content
Browse files

[Vector] For Vectors v["2.00"] is equivalent to v[2], unlike Arrays

See Tamarin as3/Vector/initializerExpressions.as
  • Loading branch information...
1 parent f1e20d4 commit 9acc5e543e45461ed7319ae724d0688712f09beb @aajanki aajanki committed Mar 14, 2013
Showing with 17 additions and 4 deletions.
  1. +1 −1 src/scripting/toplevel/Vector.cpp
  2. +15 −2 src/swftypes.cpp
  3. +1 −1 src/swftypes.h
View
2 src/scripting/toplevel/Vector.cpp
@@ -967,7 +967,7 @@ bool Vector::isValidMultiname(const multiname& name, uint32_t& index)
if(!name.ns[0].hasEmptyName())
return false;
- bool validIndex=name.toUInt(index);
+ bool validIndex=name.toUInt(index, true);
// Don't throw for non-numeric NAME_STRING or NAME_OBJECT
// because they can still be valid built-in property names.
if(!validIndex && (name.name_type==multiname::NAME_INT || name.name_type==multiname::NAME_NUMBER))
View
17 src/swftypes.cpp
@@ -145,7 +145,7 @@ void multiname::resetNameIfObject()
}
}
-bool multiname::toUInt(uint32_t& index) const
+bool multiname::toUInt(uint32_t& index, bool acceptStringFractions) const
{
switch(name_type)
{
@@ -164,7 +164,20 @@ bool multiname::toUInt(uint32_t& index) const
index=0;
for(auto i=str.begin(); i!=str.end(); ++i)
{
- if(!i.isdigit())
+ if (*i == '.' && acceptStringFractions)
+ {
+ if (i==str.begin())
+ return false;
+
+ // Accept fractional part if it
+ // is all zeros, e.g. "2.00"
+ ++i;
+ for (; i!=str.end(); ++i)
+ if (*i != '0')
+ return false;
+ return true;
+ }
+ else if(!i.isdigit())
return false;
index*=10;
View
2 src/swftypes.h
@@ -375,7 +375,7 @@ struct multiname: public memory_reporter
void setName(ASObject* n);
void resetNameIfObject();
bool isQName() const { return ns.size() == 1; }
- bool toUInt(uint32_t& out) const;
+ bool toUInt(uint32_t& out, bool acceptStringFractions=false) const;
};
class FLOAT

0 comments on commit 9acc5e5

Please sign in to comment.
Something went wrong with that request. Please try again.