static private ToInteger ( Object value ) : double | ||
value | Object | |
Результат | double |
public static String toExponential(Object thisob, Object fractionDigits) { double value = NumberPrototype.ThisobToDouble(thisob); double f; if (fractionDigits == null || fractionDigits is Missing) { f = 16; } else { f = Convert.ToInteger(fractionDigits); } if (f < 0 || f > 20) { throw new JScriptException(JSError.FractionOutOfRange); } StringBuilder fmt = new StringBuilder("#."); for (int i = 0; i < f; i++) { fmt.Append('0'); } fmt.Append("e+0"); return(value.ToString(fmt.ToString(), CultureInfo.InvariantCulture)); }
internal bool test(String input) { Match match = null; if (!this.globalInt) { match = this.regex.Match(input); } else { int lastIndex = (int)Convert.ToInteger(this.lastIndexInt); if (lastIndex <= 0) { match = this.regex.Match(input); } else if (lastIndex <= input.Length) { match = this.regex.Match(input, lastIndex); } } if (match == null || !match.Success) { this.lastIndexInt = 0; return(false); } this.lastIndexInt = this.regExpConst.UpdateConstructor(this.regex, match, input); return(true); }
internal Object exec(String input) { Match match = null; if (!this.globalInt) { match = this.regex.Match(input); } else { int lastIndex = (int)Convert.ToInteger(this.lastIndexInt); if (lastIndex <= 0) { match = this.regex.Match(input); } else if (lastIndex <= input.Length) { match = this.regex.Match(input, lastIndex); } } if (match == null || !match.Success) { this.lastIndexInt = 0; return(DBNull.Value); } this.lastIndexInt = this.regExpConst.UpdateConstructor(this.regex, match, input); return(new RegExpMatch(this.regExpConst.arrayPrototype, this.regex, match, input)); }
public static String toPrecision(Object thisob, Object precision) { double value = NumberPrototype.ThisobToDouble(thisob); if (precision == null || precision is Missing) { return(Convert.ToString(value)); } double df = Convert.ToInteger(precision); if (df < 1 || df > 21) { throw new JScriptException(JSError.PrecisionOutOfRange); } int f = (int)df; if (Double.IsNaN(value)) { return("NaN"); } if (Double.IsInfinity(value)) { return(value > 0.0 ? "Infinity" : "-Infinity"); } String sign; if (value >= 0.0) { sign = ""; } else { sign = "-"; value = -value; } String mant = value.ToString("e" + (f - 1).ToString(), CultureInfo.InvariantCulture); int exp = Int32.Parse(mant.Substring(mant.Length - 4), CultureInfo.InvariantCulture); mant = mant.Substring(0, 1) + mant.Substring(2, f - 1); if (exp >= f || exp < -6) { return(sign + mant.Substring(0, 1) + (f > 1 ? "." + mant.Substring(1) : "") + (exp >= 0 ? "e+" : "e") + exp.ToString()); } if (exp == f - 1) { return(sign + mant); } if (exp >= 0) { return(sign + mant.Substring(0, exp + 1) + "." + mant.Substring(exp + 1)); } return(sign + "0." + mant.PadLeft(f - exp - 1, '0')); }
public static Object charCodeAt(Object thisob, double pos) //This returns an object so that integers stay integers { String thisStr = Convert.ToString(thisob); double position = Convert.ToInteger(pos); if (position < 0 || !(position < thisStr.Length)) { return(Double.NaN); } return((int)(thisStr[(int)position])); }
public static String charAt(Object thisob, double pos) { String thisStr = Convert.ToString(thisob); double position = Convert.ToInteger(pos); if (position < 0 || !(position < thisStr.Length)) { return(""); } return(thisStr.Substring((int)position, 1)); }
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 int indexOf(Object thisob, Object searchString, double position) { String thisStr = Convert.ToString(thisob); String searchStr = Convert.ToString(searchString); double startIndex = Convert.ToInteger(position); int length = thisStr.Length; if (startIndex < 0) { startIndex = 0; } if (startIndex >= length) { return(searchStr.Length == 0 ? 0 : -1); } return(thisStr.IndexOf(searchStr, (int)startIndex)); }
public static String slice(Object thisob, double start, Object end) { String thisStr = Convert.ToString(thisob); int length = thisStr.Length; double startIndex = Convert.ToInteger(start); double endIndex = (end == null || end is Missing) ? length : Convert.ToInteger(end); if (startIndex < 0) { startIndex = length + startIndex; if (startIndex < 0) { startIndex = 0; } } else if (startIndex > length) { startIndex = length; } if (endIndex < 0) { endIndex = length + endIndex; if (endIndex < 0) { endIndex = 0; } } else if (endIndex > length) { endIndex = length; } int nChars = (int)(endIndex - startIndex); if (nChars <= 0) { return(""); } else { return(thisStr.Substring((int)startIndex, nChars)); } }
public static String substr(Object thisob, double start, Object count) { String thisStr = thisob as String; if (thisStr == null) { thisStr = Convert.ToString(thisob); } int length = thisStr.Length; double startIndex = Convert.ToInteger(start); if (startIndex < 0) { startIndex += length; } if (startIndex < 0) { startIndex = 0; } else if (startIndex > length) { startIndex = length; } int nChars = count is int?(int)count: ((count == null || count is Missing) ? length - (int)startIndex : (int)Convert.ToInteger(count)); if (startIndex + nChars > length) { nChars = length - (int)startIndex; } if (nChars <= 0) { return(""); } else { return(thisStr.Substring((int)startIndex, nChars)); } }
public static String substring(Object thisob, double start, Object end) { String thisStr = thisob as String; if (thisStr == null) { thisStr = Convert.ToString(thisob); } int length = thisStr.Length; double startIndex = Convert.ToInteger(start); if (startIndex < 0) { startIndex = 0; } else if (startIndex > length) { startIndex = length; } double endIndex = (end == null || end is Missing) ? length : Convert.ToInteger(end); if (endIndex < 0) { endIndex = 0; } else if (endIndex > length) { endIndex = length; } if (startIndex > endIndex) { double temp = startIndex; startIndex = endIndex; endIndex = temp; } return(thisStr.Substring((int)startIndex, (int)(endIndex - startIndex))); }
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 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); }