/// <summary> /// ゼロ埋め /// </summary> /// <param name="info"></param> /// <returns></returns> private object _zeroFill(INakoFuncCallInfo info) { long s = info.StackPopAsInt(); string l = info.StackPopAsInt().ToString(); return(String.Format(@"{0:D" + l + "}", s)); }
/// <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)); }
/// <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 _right(INakoFuncCallInfo info) { string s = info.StackPopAsString(); int len = (int)info.StackPopAsInt(); return(s.Substring(s.Length - len)); }
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); }
public object _methodA(INakoFuncCallInfo info) { CountDown o = info.StackPop() as CountDown; int a = (int)info.StackPopAsInt(); o.decrement(a); return(o); }
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 _remove(INakoFuncCallInfo info) { object sr = info.StackPop(); int a = NadesikoPositionToCSPosition((int)info.StackPopAsInt()); int b = (int)info.StackPopAsInt(); object s = ((NakoVariable)sr).Body; object ret; if (s is string) { ret = ((string)s).Remove(a, b); } else { ret = null; } ((NakoVariable)sr).SetBodyAutoType(ret); return(null); }
private object _random(INakoFuncCallInfo info) { long range = info.StackPopAsInt(); if (_randObj == null) { _randObj = new Random(); } int v = _randObj.Next((int)range); return((long)v); }
private object _remove(INakoFuncCallInfo info) { object sr = info.StackPop(); int a = NadesikoPositionToCSPosition((int)info.StackPopAsInt()); int b = (int)info.StackPopAsInt(); object s = ((NakoVariable)sr).Body; object ret; if (s is string) { string str = (string)s; if (a < str.Length) { if (a + b > str.Length) { b = str.Length - a; } ret = str.Remove(a, b); ((NakoVariable)sr).SetBodyAutoType(ret); } } return(""); }
/// <summary> /// 標準入力取得 /// </summary> /// <param name="info"></param> /// <returns></returns> public object _cin(INakoFuncCallInfo info) { long count = info.StackPopAsInt(); //TODO:標準入力の取得方法が効率が悪い long i = 0; string r = ""; while (i < count) { int ch = System.Console.Read(); if (ch < 0) { break; } r += (char)ch; i++; } return(r); }
private object _removeright(INakoFuncCallInfo info) { object sr = info.StackPop(); int a = (int)info.StackPopAsInt(); object s = ((NakoVariable)sr).Body; object ret; if (s is string) { string _tmp = (string)s; ret = _tmp.Remove(_tmp.Length - a); } else { ret = null; } ((NakoVariable)sr).SetBodyAutoType(ret); return(null); }
private object _insertArray(INakoFuncCallInfo info) { object obj_base = info.StackPop(); // 参照渡しなので変数への参照が得られる int i = (int)info.StackPopAsInt(); object obj_insert = info.StackPop(); if (!(obj_base is NakoVariable)) { throw new NakoPluginRuntimeException("『配列一括挿入』の元配列がvariableではありません"); } NakoVarArray array_insert = new NakoVarArray(); if (obj_insert is NakoVariable) { NakoVariable var_insert = (NakoVariable)obj_insert; if (var_insert.Body is NakoVarArray) { array_insert = (NakoVarArray)var_insert.Body; } } else if (obj_insert is string) { array_insert.SetValuesFromString((string)obj_insert); } else { throw new NakoPluginRuntimeException("『配列一括挿入』の挿入配列がvariableではありません"); } NakoVariable var_base = (NakoVariable)obj_base; if (var_base.Body is NakoVarArray) { NakoVarArray array_base = (NakoVarArray)var_base.Body; while (array_insert.Count > 0) { NakoVariable variable = array_insert.Pop(); array_base.Insert(i, variable); } } return(null); }
private object _search(INakoFuncCallInfo info) { object ar = info.StackPop(); int i = (int)info.StackPopAsInt(); object key = info.StackPop(); if (!(ar is NakoVarArray)) { throw new NakoPluginRuntimeException("『検索』の引数が配列ではありません"); } NakoVarArray arr = (NakoVarArray)ar; while (arr.GetValue(i) != null) { object var = arr.GetValue(i); if (var.ToString() == key.ToString()) { return(i); } i++; } return(-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 _removeright(INakoFuncCallInfo info) { object sr = info.StackPop(); int a = (int)info.StackPopAsInt(); object s = ((NakoVariable)sr).Body; object ret; if(s is string){ string _tmp = (string)s; ret = _tmp.Remove(_tmp.Length - a); }else{ ret = null; } ((NakoVariable)sr).SetBodyAutoType(ret); return null; }
private object _remove(INakoFuncCallInfo info) { object sr = info.StackPop(); int a = NadesikoPositionToCSPosition((int)info.StackPopAsInt()); int b = (int)info.StackPopAsInt(); object s = ((NakoVariable)sr).Body; object ret; if(s is string){ ret = ((string)s).Remove(a,b); }else{ ret = null; } ((NakoVariable)sr).SetBodyAutoType(ret); return null; }
/// <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); }
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> public object _cin(INakoFuncCallInfo info) { long count = info.StackPopAsInt(); //TODO:標準入力の取得方法が効率が悪い long i = 0; string r = ""; while (i < count) { int ch = System.Console.Read(); if (ch < 0) break; r += (char)ch; i++; } return r; }
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 _insertArray(INakoFuncCallInfo info) { object obj_base = info.StackPop(); // 参照渡しなので変数への参照が得られる int i = (int)info.StackPopAsInt(); object obj_insert = info.StackPop(); if (!(obj_base is NakoVariable)) { throw new NakoPluginRuntimeException("『配列一括挿入』の元配列がvariableではありません"); } NakoVarArray array_insert = new NakoVarArray(); if (obj_insert is NakoVariable) { NakoVariable var_insert = (NakoVariable)obj_insert; if(var_insert.Body is NakoVarArray){ array_insert = (NakoVarArray)var_insert.Body; } }else if(obj_insert is string){ array_insert.SetValuesFromString((string)obj_insert); }else{ throw new NakoPluginRuntimeException("『配列一括挿入』の挿入配列がvariableではありません"); } NakoVariable var_base = (NakoVariable)obj_base; if(var_base.Body is NakoVarArray){ NakoVarArray array_base = (NakoVarArray)var_base.Body; while(array_insert.Count>0){ NakoVariable variable = array_insert.Pop(); array_base.Insert(i,variable); } } return null; }
public object _unixtime_to_datetime(INakoFuncCallInfo info) { long unixtime = info.StackPopAsInt(); return(UnixEpoch.AddSeconds(unixtime).ToLocalTime()); }
public object _unixtime_to_datetime(INakoFuncCallInfo info) { long unixtime = info.StackPopAsInt(); return UnixEpoch.AddSeconds(unixtime).ToLocalTime(); }
private object _intVal(INakoFuncCallInfo info) { return info.StackPopAsInt(); }
public object _to_int(INakoFuncCallInfo info) { return info.StackPopAsInt(); }
public object _to_int(INakoFuncCallInfo info) { return(info.StackPopAsInt()); }
/// <summary> /// ゼロ埋め /// </summary> /// <param name="info"></param> /// <returns></returns> private object _zeroFill(INakoFuncCallInfo info) { long s = info.StackPopAsInt(); string l = info.StackPopAsInt().ToString(); return String.Format(@"{0:D"+l+"}",s); }
private object _random(INakoFuncCallInfo info) { long range = info.StackPopAsInt(); if (_randObj == null) { _randObj = new Random(); } int v = _randObj.Next((int)range); return (long)v; }
private object _search(INakoFuncCallInfo info) { object ar = info.StackPop(); int i = (int)info.StackPopAsInt(); object key = info.StackPop(); if (!(ar is NakoVarArray)) { throw new NakoPluginRuntimeException("『検索』の引数が配列ではありません"); } NakoVarArray arr = (NakoVarArray)ar; while(arr.GetValue(i)!=null){ object var = arr.GetValue(i); if(var.ToString()==key.ToString()){ return i; } i++; } return -1; }
/// <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 _intVal(INakoFuncCallInfo info) { return(info.StackPopAsInt()); }