Ejemplo n.º 1
0
        private unsafe void ReadLinesImpl(IAddResult result, int max_lines)
        {
            int line_count = 0;

            line_count += this.PickLinesImpl(result, max_lines);
            if (line_count == max_lines)
            {
                return;
            }

            _lines.Clear();
            while (line_count < max_lines)
            {
                if (_blockPos < _blockNum && _worker.IsEmpty)
                {
                    this.ReadStream();
                    fixed(byte *byte_ptr = _byteBuffer)
                    {
                        var handle = new GCHandle <Decoder>();

                        handle.Create(_decoder);
                        _worker.DecodeTextIntoBuffer(byte_ptr, _byteLength, handle);
                        handle.Dispose();
                        _worker.GetLines(_lines);
                    }
                }

                line_count += this.PickLinesImpl(result, max_lines - line_count);
                if (line_count == max_lines)
                {
                    return;
                }

                if (_blockPos == _blockNum)
                {
                    // if final part do not have LF.
                    if (!_worker.IsEmpty)
                    {
                        var buff = new NativeList <Char16>(Allocator.Temp);
                        _worker.GetInternalBuffer(buff);
                        result.AddResult((char *)buff.GetUnsafePtr(), buff.Length);
                        buff.Dispose();
                    }

                    // reach EOF
                    break;
                }
            }
        }
Ejemplo n.º 2
0
 public void SetDelim(NativeStringList delims)
 {
     _delims.Clear();
     foreach (var se in delims)
     {
         // check duplication
         if (_delims.IndexOf(se) < 0)
         {
             _delims.Add(se);
         }
     }
 }
Ejemplo n.º 3
0
        public unsafe void Split(NativeList <Char16> source, NativeStringList result, bool append = false)
        {
            if (!append)
            {
                result.Clear();
            }

            // redirect to using Char16.IsWhiteSpace() function
            if (_delims.Length == 0)
            {
                source.Split(result, append);
                return;
            }
            // redirect to using single char delim function
            if (_delims.Length == 1 && _delims[0].Length == 1)
            {
                source.Split(_delims[0][0], result, append);
                return;
            }

            this.SplitImpl((Char16 *)source.GetUnsafePtr(), source.Length, result);
        }