// Punct // Mask 1 excludes @*_-. // Mask 2 excludes @*_-. // Mask 4 excludes @*_-.+/ // AlphaNumeric, spaces // Mask 1 excludes letters and numbers // Mask 2 escapes ' ' with + // Mask 4 excludes letters and numbers // 1 and 4 unexclude ' ' public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x) { int alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL)); int mask = 4; if (alen == 0) { return(JSUndefined.Undefined); } else if (alen > 1) { mask = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "1").GetValue(GLOBAL)); } string instr = JSObject.ToPrimitive(GLOBAL, a.GetItem(GLOBAL, "0").GetValue(GLOBAL)); StringBuilder result = new StringBuilder(); foreach (char ch in instr) { if (ch == ' ' && mask == 2) { result.Append('+'); } else if ((ch == '+' || ch == '/') && (mask & 4) != 0) { result.Append(ch); } else if ((ch == '@' || ch == '*' || ch == '_' || ch == '-' || ch == '.') && mask != 0) { result.Append(ch); } else if (char.IsLetterOrDigit(ch) && mask != 0) { result.Append(ch); } else { if (ch >= (char)0x100) { result.Append(string.Format("%u{0:X4}", (int)ch)); } else { result.Append(string.Format("%{0:X2}", (int)ch)); } } } return(result.ToString()); }
public static string join(ExecutionContext GLOBAL, object selfOb, string sep) { JSObjectBase self = (JSObjectBase)selfOb; List <string> strings = new List <string>(); int idx; for (idx = 0; idx < JSObject.ToNumber(GLOBAL, self.GetItem(GLOBAL, "length").GetValue(GLOBAL)); idx++) { string istr = idx.ToString(); if (self.HasOwnProperty(istr) && self.GetItem(GLOBAL, istr).GetValue(GLOBAL) != null) { strings.Add(JSObject.ToPrimitive(GLOBAL, self.GetItem(GLOBAL, istr).GetValue(GLOBAL))); } else { strings.Add(""); } } return(string.Join(sep, strings.ToArray())); }
internal object Add(object res1, object res2) { object v; if (res1 is string || res2 is string) { string s1 = res1 != null?JSObject.ToPrimitive(GLOBAL, res1) : ""; string s2 = res2 != null?JSObject.ToPrimitive(GLOBAL, res2) : ""; v = s1 + s2; } else if (res1 is double || res2 is double || res1 is bool || res2 is bool) { v = (double)(JSObject.ToNumber(GLOBAL, res1) + JSObject.ToNumber(GLOBAL, res2)); } else { v = JSObject.ToPrimitive(GLOBAL, res1) + JSObject.ToPrimitive(GLOBAL, res2); } return(v); }
public override object Call(ExecutionContext GLOBAL, object t, JSObjectBase a, ExecutionContext x) { int alen = (int)JSObject.ToNumber(GLOBAL, a.GetItem(GLOBAL, "length").GetValue(GLOBAL)); StringBuilder result = new StringBuilder(); Match escChar; if (alen == 0) { return(JSUndefined.Undefined); } string instr = JSObject.ToPrimitive(GLOBAL, a.GetItem(GLOBAL, "0").GetValue(GLOBAL)); int startAt = 0; int lastUsed = 0; while (startAt < instr.Length && (escChar = escapedChar.Match(instr, startAt)).Success) { startAt = escChar.Index; result.Append(instr.Substring(lastUsed, startAt - lastUsed)); if (escChar.Groups[0].Value[1] == 'u') { startAt += 6; result.Append((char)int.Parse(escChar.Groups[0].Value.Substring(2), NumberStyles.HexNumber)); } else { startAt += 3; result.Append((char)int.Parse(escChar.Groups[0].Value.Substring(1), NumberStyles.HexNumber)); } lastUsed = startAt; } if (lastUsed < instr.Length) { result.Append(instr.Substring(lastUsed)); } return(result.ToString()); }
int lexorder(ExecutionContext GLOBAL, object a, object b) { string astr = JSObject.ToPrimitive(GLOBAL, a), bstr = JSObject.ToPrimitive(GLOBAL, b); return(astr.CompareTo(bstr)); }