public Object _split(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string a = info.StackPopAsString(); return(__extract(info, s, a, false)); }
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); }
public object _relativeUrl(INakoFuncCallInfo info) { string a = info.StackPopAsString(); string b = info.StackPopAsString(); return(new Uri(new Uri(b), a).AbsoluteUri); }
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 _occurrence(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string search = info.StackPopAsString(); return((int)((s.Length - s.Replace(search, "").Length) / search.Length)); }
/// <summary> /// 文字列検索 /// </summary> /// <param name="info"></param> /// <returns></returns> private object _search(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string needle = info.StackPopAsString(); return(s.IndexOf(needle) + 1); }
private object _cutRange(INakoFuncCallInfo info) { object sr = info.StackPop(); string a = info.StackPopAsString(); string b = info.StackPopAsString(); string[] predelim = { a }; string[] postdelim = { b }; if (!(sr is NakoVariable)) { throw new ApplicationException("『範囲切り取る』に変数が設定されていません"); } object s = ((NakoVariable)sr).Body; string ret; if (s is string) { string[] split_s = ((string)s).Split(predelim, 2, StringSplitOptions.None); if (split_s.Length == 2) { ret = split_s[1]; string[] post_split_s = ret.Split(postdelim, 2, StringSplitOptions.None); if (post_split_s.Length == 2) { ((NakoVariable)sr).SetBodyAutoType(split_s[0] + post_split_s[1]); return(post_split_s[0]); } } } return(null); }
public Object _urlDecode(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string e = info.StackPopAsString(); return(HttpUtility.UrlDecode(s, Encoding.GetEncoding(e))); }
// Define Method public Object _openFile(INakoFuncCallInfo info) { string fileName = info.StackPopAsString(); string e = info.StackPopAsString(); // Exists? if (!System.IO.File.Exists(fileName)) { throw new NakoPluginRuntimeException("ファイル『" + fileName + "』は存在しません。"); } // Load //string src = File.ReadAllText(fileName); string src; if (e == "Auto") { src = StrUnit.LoadFromFileAutoEnc(fileName); } else { if (sjis.Contains(e)) { src = File.ReadAllText(fileName, Encoding.GetEncoding(932)); } else { src = File.ReadAllText(fileName, Encoding.GetEncoding(e)); } } return(src); }
private object _strpos(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string ss = info.StackPopAsString(); int i = s.IndexOf(ss); return(i + 1); // 1からはじまるので }
// public Object _group(INakoFuncCallInfo info){ // NakoVarArray groups = new NakoVarArray(); // if(m is Match && m.Success){ // for(int i = 0;i < m.Groups.Count;i++){ // groups.SetValue(i,m.Groups[i].Value); // } // return groups; // } // return null; // } public Object _replace(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string pattern = info.StackPopAsString(); string replace = info.StackPopAsString(); return(Regex.Replace(s, pattern, replace)); }
public Object _moveFile(INakoFuncCallInfo info) { string f1 = info.StackPopAsString(); string f2 = info.StackPopAsString(); File.Move(f1, f2); return(null); }
public object _format(INakoFuncCallInfo info) { string a = info.StackPopAsString(); string format = info.StackPopAsString(); DateTime aDate = DateTime.Parse(a); return(aDate.ToString(format)); }
private object _insert(INakoFuncCallInfo info) { StringBuilder s = new StringBuilder(info.StackPopAsString()); int cnt = NadesikoPositionToCSPosition((int)info.StackPopAsInt()); string a = info.StackPopAsString(); return(s.Insert(cnt, a).ToString()); }
/// <summary> /// 置換 /// </summary> /// <param name="info"></param> /// <returns></returns> private object _replace(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string search = info.StackPopAsString(); string replace = info.StackPopAsString(); return(s.Replace(search, replace)); }
public object _append(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string fileName = info.StackPopAsString(); System.Text.Encoding enc = new System.Text.UTF8Encoding(false); System.IO.File.AppendAllText(fileName, s, enc); return(null); }
public object _daysDifference(INakoFuncCallInfo info) { string a = info.StackPopAsString(); string b = info.StackPopAsString(); DateTime aDate = DateTime.Parse(a); DateTime bDate = DateTime.Parse(b); return(bDate.Subtract(aDate).TotalDays); }
public Object _diffhours(INakoFuncCallInfo info) { string atime = info.StackPopAsString(); string btime = info.StackPopAsString(); DateTime adatetime = DateTime.Parse(atime); DateTime bdatetime = DateTime.Parse(btime); return(adatetime.Subtract(bdatetime).TotalHours); }
public object _format(INakoFuncCallInfo info) { CultureInfo culture = new CultureInfo("ja-JP", true); string a = info.StackPopAsString(); string format = info.StackPopAsString(); DateTime aDate = DateTime.Parse(a); return(aDate.ToString(format, culture)); }
public Object _sendKeys(INakoFuncCallInfo info) { string title = info.StackPopAsString(); string keys = info.StackPopAsString(); EnumWindows.ActivateWindow(title); SendKeys.Send(keys); return(null); }
public object _downloadGet(INakoFuncCallInfo info) { string url = info.StackPopAsString(); string file = info.StackPopAsString(); WebClient client = new WebClient(); client.DownloadFile(url, file); client.Dispose(); return(null); }
/// <summary> /// 単置換 /// </summary> /// <param name="info"></param> /// <returns></returns> private object _replace_a(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string search = info.StackPopAsString(); string replace = info.StackPopAsString(); int index = s.IndexOf(search); string pre = s.Substring(0, index); string post = s.Substring(index + search.Length); return(pre + replace + post); }
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); }
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 _add(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string addDate = info.StackPopAsString(); string addOrDel = addDate.Substring(0, 1); string[] span = addDate.Substring(1).Replace('-', '/').Split('/'); if (span.Length != 3) { throw new ArgumentException(); } DateTime current = DateTime.Parse(s); //TODO:ParseExactを使うか? return(current.AddYears(int.Parse(addOrDel + span[0])).AddMonths(int.Parse(addOrDel + span[1])).AddDays(int.Parse(addOrDel + span[2])).ToString()); }
private object _convert_kana_to_roman(INakoFuncCallInfo info) { string s = info.StackPopAsString(); //TODO: 手動実装(めんどー)キャキュキョから始まって最後に1文字カナを変換 return(s); }
/// <summary> /// 左からN文字の部分文字列 /// </summary> /// <param name="info"></param> /// <returns></returns> private object _left(INakoFuncCallInfo info) { string s = info.StackPopAsString(); int len = (int)info.StackPopAsInt(); return(s.Substring(0, len)); }
/// <summary> /// 切り取る /// </summary> /// <param name="info"></param> /// <returns></returns> private object _cut(INakoFuncCallInfo info) { object sr = info.StackPop(); string a = info.StackPopAsString(); string[] delim = { a }; if (!(sr is NakoVariable)) { throw new ApplicationException("『切り取る』に変数が設定されていません"); } object s = ((NakoVariable)sr).Body; object ret; if (s is string) { string[] split_s = ((string)s).Split(delim, 2, StringSplitOptions.None); if (split_s.Length == 2) { ret = split_s[1]; ((NakoVariable)sr).SetBodyAutoType(ret); return(split_s[0]); } } return(null); }
/// <summary> /// 右から部分文字列を返す /// </summary> /// <param name="info"></param> /// <returns></returns> private object _right(INakoFuncCallInfo info) { string s = info.StackPopAsString(); int len = (int)info.StackPopAsInt(); return(s.Substring(s.Length - len)); }
private object _concat(INakoFuncCallInfo info) { object ar = info.StackPop(); string s = info.StackPopAsString(); if (!(ar is NakoVarArray)) { throw new NakoPluginRuntimeException("『結合』の引数が配列ではありません"); } StringBuilder sb = new StringBuilder(); NakoVarArray arr = (NakoVarArray)ar; int index = 0; while (arr.GetValue(index) != null) { if (index > 0) { sb.Append(s); } object var = arr.GetValue(index); if (var != null) { sb.Append(var.ToString()); } index++; } return(sb.ToString()); }
// Define Method public object _abort(INakoFuncCallInfo info) { string s = info.StackPopAsString(); foreach(System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName(s)){ p.Kill(); } return null; }
public object _decode(INakoFuncCallInfo info) { string s = info.StackPopAsString(); var json = fastJSON.JSON.Instance.Parse(s); NakoVarArray a = ArrayToNakoVarArray(json); return a; // System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); // object json = serializer.Deserialize<object>(s); }
// Define Method public Object _eval(INakoFuncCallInfo info) { string s = info.StackPopAsString(); NakoCompiler compiler = new NakoCompiler(); compiler.DirectSource = s; NakoInterpreter runner = new NakoInterpreter(compiler.Codes); runner.Run(); Console.WriteLine("EVALLOG=" + runner.PrintLog); return runner.globalVar.GetValue(0); }
public Object _directoryDialog(INakoFuncCallInfo info) { string s = info.StackPopAsString(); FolderBrowserDialog fbd = new FolderBrowserDialog(); //RootFolderには特殊フォルダしか指定できないのでとりあえずSelectedPathで代用 fbd.SelectedPath = s; //ダイアログを表示する if (fbd.ShowDialog() == DialogResult.OK) { //OKボタンがクリックされたとき return fbd.SelectedPath; } return null; }
/// <summary> /// 文字列検索 /// </summary> /// <param name="info"></param> /// <returns></returns> private object _search(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string needle = info.StackPopAsString(); return s.IndexOf(needle) + 1; }
/// <summary> /// 右から部分文字列を返す /// </summary> /// <param name="info"></param> /// <returns></returns> private object _right(INakoFuncCallInfo info) { string s = info.StackPopAsString(); int len = (int)info.StackPopAsInt(); return s.Substring(s.Length-len); }
private object _cutRange(INakoFuncCallInfo info) { object sr = info.StackPop(); string a = info.StackPopAsString(); string b = info.StackPopAsString(); string[] predelim = {a}; string[] postdelim = {b}; if(!(sr is NakoVariable)){ throw new ApplicationException("『範囲切り取る』に変数が設定されていません"); } object s = ((NakoVariable)sr).Body; string ret; if(s is string){ string[] split_s = ((string)s).Split(predelim,2,StringSplitOptions.None); if(split_s.Length==2){ ret = split_s[1]; string[] post_split_s = ret.Split(postdelim,2,StringSplitOptions.None); if(post_split_s.Length==2){ ((NakoVariable)sr).SetBodyAutoType(split_s[0] + post_split_s[1]); return post_split_s[0]; } } } return null; }
private object _alnumToEn(INakoFuncCallInfo info) { string s = info.StackPopAsString(); return Regex.Replace(s,@"[0-9A-Za-z:- ]+",delegate(Match m){ if(NWEnviroment.isWindows()){ return Strings.StrConv(m.Value, VbStrConv.Narrow, 0); }else{ return LinuxCommand.execute("echo '"+m.Value+"' | nkf -Z3").Replace("\n",""); } }); }
// Define Method public object _open(INakoFuncCallInfo info) { string fileName = info.StackPopAsString(); string mode = info.StackPopAsString(); switch (mode) { case "作": return new FileStream(fileName,FileMode.Create); case "読": return new StreamReader(fileName); case "書": return new StreamWriter(fileName); default: return new StreamReader(fileName); } }
/// <summary> /// 左からN文字の部分文字列 /// </summary> /// <param name="info"></param> /// <returns></returns> private object _left(INakoFuncCallInfo info) { string s = info.StackPopAsString(); int len = (int)info.StackPopAsInt(); return s.Substring(0,len); }
/// <summary> /// トリム /// </summary> /// <param name="info"></param> /// <returns></returns> private object _trim(INakoFuncCallInfo info) { string s = info.StackPopAsString(); return s.Trim(); }
/// <summary> /// 文字抜き出す /// </summary> /// <param name="info"></param> /// <returns></returns> private object _extract(INakoFuncCallInfo info) { string s = info.StackPopAsString(); int a = NadesikoPositionToCSPosition((int)info.StackPopAsInt()); int cnt = (int)info.StackPopAsInt(); return s.Substring(a,cnt); }
private object _insert(INakoFuncCallInfo info) { StringBuilder s = new StringBuilder(info.StackPopAsString()); int cnt = NadesikoPositionToCSPosition((int)info.StackPopAsInt()); string a = info.StackPopAsString(); return s.Insert(cnt,a).ToString(); }
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; }
private object _Em(INakoFuncCallInfo info) { string s = info.StackPopAsString(); char c1 = s[0]; int num = Encoding.GetEncoding("Shift_JIS").GetByteCount(c1.ToString()); if(num==2){ return 1; }else{ return 0; } }
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 _strpos(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string ss = info.StackPopAsString(); int i = s.IndexOf(ss); return (i + 1); // 1からはじまるので }
// Define Method /// <summary> /// 文字列の長さを調べる /// </summary> /// <param name="info"></param> /// <returns></returns> private object _length(INakoFuncCallInfo info) { string s = info.StackPopAsString(); return s.Length; }
private object _toKana(INakoFuncCallInfo info) { string s = info.StackPopAsString(); if(NWEnviroment.isWindows()){ return Strings.StrConv(s, VbStrConv.Hiragana, 0); }else{ return LinuxCommand.execute("echo '"+s+"' | nkf --hiragana").Replace("\n",""); } }
private object _num(INakoFuncCallInfo info) { string s = info.StackPopAsString(); char c1 = s[0]; int num; if(int.TryParse(c1.ToString(), out num)){ return 1; }else{ return 0; } }
private object _uppercase(INakoFuncCallInfo info) { string s = info.StackPopAsString(); return s.ToUpper(); }
private object _occurrence(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string search = info.StackPopAsString(); return (int)((s.Length - s.Replace(search,"").Length)/search.Length); }
/// <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; }
private object _convert_kana_to_roman(INakoFuncCallInfo info) { string s = info.StackPopAsString(); //TODO: 手動実装(めんどー)キャキュキョから始まって最後に1文字カナを変換 return s; }
public object _writeLine(INakoFuncCallInfo info) { string s = info.StackPopAsString(); object stream = info.StackPop(); if(stream is StreamWriter){ StreamWriter filestream = (StreamWriter)stream; filestream.WriteLine(s); } return null; }
/// <summary> /// 文字列に追加する /// </summary> /// <param name="info"></param> /// <returns></returns> private object _append(INakoFuncCallInfo info) { object sr = info.StackPop(); object s = ((NakoVariable)sr).Body; string a = info.StackPopAsString(); string ret = (string)s + a; ((NakoVariable)sr).SetBodyAutoType(ret); return null; }
/// <summary> /// 置換 /// </summary> /// <param name="info"></param> /// <returns></returns> private object _replace(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string search = info.StackPopAsString(); string replace = info.StackPopAsString(); return s.Replace(search,replace); }
/// <summary> /// 切り取る /// </summary> /// <param name="info"></param> /// <returns></returns> private object _cut(INakoFuncCallInfo info) { object sr = info.StackPop(); string a = info.StackPopAsString(); string[] delim = {a}; if(!(sr is NakoVariable)){ throw new ApplicationException("『切り取る』に変数が設定されていません"); } object s = ((NakoVariable)sr).Body; object ret; if(s is string){ string[] split_s = ((string)s).Split(delim,2,StringSplitOptions.None); if(split_s.Length==2){ ret = split_s[1]; ((NakoVariable)sr).SetBodyAutoType(ret); return split_s[0]; } } return null; }
private object _concat(INakoFuncCallInfo info) { object ar = info.StackPop(); string s = info.StackPopAsString(); if (!(ar is NakoVarArray)) { throw new NakoPluginRuntimeException("『結合』の引数が配列ではありません"); } StringBuilder sb = new StringBuilder(); NakoVarArray arr = (NakoVarArray)ar; int index = 0; while(arr.GetValue(index)!=null){ if(index > 0) sb.Append(s); object var = arr.GetValue(index); if (var != null) { sb.Append(var.ToString()); } index++; } return sb.ToString(); }
/// <summary> /// 単置換 /// </summary> /// <param name="info"></param> /// <returns></returns> private object _replace_a(INakoFuncCallInfo info) { string s = info.StackPopAsString(); string search = info.StackPopAsString(); string replace = info.StackPopAsString(); int index = s.IndexOf(search); string pre = s.Substring(0,index); string post = s.Substring(index+search.Length); return pre + replace + post; }