Beispiel #1
0
 public void SetDelim(NativeStringList delims)
 {
     _delims.Clear();
     foreach (var se in delims)
     {
         // check duplication
         if (_delims.IndexOf(se) < 0)
         {
             _delims.Add(se);
         }
     }
 }
Beispiel #2
0
        private unsafe void SplitImpl(Char16 *source_ptr, int source_len, NativeStringList result)
        {
            // parse
            int start = 0;

            for (int i = 0; i < source_len; i++)
            {
                int match_len = 0;
                foreach (var d in _delims)
                {
                    // skip shorter delim
                    if (match_len >= d.Length)
                    {
                        continue;
                    }

                    bool match = true;
                    for (int j = 0; j < d.Length; j++)
                    {
                        if (source_ptr[i + j] != d[j])
                        {
                            match = false;
                            break;
                        }
                    }
                    if (match)
                    {
                        match_len = d.Length;
                    }
                }

                if (match_len > 0)
                {
                    int elem_len = i - start;
                    if (elem_len > 0)
                    {
                        Char16 *st_ptr = source_ptr + start;
                        result.Add(st_ptr, elem_len);
                    }
                    start = i + match_len;
                    i    += match_len;
                }
            }

            // final part
            if (start < source_len)
            {
                int     len    = source_len - start;
                Char16 *st_ptr = source_ptr + start;
                result.Add(st_ptr, len);
            }
        }
Beispiel #3
0
        static private NativeStringList ConvertListStr <T>(T str_list, Allocator alloc)
            where T : IEnumerable <string>
        {
            var tmp = new NativeStringList(alloc);

            foreach (var str in str_list)
            {
                tmp.Add(str);
            }
            return(tmp);
        }
Beispiel #4
0
        public unsafe void ReadLinesFromBuffer(NativeStringList result)
        {
            var ret = new Result_NSL();

            ret.result = result;

            if (_blockPos < _blockNum)
            {
                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);
                }
            }

            // read all lines in buffer
            this.PickLinesImpl(ret, int.MaxValue);
            _lines.Clear();

            if (_blockPos == _blockNum)
            {
                // if final part do not have LF.
                if (!_worker.IsEmpty)
                {
                    using (var buff = new NativeList <Char16>(Allocator.Temp))
                    {
                        _worker.GetInternalBuffer(buff);
                        result.Add((char *)buff.GetUnsafePtr(), buff.Length);
                    }
                }
            }
        }
Beispiel #5
0
 public unsafe void AddResult(char *ptr, int len)
 {
     result.Add(ptr, len);
 }