public static object match(object thisObj, VsaEngine engine, object regExp) { string string_obj = Convert.ToString(thisObj); RegExpObject regex_obj = Convert.ToRegExp(regExp); bool global = regex_obj.global; if (!global) { return(RegExpPrototype.exec(regex_obj, string_obj)); } MatchCollection md = regex_obj.regex.Matches(string_obj); uint n = (uint)md.Count; Match lastMatch = md [(int)(n - 1)]; regex_obj.lastIndex = lastMatch.Index + 1; RegExpConstructor.UpdateLastMatch(lastMatch, string_obj); ArrayObject result = new ArrayObject(); result.length = n; for (uint i = 0; i < n; i++) { result.elems [i] = md [(int)i].Value; } return(result); }
public static string replace(object thisObj, object regExp, object replacement) { string string_obj = Convert.ToString(thisObj); if (!(regExp is RegExpObject)) { string match_str = Convert.ToString(regExp); string replace_str = Convert.ToString(replacement); int match_pos = string_obj.IndexOf(match_str); if (match_pos == -1) { return(string_obj); } return(String.Concat(string_obj.Substring(0, match_pos), replace_str, string_obj.Substring(match_pos + match_str.Length))); } RegExpObject regex_obj = (RegExpObject)regExp; int count = regex_obj.global ? -1 : 1; if (!(replacement is ScriptFunction)) { return(regex_obj.regex.Replace(string_obj, Convert.ToString(replacement), count)); } ScriptFunction fun = (ScriptFunction)replacement; MatchEvaluator wrap_fun = new MatchEvaluator(new ReplaceDelegate(fun, string_obj).Replace); return(regex_obj.regex.Replace(string_obj, wrap_fun, count)); }
public static object match(object thisob, VsaEngine engine, object regExp) { Match match; string input = Microsoft.JScript.Convert.ToString(thisob); RegExpObject obj2 = ToRegExpObject(regExp, engine); if (!obj2.globalInt) { match = obj2.regex.Match(input); if (!match.Success) { obj2.lastIndexInt = 0; return(DBNull.Value); } if (obj2.regExpConst != null) { obj2.lastIndexInt = obj2.regExpConst.UpdateConstructor(obj2.regex, match, input); return(new RegExpMatch(obj2.regExpConst.arrayPrototype, obj2.regex, match, input)); } return(new RegExpMatch(engine.Globals.globalObject.originalRegExp.arrayPrototype, obj2.regex, match, input)); } MatchCollection matches = obj2.regex.Matches(input); if (matches.Count == 0) { obj2.lastIndexInt = 0; return(DBNull.Value); } match = matches[matches.Count - 1]; obj2.lastIndexInt = obj2.regExpConst.UpdateConstructor(obj2.regex, match, input); return(new RegExpMatch(obj2.regExpConst.arrayPrototype, obj2.regex, matches, input)); }
public static string toString(object thisObj) { SemanticAnalyser.assert_type(thisObj, typeof(RegExpObject)); RegExpObject re = (RegExpObject)thisObj; return(re.ToString()); }
private static string ReplaceWithRegExp(string thisob, RegExpObject regExpObject, object replacement) { RegExpReplace replace = (replacement is ScriptFunction) ? ((RegExpReplace) new ReplaceUsingFunction(regExpObject.regex, (ScriptFunction)replacement, thisob)) : ((RegExpReplace) new Microsoft.JScript.ReplaceWithString(Microsoft.JScript.Convert.ToString(replacement))); MatchEvaluator evaluator = new MatchEvaluator(replace.Evaluate); string str = regExpObject.globalInt ? regExpObject.regex.Replace(thisob, evaluator) : regExpObject.regex.Replace(thisob, evaluator, 1); regExpObject.lastIndexInt = (replace.lastMatch == null) ? 0 : regExpObject.regExpConst.UpdateConstructor(regExpObject.regex, replace.lastMatch, thisob); return(str); }
public static RegExpObject compile(object thisob, object source, object flags) { RegExpObject obj2 = thisob as RegExpObject; if (obj2 == null) { throw new JScriptException(JSError.RegExpExpected); } return(obj2.compile(((source == null) || (source is Missing)) ? "" : Microsoft.JScript.Convert.ToString(source), ((flags == null) || (flags is Missing)) ? "" : Microsoft.JScript.Convert.ToString(flags))); }
public static string toString(object thisob) { RegExpObject obj2 = thisob as RegExpObject; if (obj2 == null) { throw new JScriptException(JSError.RegExpExpected); } return(obj2.ToString()); }
public static String toString(Object thisob) { RegExpObject regExpObject = thisob as RegExpObject; if (regExpObject == null) { throw new JScriptException(JSError.RegExpExpected); } return(regExpObject.ToString()); }
public static object exec(object thisObj, object input) { RegExpObject re = Convert.ToRegExp(thisObj); string str = null; if (input == null) { RegExpConstructor ctr = RegExpConstructor.Ctr; str = Convert.ToString(ctr.GetField("$_").GetValue("$_")); } else { str = Convert.ToString(input); } bool global = re.global; int lastIndex = global ? (int)((double)re.lastIndex) : 0; bool success = lastIndex >= 0 && lastIndex <= str.Length; Match md = null; if (success) { md = re.regex.Match(str, lastIndex); success = md.Success; } if (!success) { re.lastIndex = 0; return(DBNull.Value); } int index = md.Index; int endIndex = index + md.Length; if (global) { re.lastIndex = endIndex; } RegExpConstructor.UpdateLastMatch(md, str); GroupCollection caps = md.Groups; uint len = (uint)caps.Count; RegExpMatch result = new RegExpMatch(); result.AddField("index", index); result.AddField("input", input); result.length = len; for (uint j = 0; j < len; j++) { result.elems [j] = caps [(int)j].Value; } return(result); }
public static RegExpObject compile(Object thisob, Object source, Object flags) { RegExpObject regExpObject = thisob as RegExpObject; if (regExpObject == null) { throw new JScriptException(JSError.RegExpExpected); } return(regExpObject.compile( source == null || source is Missing ? "" : Convert.ToString(source), flags == null || flags is Missing ? "" : Convert.ToString(flags))); }
public static bool test(Object thisob, Object input) { RegExpObject regExpObject = thisob as RegExpObject; if (regExpObject == null) { throw new JScriptException(JSError.RegExpExpected); } if (input is Missing && !regExpObject.regExpConst.noExpando) { input = regExpObject.regExpConst.input; } return(regExpObject.test(Convert.ToString(input))); }
public static int search(object thisob, VsaEngine engine, object regExp) { string input = Microsoft.JScript.Convert.ToString(thisob); RegExpObject obj2 = ToRegExpObject(regExp, engine); Match match = obj2.regex.Match(input); if (!match.Success) { obj2.lastIndexInt = 0; return(-1); } obj2.lastIndexInt = obj2.regExpConst.UpdateConstructor(obj2.regex, match, input); return(match.Index); }
public static int search(Object thisob, VsaEngine engine, Object regExp) { String thisStr = Convert.ToString(thisob); RegExpObject regExpObject = StringPrototype.ToRegExpObject(regExp, engine); Match match = regExpObject.regex.Match(thisStr); if (!match.Success) { regExpObject.lastIndexInt = 0; return(-1); } regExpObject.lastIndexInt = regExpObject.regExpConst.UpdateConstructor(regExpObject.regex, match, thisStr); return(match.Index); }
public static bool test(object thisob, object input) { RegExpObject obj2 = thisob as RegExpObject; if (obj2 == null) { throw new JScriptException(JSError.RegExpExpected); } if ((input is Missing) && !obj2.regExpConst.noExpando) { input = obj2.regExpConst.input; } return(obj2.test(Microsoft.JScript.Convert.ToString(input))); }
public static RegExpObject compile(object thisObj, object source, object flags) { // // Note: We always compile RegExp internals so all this method is useful for is for // changing the properties of the otherwise immutable RegExp objects. // RegExpObject re = Convert.ToRegExp(thisObj); string flag_str = Convert.ToString(flags); re.Initialize(Convert.ToString(source), flag_str.IndexOfAny(new char [] { 'i' }) > -1, flag_str.IndexOfAny(new char [] { 'g' }) > -1, flag_str.IndexOfAny(new char [] { 'm' }) > -1); return(re); }
private static String ReplaceWithRegExp(String thisob, RegExpObject regExpObject, Object replacement) { RegExpReplace replacer = replacement is ScriptFunction ? (RegExpReplace)(new ReplaceUsingFunction(regExpObject.regex, (ScriptFunction)replacement, thisob)) : (RegExpReplace)(new ReplaceWithString(Convert.ToString(replacement))); MatchEvaluator matchEvaluator = new MatchEvaluator(replacer.Evaluate); String newString = regExpObject.globalInt ? regExpObject.regex.Replace(thisob, matchEvaluator) : regExpObject.regex.Replace(thisob, matchEvaluator, 1); regExpObject.lastIndexInt = replacer.lastMatch == null ? 0 : regExpObject.regExpConst.UpdateConstructor(regExpObject.regex, replacer.lastMatch, thisob); return(newString); }
internal override object Evaluate() { if (VsaEngine.executeForJSEE) { throw new JScriptException(JSError.NonSupportedInDebugger); } RegExpObject obj2 = (RegExpObject)base.Globals.RegExpTable[this]; if (obj2 == null) { obj2 = (RegExpObject)base.Engine.GetOriginalRegExpConstructor().Construct(this.source, this.ignoreCase, this.global, this.multiline); base.Globals.RegExpTable[this] = obj2; } return(obj2); }
public static string replace(object thisob, object regExp, object replacement) { string str = Microsoft.JScript.Convert.ToString(thisob); RegExpObject regExpObject = regExp as RegExpObject; if (regExpObject != null) { return(ReplaceWithRegExp(str, regExpObject, replacement)); } Regex regex = regExp as Regex; if (regex != null) { return(ReplaceWithRegExp(str, new RegExpObject(regex), replacement)); } return(ReplaceWithString(str, Microsoft.JScript.Convert.ToString(regExp), Microsoft.JScript.Convert.ToString(replacement))); }
public static int search(object thisObj, VsaEngine engine, object regExp) { string string_obj = Convert.ToString(thisObj); RegExpObject regex_obj = Convert.ToRegExp(regExp); Match md = regex_obj.regex.Match(string_obj); /* Note: Microsoft's implementation updates the lastIndex property of regex_obj here, but * ECMA-262, 15.5.4.12, NOTE 1 explicitely says not to do so. We do the ECMA-262 behavior. */ if (md.Success) { return(md.Index); } else { return(-1); } }
public static String replace(Object thisob, Object regExp, Object replacement) { String thisStr = Convert.ToString(thisob); RegExpObject regExpObject = regExp as RegExpObject; if (regExpObject != null) { return(StringPrototype.ReplaceWithRegExp(thisStr, regExpObject, replacement)); } Regex regex = regExp as Regex; if (regex != null) { return(StringPrototype.ReplaceWithRegExp(thisStr, new RegExpObject(regex), replacement)); } return(StringPrototype.ReplaceWithString(thisStr, Convert.ToString(regExp), Convert.ToString(replacement))); }
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 RegExpObject ToRegExpObject(object regExp, VsaEngine engine) { if ((regExp == null) || (regExp is Missing)) { return((RegExpObject)engine.GetOriginalRegExpConstructor().Construct("", false, false, false)); } RegExpObject obj2 = regExp as RegExpObject; if (obj2 != null) { return(obj2); } Regex regex = regExp as Regex; if (regex != null) { return(new RegExpObject(regex)); } return((RegExpObject)engine.GetOriginalRegExpConstructor().Construct(Microsoft.JScript.Convert.ToString(regExp), false, false, false)); }
private static RegExpObject ToRegExpObject(Object regExp, VsaEngine engine) { if (regExp == null || regExp is Missing) { return((RegExpObject)engine.GetOriginalRegExpConstructor().Construct("", false, false, false)); } RegExpObject result = regExp as RegExpObject; if (result != null) { return(result); } Regex regex = regExp as Regex; if (regex != null) { return(new RegExpObject(regex)); } return((RegExpObject)engine.GetOriginalRegExpConstructor().Construct(Convert.ToString(regExp), false, false, false)); }
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); }
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)); }
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 Object match(Object thisob, VsaEngine engine, Object regExp) { String thisStr = Convert.ToString(thisob); RegExpObject regExpObject = StringPrototype.ToRegExpObject(regExp, engine); Match match; if (!regExpObject.globalInt) { match = regExpObject.regex.Match(thisStr); if (!match.Success) { regExpObject.lastIndexInt = 0; return(DBNull.Value); } if (regExpObject.regExpConst != null) { regExpObject.lastIndexInt = regExpObject.regExpConst.UpdateConstructor(regExpObject.regex, match, thisStr); return(new RegExpMatch(regExpObject.regExpConst.arrayPrototype, regExpObject.regex, match, thisStr)); } else { return(new RegExpMatch(engine.Globals.globalObject.originalRegExp.arrayPrototype, regExpObject.regex, match, thisStr)); } } MatchCollection matches = regExpObject.regex.Matches(thisStr); if (matches.Count == 0) { regExpObject.lastIndexInt = 0; return(DBNull.Value); } match = matches[matches.Count - 1]; regExpObject.lastIndexInt = regExpObject.regExpConst.UpdateConstructor(regExpObject.regex, match, thisStr); return(new RegExpMatch( regExpObject.regExpConst.arrayPrototype, regExpObject.regex, matches, thisStr)); }
public static ArrayObject split(object thisObj, VsaEngine engine, object separator, object limit) { string string_obj = Convert.ToString(thisObj); int length = string_obj.Length; int max_count = (limit != null) ? Convert.ToInt32(limit) : -1; ArrayObject result = new ArrayObject(); if (separator == null) { result.length = (uint)1; result.elems [(uint)0] = string_obj; return(result); } int start_pos = 0; int end_pos = -1; int match_len = 0; uint count = 0; int sep_len = 0; if (!(separator is RegExpObject)) { string sep_str = Convert.ToString(separator); sep_len = sep_str.Length; if (string_obj.Length == 0) { if (sep_len > 0) { result.length = (uint)1; result.elems [(uint)0] = string_obj; } return(result); } while (end_pos != length && (max_count == -1 || count < max_count)) { end_pos = (length != 0) ? string_obj.IndexOf(sep_str, start_pos) : length; if (end_pos == -1) { end_pos = length; } else if (sep_len == 0) { end_pos++; } match_len = end_pos - start_pos; result.elems [count] = string_obj.Substring(start_pos, match_len); start_pos += match_len + sep_len; count++; } result.length = count; return(result); } RegExpObject sep_re = (RegExpObject)separator; MatchCollection md = sep_re.regex.Matches(string_obj); uint n = (uint)md.Count; Match match = null; for (int i = 0; i < n; i++) { if (max_count != -1 && count >= max_count) { break; } match = md [i]; sep_len = match.Length; end_pos = match.Index; match_len = end_pos - start_pos; // // The specification says that "ab".split(/a*/) is ["", "b"], but would // that would also mean that "abcdef".split(/./).length would not be 6. // I'm currently going with the Rhino behavior that seems to make more // sense. // if (!(end_pos == 0 && sep_len == 0)) { result.elems [count] = string_obj.Substring(start_pos, match_len); count++; } bool first_cap = true; foreach (Capture cap in match.Groups) { if (max_count != -1 && count >= max_count) { break; } if (first_cap) { first_cap = false; continue; } result.elems [count] = cap.Value; count++; } start_pos += match_len + sep_len; } if (n > 0 && (max_count == -1 || count < max_count)) { sep_re.lastIndex = match.Index + match.Length; RegExpConstructor.UpdateLastMatch(match, string_obj); if (start_pos < length) { result.elems [count] = string_obj.Substring(start_pos); count++; } } else if (n == 0) { result.elems [(uint)0] = string_obj; count++; } result.length = count; return(result); }
private static string ReplaceWithRegExp(string thisob, RegExpObject regExpObject, object replacement) { RegExpReplace replace = (replacement is ScriptFunction) ? ((RegExpReplace) new ReplaceUsingFunction(regExpObject.regex, (ScriptFunction) replacement, thisob)) : ((RegExpReplace) new Microsoft.JScript.ReplaceWithString(Microsoft.JScript.Convert.ToString(replacement))); MatchEvaluator evaluator = new MatchEvaluator(replace.Evaluate); string str = regExpObject.globalInt ? regExpObject.regex.Replace(thisob, evaluator) : regExpObject.regex.Replace(thisob, evaluator, 1); regExpObject.lastIndexInt = (replace.lastMatch == null) ? 0 : regExpObject.regExpConst.UpdateConstructor(regExpObject.regex, replace.lastMatch, thisob); return str; }
public Object Construct(string pattern, bool ignoreCase, bool global, bool multiLine) { RegExpObject re = new RegExpObject(pattern, ignoreCase, global, multiLine); return(re); }
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 String ReplaceWithRegExp(String thisob, RegExpObject regExpObject, Object replacement){ RegExpReplace replacer = replacement is ScriptFunction ? (RegExpReplace)(new ReplaceUsingFunction(regExpObject.regex, (ScriptFunction)replacement, thisob)) : (RegExpReplace)(new ReplaceWithString(Convert.ToString(replacement))); MatchEvaluator matchEvaluator = new MatchEvaluator(replacer.Evaluate); String newString = regExpObject.globalInt ? regExpObject.regex.Replace(thisob, matchEvaluator) : regExpObject.regex.Replace(thisob, matchEvaluator, 1); regExpObject.lastIndexInt = replacer.lastMatch == null ? 0 : regExpObject.regExpConst.UpdateConstructor(regExpObject.regex, replacer.lastMatch, thisob); return newString; }
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; }
public Object Construct(string pattern, bool ignoreCase, bool global, bool multiLine) { RegExpObject re = new RegExpObject (pattern, ignoreCase, global, multiLine); return re; }