public static ArrayObject concat(Object thisob, VsaEngine engine, params Object[] args) { ArrayObject arrayObj = engine.GetOriginalArrayConstructor().Construct(); if (thisob is ArrayObject) { arrayObj.Concat((ArrayObject)thisob); } else { arrayObj.Concat(thisob); } for (int i = 0; i < args.Length; i++) { Object arg = args[i]; if (arg is ArrayObject) { arrayObj.Concat((ArrayObject)arg); } else { arrayObj.Concat(arg); } } return(arrayObj); }
public static ArrayObject concat(object thisob, VsaEngine engine, params object[] args) { ArrayObject obj2 = engine.GetOriginalArrayConstructor().Construct(); if (thisob is ArrayObject) { obj2.Concat((ArrayObject)thisob); } else { obj2.Concat(thisob); } for (int i = 0; i < args.Length; i++) { object obj3 = args[i]; if (obj3 is ArrayObject) { obj2.Concat((ArrayObject)obj3); } else { obj2.Concat(obj3); } } return(obj2); }
public static ArrayObject slice(Object thisob, VsaEngine engine, double start, Object end) { ArrayObject array = engine.GetOriginalArrayConstructor().Construct(); uint length = Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length")); // compute the start index long startIndex = Runtime.DoubleToInt64(Convert.ToInteger(start)); if (startIndex < 0) { startIndex = length + startIndex; if (startIndex < 0) { startIndex = 0; } } else if (startIndex > length) { startIndex = length; } // compute the end index long endIndex = length; if (end != null && !(end is Missing)) { endIndex = Runtime.DoubleToInt64(Convert.ToInteger(end)); if (endIndex < 0) { endIndex = length + endIndex; if (endIndex < 0) { endIndex = 0; } } else if (endIndex > length) { endIndex = length; } } // slice if (endIndex > startIndex) { array.length = endIndex - startIndex; for (ulong i = (ulong)startIndex, j = 0; i < (ulong)endIndex; i++, j++) { Object val = LateBinding.GetValueAtIndex(thisob, i); if (!(val is Missing)) { LateBinding.SetValueAtIndex(array, j, val); } } } return(array); }
public static ArrayObject slice(object thisob, VsaEngine engine, double start, object end) { ArrayObject obj2 = engine.GetOriginalArrayConstructor().Construct(); uint num = Microsoft.JScript.Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length")); long num2 = Runtime.DoubleToInt64(Microsoft.JScript.Convert.ToInteger(start)); if (num2 < 0L) { num2 = num + num2; if (num2 < 0L) { num2 = 0L; } } else if (num2 > num) { num2 = num; } long num3 = num; if ((end != null) && !(end is Missing)) { num3 = Runtime.DoubleToInt64(Microsoft.JScript.Convert.ToInteger(end)); if (num3 < 0L) { num3 = num + num3; if (num3 < 0L) { num3 = 0L; } } else if (num3 > num) { num3 = num; } } if (num3 > num2) { obj2.length = num3 - num2; ulong index = (ulong)num2; for (ulong i = 0L; index < num3; i += (ulong)1L) { object valueAtIndex = LateBinding.GetValueAtIndex(thisob, index); if (!(valueAtIndex is Missing)) { LateBinding.SetValueAtIndex(obj2, i, valueAtIndex); } index += (ulong)1L; } } return(obj2); }
public static ArrayObject split(Object thisob, VsaEngine engine, Object separator, Object limit) { String thisStr = Convert.ToString(thisob); uint limitValue = UInt32.MaxValue; if (limit != null && !(limit is Missing) && limit != DBNull.Value) { double lmt = Convert.ToInteger(limit); if (lmt >= 0 && lmt < UInt32.MaxValue) { limitValue = (uint)lmt; } } if (limitValue == 0) { return((ArrayObject)engine.GetOriginalArrayConstructor().Construct()); } if (separator == null || separator is Missing) { ArrayObject array = (ArrayObject)engine.GetOriginalArrayConstructor().Construct(); array.SetValueAtIndex(0, thisob); return(array); } RegExpObject regExpObject = separator as RegExpObject; if (regExpObject != null) { return(StringPrototype.SplitWithRegExp(thisStr, engine, regExpObject, limitValue)); } Regex regex = separator as Regex; if (regex != null) { return(StringPrototype.SplitWithRegExp(thisStr, engine, new RegExpObject(regex), limitValue)); } return(StringPrototype.SplitWithString(thisStr, engine, Convert.ToString(separator), limitValue)); }
public static ArrayObject split(object thisob, VsaEngine engine, object separator, object limit) { string str = Microsoft.JScript.Convert.ToString(thisob); uint maxValue = uint.MaxValue; if (((limit != null) && !(limit is Missing)) && (limit != DBNull.Value)) { double num2 = Microsoft.JScript.Convert.ToInteger(limit); if ((num2 >= 0.0) && (num2 < 4294967295)) { maxValue = (uint)num2; } } if (maxValue == 0) { return(engine.GetOriginalArrayConstructor().Construct()); } if ((separator == null) || (separator is Missing)) { ArrayObject obj2 = engine.GetOriginalArrayConstructor().Construct(); obj2.SetValueAtIndex(0, thisob); return(obj2); } RegExpObject regExpObject = separator as RegExpObject; if (regExpObject != null) { return(SplitWithRegExp(str, engine, regExpObject, maxValue)); } Regex regex = separator as Regex; if (regex != null) { return(SplitWithRegExp(str, engine, new RegExpObject(regex), maxValue)); } return(SplitWithString(str, engine, Microsoft.JScript.Convert.ToString(separator), maxValue)); }
internal virtual ArrayObject toArray(VsaEngine engine) { IList array = this.array; ArrayObject obj2 = engine.GetOriginalArrayConstructor().Construct(); uint num = 0; int count = array.Count; IEnumerator enumerator = array.GetEnumerator(); obj2.length = count; while (enumerator.MoveNext()) { obj2.SetValueAtIndex(num++, enumerator.Current); } return(obj2); }
internal virtual ArrayObject toArray(VsaEngine engine) { IList aList = this.array; ArrayObject result = engine.GetOriginalArrayConstructor().Construct(); uint i = 0; int n = aList.Count; IEnumerator e = aList.GetEnumerator(); result.length = n; while (e.MoveNext()) { result.SetValueAtIndex(i++, e.Current); } return(result); }
private static ArrayObject SplitWithRegExp(String thisob, VsaEngine engine, RegExpObject regExpObject, uint limit) { ArrayObject array = (ArrayObject)engine.GetOriginalArrayConstructor().Construct(); Match match = regExpObject.regex.Match(thisob); if (!match.Success) { array.SetValueAtIndex(0, thisob); regExpObject.lastIndexInt = 0; return(array); } Match lastMatch; int prevIndex = 0; uint i = 0; do { int len = match.Index - prevIndex; if (len > 0) { array.SetValueAtIndex(i++, thisob.Substring(prevIndex, len)); if (limit > 0 && i >= limit) { regExpObject.lastIndexInt = regExpObject.regExpConst.UpdateConstructor(regExpObject.regex, match, thisob); return(array); } } prevIndex = match.Index + match.Length; lastMatch = match; match = match.NextMatch(); }while(match.Success); if (prevIndex < thisob.Length) { array.SetValueAtIndex(i, thisob.Substring(prevIndex)); } regExpObject.lastIndexInt = regExpObject.regExpConst.UpdateConstructor(regExpObject.regex, lastMatch, thisob); return(array); }
private static ArrayObject SplitWithString(String thisob, VsaEngine engine, String separator, uint limit) { ArrayObject array = (ArrayObject)engine.GetOriginalArrayConstructor().Construct(); if (separator.Length == 0) { if (limit > thisob.Length) { limit = (uint)thisob.Length; } for (int i = 0; i < limit; i++) { array.SetValueAtIndex((uint)i, thisob[i].ToString()); } } else { int prevIndex = 0; uint i = 0; int index; while ((index = thisob.IndexOf(separator, prevIndex)) >= 0) { array.SetValueAtIndex(i++, thisob.Substring(prevIndex, index - prevIndex)); if (i >= limit) { return(array); } prevIndex = index + separator.Length; } if (i == 0) { array.SetValueAtIndex(0, thisob); } else { array.SetValueAtIndex(i, thisob.Substring(prevIndex)); } } return(array); }
private static ArrayObject SplitWithRegExp(string thisob, VsaEngine engine, RegExpObject regExpObject, uint limit) { Match match2; ArrayObject obj2 = engine.GetOriginalArrayConstructor().Construct(); Match match = regExpObject.regex.Match(thisob); if (!match.Success) { obj2.SetValueAtIndex(0, thisob); regExpObject.lastIndexInt = 0; return(obj2); } int startIndex = 0; uint index = 0; do { int length = match.Index - startIndex; if (length > 0) { obj2.SetValueAtIndex(index++, thisob.Substring(startIndex, length)); if ((limit > 0) && (index >= limit)) { regExpObject.lastIndexInt = regExpObject.regExpConst.UpdateConstructor(regExpObject.regex, match, thisob); return(obj2); } } startIndex = match.Index + match.Length; match2 = match; match = match.NextMatch(); }while (match.Success); if (startIndex < thisob.Length) { obj2.SetValueAtIndex(index, thisob.Substring(startIndex)); } regExpObject.lastIndexInt = regExpObject.regExpConst.UpdateConstructor(regExpObject.regex, match2, thisob); return(obj2); }
private static ArrayObject SplitWithString(string thisob, VsaEngine engine, string separator, uint limit) { int num4; ArrayObject obj2 = engine.GetOriginalArrayConstructor().Construct(); if (separator.Length == 0) { if (limit > thisob.Length) { limit = (uint)thisob.Length; } for (int i = 0; i < limit; i++) { obj2.SetValueAtIndex((uint)i, thisob[i].ToString()); } return(obj2); } int startIndex = 0; uint index = 0; while ((num4 = thisob.IndexOf(separator, startIndex)) >= 0) { obj2.SetValueAtIndex(index++, thisob.Substring(startIndex, num4 - startIndex)); if (index >= limit) { return(obj2); } startIndex = num4 + separator.Length; } if (index == 0) { obj2.SetValueAtIndex(0, thisob); return(obj2); } obj2.SetValueAtIndex(index, thisob.Substring(startIndex)); return(obj2); }
public static ArrayObject splice(Object thisob, VsaEngine engine, double start, double deleteCnt, params Object[] args) { uint oldLength = Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length")); // compute the start index long startIndex = Runtime.DoubleToInt64(Convert.ToInteger(start)); if (startIndex < 0) { startIndex = oldLength + startIndex; if (startIndex < 0) { startIndex = 0; } } else if (startIndex > oldLength) { startIndex = oldLength; } // compute the number of items to delete long deleteCount = Runtime.DoubleToInt64(Convert.ToInteger(deleteCnt)); if (deleteCount < 0) { deleteCount = 0; } else if (deleteCount > oldLength - startIndex) { deleteCount = oldLength - startIndex; } long newLength = oldLength + args.Length - deleteCount; // create an array for the result ArrayObject result = engine.GetOriginalArrayConstructor().Construct(); result.length = deleteCount; // special case array objects (nice speedup if dense) if (thisob is ArrayObject) { ((ArrayObject)thisob).Splice((uint)startIndex, (uint)deleteCount, args, result, (uint)oldLength, (uint)newLength); return(result); } // copy the deleted items to the result array for (ulong i = 0; i < (ulong)deleteCount; i++) { result.SetValueAtIndex((uint)i, LateBinding.GetValueAtIndex(thisob, i + (ulong)startIndex)); } // shift the remaining elements left or right long n = oldLength - startIndex - deleteCount; if (newLength < oldLength) { for (long i = 0; i < n; i++) { LateBinding.SetValueAtIndex(thisob, (ulong)(i + startIndex + args.Length), LateBinding.GetValueAtIndex(thisob, (ulong)(i + startIndex + deleteCount))); } LateBinding.SetMemberValue(thisob, "length", newLength); } else { LateBinding.SetMemberValue(thisob, "length", newLength); for (long i = n - 1; i >= 0; i--) { LateBinding.SetValueAtIndex(thisob, (ulong)(i + startIndex + args.Length), LateBinding.GetValueAtIndex(thisob, (ulong)(i + startIndex + deleteCount))); } } // splice in the arguments int m = args == null ? 0 : args.Length; for (uint i = 0; i < m; i++) { LateBinding.SetValueAtIndex(thisob, i + (ulong)startIndex, args[i]); } return(result); }
public static ArrayObject splice(object thisob, VsaEngine engine, double start, double deleteCnt, params object[] args) { uint oldLength = Microsoft.JScript.Convert.ToUint32(LateBinding.GetMemberValue(thisob, "length")); long num2 = Runtime.DoubleToInt64(Microsoft.JScript.Convert.ToInteger(start)); if (num2 < 0L) { num2 = oldLength + num2; if (num2 < 0L) { num2 = 0L; } } else if (num2 > oldLength) { num2 = oldLength; } long num3 = Runtime.DoubleToInt64(Microsoft.JScript.Convert.ToInteger(deleteCnt)); if (num3 < 0L) { num3 = 0L; } else if (num3 > (oldLength - num2)) { num3 = oldLength - num2; } long num4 = (oldLength + args.Length) - num3; ArrayObject outArray = engine.GetOriginalArrayConstructor().Construct(); outArray.length = num3; if (thisob is ArrayObject) { ((ArrayObject)thisob).Splice((uint)num2, (uint)num3, args, outArray, oldLength, (uint)num4); return(outArray); } for (ulong i = 0L; i < num3; i += (ulong)1L) { outArray.SetValueAtIndex((uint)i, LateBinding.GetValueAtIndex(thisob, i + ((ulong)num2))); } long num6 = (oldLength - num2) - num3; if (num4 < oldLength) { for (long k = 0L; k < num6; k += 1L) { LateBinding.SetValueAtIndex(thisob, (ulong)((k + num2) + args.Length), LateBinding.GetValueAtIndex(thisob, (ulong)((k + num2) + num3))); } LateBinding.SetMemberValue(thisob, "length", num4); } else { LateBinding.SetMemberValue(thisob, "length", num4); for (long m = num6 - 1L; m >= 0L; m -= 1L) { LateBinding.SetValueAtIndex(thisob, (ulong)((m + num2) + args.Length), LateBinding.GetValueAtIndex(thisob, (ulong)((m + num2) + num3))); } } int num9 = (args == null) ? 0 : args.Length; for (uint j = 0; j < num9; j++) { LateBinding.SetValueAtIndex(thisob, (ulong)(j + num2), args[j]); } return(outArray); }