Exemplo n.º 1
0
        internal static PythonList /*!*/ SplitInternal(IList <byte> /*!*/ bytes, byte[] seps, int maxsplit, Func <List <byte> /*!*/, object> /*!*/ ctor)
        {
            Debug.Assert(ctor != null);

            if (bytes.Count == 0)
            {
                return(SplitEmptyString(seps != null, ctor));
            }
            else
            {
                List <byte>[] r = null;
                //  If the optional second argument sep is absent or None, the words are separated
                //  by arbitrary strings of whitespace characters (space, tab, newline, return, formfeed);

                r = bytes.Split(seps, (maxsplit < 0) ? Int32.MaxValue : maxsplit + 1,
                                GetStringSplitOptions(seps));

                PythonList ret = PythonOps.MakeEmptyList(r.Length);
                foreach (List <byte> s in r)
                {
                    ret.AddNoLock(ctor(s));
                }
                return(ret);
            }
        }
Exemplo n.º 2
0
        internal static PythonList /*!*/ Split(this IList <byte> /*!*/ bytes, IList <byte> sep, int maxsplit, Func <List <byte> /*!*/, object> /*!*/ ctor)
        {
            Debug.Assert(ctor != null);

            if (sep == null)
            {
                if (maxsplit == 0)
                {
                    // Corner case for CPython compatibility
                    PythonList result = PythonOps.MakeEmptyList(1);
                    result.AddNoLock(ctor(bytes.LeftStrip() ?? bytes as List <byte> ?? new List <byte>(bytes)));
                    return(result);
                }

                return(SplitInternal(bytes, (byte[])null, maxsplit, ctor));
            }

            if (sep.Count == 0)
            {
                throw PythonOps.ValueError("empty separator");
            }
            else if (sep.Count == 1)
            {
                return(SplitInternal(bytes, new byte[] { sep[0] }, maxsplit, ctor));
            }
            else
            {
                return(SplitInternal(bytes, sep, maxsplit, ctor));
            }
        }
Exemplo n.º 3
0
            static PythonList SplitEmptyString(bool separators, Func <List <byte>, object> ctor)
            {
                PythonList ret = PythonOps.MakeEmptyList(1);

                if (separators)
                {
                    ret.AddNoLock(ctor(new List <byte>(0)));
                }
                return(ret);
            }
Exemplo n.º 4
0
        private static PythonList /*!*/ SplitEmptyString(bool separators, Func <List <byte> /*!*/, object> /*!*/ ctor)
        {
            Debug.Assert(ctor != null);

            PythonList ret = PythonOps.MakeEmptyList(1);

            if (separators)
            {
                ret.AddNoLock(ctor(new List <byte>(0)));
            }
            return(ret);
        }
Exemplo n.º 5
0
        internal static PythonList /*!*/ SplitInternal(this IList <byte> /*!*/ bytes, IList <byte> /*!*/ separator, int maxsplit, Func <List <byte> /*!*/, object> /*!*/ ctor)
        {
            Debug.Assert(ctor != null);

            if (bytes.Count == 0)
            {
                return(SplitEmptyString(separator != null, ctor));
            }

            List <byte>[] r = bytes.Split(separator, (maxsplit < 0) ? Int32.MaxValue : maxsplit + 1, GetStringSplitOptions(separator));

            PythonList ret = PythonOps.MakeEmptyList(r.Length);

            foreach (List <byte> s in r)
            {
                ret.AddNoLock(ctor(s));
            }
            return(ret);
        }
Exemplo n.º 6
0
        internal static PythonList SplitInternal(this IList <byte> bytes, IList <byte>?separator, int maxsplit, Func <List <byte>, IList <byte> > ctor)
        {
            if (bytes.Count == 0)
            {
                return(SplitEmptyString(separator != null, ctor));
            }

            //  If the optional second argument sep is absent or None, the words are separated
            //  by arbitrary strings of whitespace characters (space, tab, newline, return, formfeed);

            List <byte>[] r = bytes.Split(separator, (maxsplit < 0) ? Int32.MaxValue : maxsplit + 1, GetStringSplitOptions(separator));

            PythonList ret = PythonOps.MakeEmptyList(r.Length);

            foreach (List <byte> s in r)
            {
                ret.AddNoLock(ctor(s));
            }
            return(ret);