Returns a copy of the string.
+### <a id="string-reverse"></a> String#reverse
+
+Signature:
+
+ function reverse();
+
+Returns a copy of the string in reverse order.
+
## <a id="array-type"></a> Array type
### <a id="array-add"></a> Array#add
Joins all elements of the array using the specified separator.
-## <a id="dictionary-type"></a> Dictionary type
+### <a id="array-reverse"></a> Array#reverse
+
+Signature:
+
+ function reverse();
+
+Returns a new array with all elements of the current array in reverse order.
### <a id="dictionary-shallow-clone"></a> Dictionary#shallow_clone
return result;
}
+static Array::Ptr ArrayReverse(void)
+{
+ ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
+ Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
+ return self->Reverse();
+}
+
Object::Ptr Array::GetPrototype(void)
{
static Dictionary::Ptr prototype;
prototype->Set("sort", new Function(WrapFunction(ArraySort), true));
prototype->Set("shallow_clone", new Function(WrapFunction(ArrayShallowClone), true));
prototype->Set("join", new Function(WrapFunction(ArrayJoin), true));
+ prototype->Set("reverse", new Function(WrapFunction(ArrayReverse), true));
}
return prototype;
return arr;
}
+Array::Ptr Array::Reverse(void) const
+{
+ Array::Ptr result = new Array();
+
+ ObjectLock olock(this);
+ ObjectLock xlock(result);
+
+ std::copy(m_Data.rbegin(), m_Data.rend(), std::back_inserter(result->m_Data));
+
+ return result;
+}
virtual Object::Ptr Clone(void) const override;
+ Array::Ptr Reverse(void) const;
+
private:
std::vector<Value> m_Data; /**< The data for the array. */
};
return self;
}
+static String StringReverse(void)
+{
+ ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
+ String self = vframe->Self;
+ return self.Reverse();
+}
Object::Ptr String::GetPrototype(void)
{
prototype->Set("find", new Function(WrapFunction(StringFind), true));
prototype->Set("contains", new Function(WrapFunction(StringContains), true));
prototype->Set("replace", new Function(WrapFunction(StringReplace), true));
+ prototype->Set("reverse", new Function(WrapFunction(StringReverse), true));
}
return prototype;
return t;
}
+ inline String Reverse(void) const
+ {
+ String t = m_Data;
+ std::reverse(t.m_Data.begin(), t.m_Data.end());
+ return t;
+ }
+
inline bool Contains(const String& str) const
{
return (m_Data.find(str) != std::string::npos);