// Start is called before the first frame update private void Awake() { selector = GetComponent <FunctionSelector>(); points = new Transform[resolution * resolution]; for (int i = 0; i < points.Length; i++) { Transform point = Instantiate(PointPrefab, transform, false); point.localScale = Scale; points[i] = point; } }
/// <summary> /// parse selector /// </summary> /// <param name="expression">selectors expression</param> /// <returns>selector</returns> public static ISelector ParserSelector(string expression) { expression = expression.Trim(); var sp = expression.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (sp.Length == 0) { return(null); } var cmd = sp[0]; var remove = Regex.IsMatch(expression, @".*\-r$"); var p = Regex.Replace(expression, "^" + cmd, ""); p = Regex.Replace(p, @"\-r$", "").Trim(); switch (cmd) { case "clear": { var tags = p.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray(); if (tags.Length == 0) { return(null); } var selector = new ClearTagSelector(tags); selector.Remove = remove; return(selector); } case "css": { var selector = new CssSelector(); selector.Remove = remove; if (p.EndsWith(":ohtml")) { selector.Type = CssTypeEnum.OUTERHTML; selector.Selector = Regex.Replace(p, ":ohtml$", "").Trim(); } else if (p.EndsWith(":html")) { selector.Type = CssTypeEnum.INNERHTML; selector.Selector = Regex.Replace(p, ":html$", "").Trim(); } else if (p.EndsWith(":text")) { selector.Type = CssTypeEnum.TEXT; selector.Selector = Regex.Replace(p, ":text$", "").Trim(); } else { selector.Type = CssTypeEnum.ATTR; var ms = Regex.Match(p, @"(.*):\[(.*?)\]$"); if (ms.Groups.Count == 3) { selector.Selector = ms.Groups[1].Value.Trim(); selector.AttrName = ms.Groups[2].Value.Trim(); } else { selector.Type = CssTypeEnum.OUTERHTML; selector.Selector = Regex.Replace(p, ":ohtml$", "").Trim(); } } return(selector); } case "ex": { var selector = new ExcludeSelector(); selector.Remove = remove; selector.Pattern = Regex.Replace(p, @"\-[bea]?$", "").Trim(); if (selector.Pattern.StartsWith("/")) { selector.Pattern = selector.Pattern.Trim('/'); } if (p.EndsWith("-b")) { selector.Type = ExcludeTypeEnum.BEGIN; } else if (p.EndsWith("-e")) { selector.Type = ExcludeTypeEnum.END; } else { selector.Type = ExcludeTypeEnum.ALL; } return(selector); } case "exp": { var selector = new ExpressionSelector(); selector.Remove = remove; selector.Expression = p; var ssp = p.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (ssp.Length == 2) { selector.Expression = ssp[0]; selector.Split = ssp[1].Trim('/'); } return(selector); } case "reg": { var selector = new RegexSelector(); selector.Remove = remove; var ms = Regex.Match(p, @"/?(.*)/([\d\s]*)"); if (ms.Groups.Count == 2) { selector.Pattern = ms.Groups[0].Value; return(selector); } if (ms.Groups.Count == 3) { selector.Pattern = ms.Groups[1].Value; selector.Index = ms.Groups[2].Value.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(m => Convert.ToInt32(m)).ToArray(); return(selector); } return(null); } case "regR": { var selector = new RegexReplaceSelector(); selector.Remove = remove; var ms = Regex.Match(p, @"^/(.*?)/[\s]+(.*)"); if (ms.Groups.Count == 2) { selector.Pattern = ms.Groups[1].Value; selector.NewString = ""; return(selector); } if (ms.Groups.Count == 3) { selector.Pattern = ms.Groups[1].Value; selector.NewString = ms.Groups[2].Value; return(selector); } return(null); } case "regS": { var selector = new RegexSplitSelector(); selector.Remove = remove; var ms = Regex.Match(p, @"/?(.*)/([\d\s]*)"); if (ms.Groups.Count == 3) { selector.Pattern = ms.Groups[1].Value; selector.Index = ms.Groups[2].Value.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(m => Convert.ToInt32(m)).ToArray(); return(selector); } return(null); } case "text": { var selector = new TextRangeSelector(); selector.Remove = remove; var ms = Regex.Matches(p, @"/(.*?[^\\\/])/"); if (ms.Count == 2) { selector.Begin = ms[0].Value.Trim('/'); selector.End = ms[1].Value.Trim('/'); return(selector); } return(null); } case "xpath": { var selector = new XPathSelector(); selector.Remove = remove; if (p.EndsWith(":oxml")) { selector.Type = XPathTypeEnum.OUTERXML; selector.XPath = Regex.Replace(p, ":oxml", "").Trim(); } else if (p.EndsWith(":xml")) { selector.Type = XPathTypeEnum.INNERXML; selector.XPath = Regex.Replace(p, ":xml$", "").Trim(); } else if (p.EndsWith(":text")) { selector.Type = XPathTypeEnum.TEXT; selector.XPath = Regex.Replace(p, ":text$", "").Trim(); } else { selector.Type = XPathTypeEnum.ATTR; var ms = Regex.Match(p, @"(.*):\[(.*?)\]$"); if (ms.Groups.Count == 3) { selector.XPath = ms.Groups[1].Value.Trim(); selector.AttrName = ms.Groups[2].Value.Trim(); } else { selector.Type = XPathTypeEnum.OUTERXML; selector.XPath = Regex.Replace(p, ":oxml$", "").Trim(); } } return(selector); } case "jpath": { var selector = new JsonPathSelector(); selector.Remove = remove; selector.JsonPath = p; return(selector); } case "proc": { var selector = new FunctionSelector(); selector.Remove = remove; selector.Name = p; return(selector); } } return(null); }