コード例 #1
0
ファイル: Builtin.cs プロジェクト: weimingtom/IronPythonMod
 public static string Chr(int value)
 {
     if (value < 0 || value > 0xFF)
     {
         throw Ops.ValueError("{0} is not in required range", value);
     }
     return(Ops.Char2String((char)value));
 }
コード例 #2
0
ファイル: Builtin.cs プロジェクト: weimingtom/IronPythonMod
 public static string Unichr(int i)
 {
     if (i < Char.MinValue || i > Char.MaxValue)
     {
         throw Ops.ValueError("{0} is not in required range", i);
     }
     return(Ops.Char2String((char)i));
 }
コード例 #3
0
ファイル: Builtin.cs プロジェクト: weimingtom/IronPythonMod
        public static object Filter(object function, object list)
        {
            string str = list as string;

            if (str != null)
            {
                if (function == null)
                {
                    return(str);
                }
                StringBuilder sb = new StringBuilder();
                foreach (char c in str)
                {
                    if (Ops.IsTrue(Ops.Call(function, Ops.Char2String(c))))
                    {
                        sb.Append(c);
                    }
                }
                return(sb.ToString());
            }
            else if (IsSubClass(Ops.GetDynamicType(list), Ops.GetDynamicTypeFromType(typeof(string))))
            {
                StringBuilder sb = new StringBuilder();
                IEnumerator   e  = Ops.GetEnumerator(list);
                while (e.MoveNext())
                {
                    object o = e.Current;
                    object t = (function != null) ? Ops.Call(function, o) : o;

                    if (!Ops.IsTrue(t))
                    {
                        continue;
                    }

                    sb.Append(Converter.ConvertToString(o));
                }
                return(sb.ToString());
            }

            List ret = new List();

            IEnumerator i = Ops.GetEnumerator(list);

            while (i.MoveNext())
            {
                if (function == null)
                {
                    if (Ops.IsTrue(i.Current))
                    {
                        ret.AddNoLock(i.Current);
                    }
                }
                else
                {
                    if (Ops.IsTrue(Ops.Call(function, i.Current)))
                    {
                        ret.AddNoLock(i.Current);
                    }
                }
            }

            if (IsInstance(list, Ops.GetDynamicTypeFromType(typeof(Tuple))))
            {
                return(Tuple.Make(ret));
            }
            else
            {
                return(ret);
            }
        }