public Object _matchAll(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string pattern = info.StackPopAsString(); m = Regex.Match(s, pattern); NakoVarArray res = info.CreateArray(); int index = 0; NakoVarArray groups = new NakoVarArray(); // NakoVariable ret = new NakoVariable(); while (m.Success) { res.SetValue(index, m.Value); NakoVarArray subgroups = new NakoVarArray(); for (int i = 0; i < m.Groups.Count; i++) { subgroups.SetValue(i, m.Groups[i].Value); } groups.Add(subgroups); // for(int i = 0;i < m.Groups.Count;i++){ // groups.SetValue(i,m.Groups[i].Value); // } // ret.Type = NakoVarType.Array; // ret.Body = groups; index++; m = m.NextMatch(); } info.SetVariableValue("抽出文字列", groups); return(res); }
public Object _extract(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string a = info.StackPopAsString(); HtmlDocument doc = new HtmlDocument(); doc.OptionFixNestedTags = true; doc.OptionOutputAsXml = true; doc.LoadHtml(s); string html = doc.DocumentNode.OuterHtml; HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes(String.Format(@"//{0}", a)); NakoVarArray res = info.CreateArray(); if (nodes != null) { for (int i = 0; i < nodes.Count; i++) { HtmlNode node = nodes[i]; if (html.Contains(node.OuterHtml)) { res.SetValue(i, node.InnerHtml); html = html.Remove(html.IndexOf(node.OuterHtml), node.OuterHtml.Length); } } } return(res); }
private object _removeAt(INakoFuncCallInfo info) { object a = info.StackPop(); long i = info.StackPopAsInt(); if (!(a is NakoVariable)) { throw new NakoPluginRuntimeException("『削除』の引数が変数ではありません"); } NakoVariable av = (NakoVariable)a; NakoVarArray a_body = null; // 配列でなければ配列に強制変換する if (!(av.Body is NakoVarArray)) { a_body = info.CreateArray(); a_body.SetValuesFromString(av.Body.ToString()); av.SetBody(a_body, NakoVarType.Array); } else { a_body = (NakoVarArray)av.Body; } // 要素を削除する a_body.RemoveAt((int)i); // 結果をセット return(null); }
private object _getFunctionNames(INakoFuncCallInfo info) { NakoVarArray a = info.CreateArray(); foreach (NakoAPIFunc f in NakoAPIFuncBank.Instance.FuncList) { NakoVariable v = new NakoVariable(); v.SetBodyAutoType(f.name); a.Add(v); } return(a); }
private object _getPlugins(INakoFuncCallInfo info) { NakoVarArray a = info.CreateArray(); foreach (KeyValuePair <string, INakoPlugin> pair in NakoAPIFuncBank.Instance.PluginList) { NakoVariable v = new NakoVariable(); v.SetBodyAutoType(pair.Key); a.Add(v); } return(a); }
public Object _enumDirs(INakoFuncCallInfo info) { string path = info.StackPopAsString(); string[] files = Directory.GetDirectories(path); NakoVarArray res = info.CreateArray(); for (int i = 0; i < files.Length; i++) { res.SetValue(i, files[i]); } return(res); }
private object _degrade(INakoFuncCallInfo info) { string s = info.StackPopAsString(); char[] splitted = s.ToCharArray(); NakoVarArray arr = info.CreateArray(); for (int i = 0; i < splitted.Length; i++) { arr.SetValue(i, splitted[i]); } return(arr); }
private object _explode(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string a = info.StackPopAsString(); string[] splitted = s.Split(new string[] { a }, StringSplitOptions.None); NakoVarArray arr = info.CreateArray(); for (int i = 0; i < splitted.Length; i++) { arr.SetValue(i, splitted[i]); } return(arr); }
public Object _split(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string pattern = info.StackPopAsString(); string[] splitted = Regex.Split(s, pattern); NakoVarArray arr = info.CreateArray(); for (int i = 0; i < splitted.Length; i++) { arr.SetValue(i, splitted[i]); } return(arr); }
public Object _enumAllFiles(INakoFuncCallInfo info) { string path = info.StackPopAsString(); string[] files = Directory.GetFiles(path, "*", System.IO.SearchOption.AllDirectories); NakoVarArray res = info.CreateArray(); for (int i = 0; i < files.Length; i++) { //string f = Path.GetFileName(files[i]); string f = files[i]; res.SetValue(i, f); } return(res); }
/// <summary> /// 配列のキー列挙 /// </summary> /// <param name="info"></param> /// <returns></returns> private object _enumKeys(INakoFuncCallInfo info) { object ar = info.StackPop(); NakoVarArray arv = (NakoVarArray)ar; if (arv.Type != NakoVarType.Array) { throw new NakoPluginArgmentException("『ハッシュキー列挙』の引数が配列ではありません。"); } string[] keys = arv.GetKeys(); NakoVarArray res = info.CreateArray(); int i = 0; foreach (string key in keys) { res.SetValue(i++, key); } return(res); }
public Object _link(INakoFuncCallInfo info) { string s = info.StackPopAsString(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(s); HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes(@"//a"); NakoVarArray res = info.CreateArray(); if (nodes != null) { for (int i = 0; i < nodes.Count; i++) { HtmlNode node = nodes[i]; res.SetValue(i, node.GetAttributeValue("href", "")); } } return(res); }
// Define Method public Object _match(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string pattern = info.StackPopAsString(); m = Regex.Match(s, pattern); NakoVarArray groups = info.CreateArray(); if (m.Success) { for (int i = 0; i < m.Groups.Count; i++) { groups.SetValue(i, m.Groups[i].Value); } info.SetVariableValue("抽出文字列", groups); return(m.Value); } return(""); }
public Object _hirextract(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string a = info.StackPopAsString(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(s); HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes(String.Format(@"//{0}", a)); NakoVarArray res = info.CreateArray(); if (nodes != null) { for (int i = 0; i < nodes.Count; i++) { HtmlNode node = nodes[i]; res.SetValue(i, node.InnerHtml); } } return(res); }
/// <summary> /// 配列キー存在? /// </summary> /// <param name="array"></param> /// <param name="key"></param> /// <returns></returns> private object _hasKey(INakoFuncCallInfo info) { object ar = info.StackPop(); NakoVarArray arv = (NakoVarArray)ar; string searchKey = info.StackPopAsString(); if (arv.Type != NakoVarType.Array) { throw new NakoPluginArgmentException("『存在』の引数が配列ではありません。"); } string[] keys = arv.GetKeys(); NakoVarArray res = info.CreateArray(); foreach (string key in keys) { if (key == searchKey) { return(1); } } return(0); }
public Object _attrlist(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string a = info.StackPopAsString(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(s); HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes(String.Format(@"//{0}", a)); NakoVarArray res = info.CreateArray(); if (nodes != null) { foreach (HtmlNode node in nodes) { foreach (HtmlAttribute attr in node.Attributes) { res.SetValueFromKey(attr.Name, attr.Value); } } } return(res); }
private object _reverse(INakoFuncCallInfo info) { object ar = info.StackPop(); if (!(ar is NakoVariable)) { throw new NakoPluginRuntimeException("『逆順』の引数が変数ではありません"); } object a = ((NakoVariable)ar).Body; if (a is NakoVarArray) { ((NakoVarArray)a).Reverse(); } else { NakoVarArray a2 = info.CreateArray(); a2.SetValuesFromString(a.ToString()); a2.Reverse(); ((NakoVariable)ar).SetBody(a2, NakoVarType.Array); } // 結果をセット return(null); }
private object _removeAt(INakoFuncCallInfo info) { object a = info.StackPop(); long i = info.StackPopAsInt(); if (!(a is NakoVariable)) { throw new NakoPluginRuntimeException("『削除』の引数が変数ではありません"); } NakoVariable av = (NakoVariable)a; NakoVarArray a_body = null; // 配列でなければ配列に強制変換する if (!(av.Body is NakoVarArray)) { a_body = info.CreateArray(); a_body.SetValuesFromString(av.Body.ToString()); av.SetBody(a_body, NakoVarType.Array); } else { a_body = (NakoVarArray)av.Body; } // 要素を削除する a_body.RemoveAt((int)i); // 結果をセット return null; }
private object _getPlugins(INakoFuncCallInfo info) { NakoVarArray a = info.CreateArray(); foreach (KeyValuePair<string, INakoPlugin> pair in NakoAPIFuncBank.Instance.PluginList) { NakoVariable v = new NakoVariable(); v.SetBodyAutoType(pair.Key); a.Add(v); } return a; }
// Define Method public Object _match(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string pattern = info.StackPopAsString(); m = Regex.Match(s,pattern); NakoVarArray groups = info.CreateArray(); if(m.Success){ for(int i = 0;i < m.Groups.Count;i++){ groups.SetValue(i,m.Groups[i].Value); } info.SetVariableValue("抽出文字列", groups); return m.Value; } return null; }
public Object _enumAllFiles(INakoFuncCallInfo info) { string path = info.StackPopAsString(); string[] files = Directory.GetFiles(path,"*",System.IO.SearchOption.AllDirectories); NakoVarArray res = info.CreateArray(); for (int i = 0; i < files.Length; i++) { //string f = Path.GetFileName(files[i]); string f = files[i]; res.SetValue(i, f); } return res; }
public Object _attr(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string a = info.StackPopAsString(); string b = info.StackPopAsString(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(s); HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes(String.Format(@"//{0}",a)); NakoVarArray res = info.CreateArray(); if(nodes!=null){ for(int i=0;i<nodes.Count;i++){ HtmlNode node = nodes[i]; res.SetValue(i,node.GetAttributeValue(b,"")); } } return res; }
private object _degrade(INakoFuncCallInfo info) { string s = info.StackPopAsString(); char[] splitted = s.ToCharArray(); NakoVarArray arr = info.CreateArray(); for(int i=0;i<splitted.Length;i++){ arr.SetValue(i,splitted[i]); } return arr; }
private object _explode(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string a = info.StackPopAsString(); string[] splitted = s.Split(new string[]{a},StringSplitOptions.None); NakoVarArray arr = info.CreateArray(); for(int i=0;i<splitted.Length;i++){ arr.SetValue(i,splitted[i]); } return arr; }
public Object _split(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string pattern = info.StackPopAsString(); string[] splitted = Regex.Split(s,pattern); NakoVarArray arr = info.CreateArray(); for(int i=0;i<splitted.Length;i++){ arr.SetValue(i,splitted[i]); } return arr; }
public Object _attrlist(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string a = info.StackPopAsString(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(s); HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes(String.Format(@"//{0}",a)); NakoVarArray res = info.CreateArray(); if(nodes!=null){ foreach(HtmlNode node in nodes){ foreach(HtmlAttribute attr in node.Attributes){ res.SetValueFromKey(attr.Name,attr.Value); } } } return res; }
/// <summary> /// 配列キー存在? /// </summary> /// <param name="array"></param> /// <param name="key"></param> /// <returns></returns> private object _hasKey(INakoFuncCallInfo info) { object ar = info.StackPop(); NakoVarArray arv = (NakoVarArray)ar; string searchKey = info.StackPopAsString (); if (arv.Type != NakoVarType.Array) { throw new NakoPluginArgmentException("『存在』の引数が配列ではありません。"); } string[] keys = arv.GetKeys(); NakoVarArray res = info.CreateArray(); foreach (string key in keys) { if (key == searchKey) return 1; } return 0; }
/// <summary> /// 配列のキー列挙 /// </summary> /// <param name="info"></param> /// <returns></returns> private object _enumKeys(INakoFuncCallInfo info) { object ar = info.StackPop(); NakoVarArray arv = (NakoVarArray)ar; if (arv.Type != NakoVarType.Array) { throw new NakoPluginArgmentException("『ハッシュキー列挙』の引数が配列ではありません。"); } string[] keys = arv.GetKeys(); NakoVarArray res = info.CreateArray(); int i = 0; foreach (string key in keys) { res.SetValue(i++, key); } return res; }
public Object _enumFiles(INakoFuncCallInfo info) { string path = info.StackPopAsString(); string[] files = Directory.GetFiles(path); NakoVarArray res = info.CreateArray(); for (int i = 0; i < files.Length; i++) { string f = Path.GetFileName(files[i]); res.SetValue(i, f); } return res; }
public Object _matchAll(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string pattern = info.StackPopAsString(); m = Regex.Match(s,pattern); NakoVarArray res = info.CreateArray(); int index = 0; NakoVarArray groups = new NakoVarArray(); // NakoVariable ret = new NakoVariable(); while(m.Success){ res.SetValue(index,m.Value); NakoVarArray subgroups = new NakoVarArray(); for (int i = 0; i < m.Groups.Count; i++) { subgroups.SetValue(i,m.Groups[i].Value); } groups.Add(subgroups); // for(int i = 0;i < m.Groups.Count;i++){ // groups.SetValue(i,m.Groups[i].Value); // } // ret.Type = NakoVarType.Array; // ret.Body = groups; index++; m = m.NextMatch(); } info.SetVariableValue("抽出文字列", groups); return res; }
private object _reverse(INakoFuncCallInfo info) { object ar = info.StackPop(); if (!(ar is NakoVariable)) { throw new NakoPluginRuntimeException("『逆順』の引数が変数ではありません"); } object a = ((NakoVariable)ar).Body; if (a is NakoVarArray) { ((NakoVarArray)a).Reverse(); } else { NakoVarArray a2 = info.CreateArray(); a2.SetValuesFromString(a.ToString()); a2.Reverse(); ((NakoVariable)ar).SetBody(a2, NakoVarType.Array); } // 結果をセット return null; }