예제 #1
0
            public DummyData(LineConstructor constructor, Encoding encoding, byte[] separator)
            {
                someField   = default;
                extraFields = default;

                SetFromLineConstructor(constructor, encoding, separator);
            }
예제 #2
0
            private unsafe void SetFromLineConstructor(LineConstructor constructor, Encoding encoding, byte[] separator)
            {
                fixed(byte *from = constructor.buffer)
                {
                    var start  = from;
                    var length = constructor.length;
                    var column = 0;

                    while (true)
                    {
                        var line = new ReadOnlySpan <byte>(start, length);
                        var next = line.IndexOf(separator);
                        if (next == -1)
                        {
                            if (line.IndexOf(Constants.CarriageReturn) > -1)
                            {
                                C = new StringField(start, length - 2, encoding);
                            }
                            else if (line.IndexOf(Constants.LineFeed) > -1)
                            {
                                C = new StringField(start, length - 1, encoding);
                            }
                            else
                            {
                                C = new StringField(start, length, encoding);
                            }

                            break;
                        }

                        var consumed = next + separator.Length;
                        length -= next + separator.Length;

                        switch (column)
                        {
                        case 0:
                            A = new StringField(start, next, encoding);
                            break;

                        case 1:
                            B = new StringField(start, next, encoding);
                            break;

                        case 2:
                            C = new StringField(start, next, encoding);
                            break;

                        default:
                            ExtraFields = ExtraFields.Initialized
                                                                        ? ExtraFields.AddLength(next)
                                                                        : new StringField(start, next, encoding);
                            break;
                        }

                        start += consumed;
                        column++;
                    }
                }
            }
예제 #3
0
            public RowLayout(LineConstructor constructor, Encoding encoding, byte[] separator)
            {
                A           = default;
                B           = default;
                C           = default;
                ExtraFields = default;

                SetFromLineConstructor(constructor, encoding, separator);
            }
예제 #4
0
파일: PersonLayout.cs 프로젝트: lulzzz/HQ
        public PersonLayout(LineConstructor constructor, Encoding encoding, byte[] separator)
        {
            Name        = default;
            Welcome     = default;
            ExtraFields = default;
            Fields      = 0;
            LineNumber  = constructor.lineNumber;

            SetFromLineConstructor(constructor, encoding, separator);
        }
예제 #5
0
파일: PersonLayout.cs 프로젝트: lulzzz/HQ
        public unsafe void SetFromLineConstructor(LineConstructor constructor, Encoding encoding, byte[] separator)
        {
            fixed(byte *from = constructor.buffer)
            {
                var start  = from;
                var length = constructor.length;
                var fields = 0;

                while (true)
                {
                    var line = new ReadOnlySpan <byte>(start, length);
                    var next = line.IndexOf(separator);
                    if (next == -1)
                    {
                        if (line.IndexOf((byte)'\r') > -1)
                        {
                            length -= 2;
                        }
                        else if (line.IndexOf((byte)'\n') > -1)
                        {
                            length -= 1;
                        }
                        next = length;
                    }

                    var consumed = next + separator.Length;
                    length -= next + separator.Length;

                    switch (fields)
                    {
                    case 0:
                        Name = new StringField(start, next, encoding);
                        break;

                    case 1:
                        Welcome = new StringField(start, next, encoding);
                        break;

                    default:
                        ExtraFields = ExtraFields.Initialized ? ExtraFields.AddLength(next) : new StringField(start, next, encoding);
                        break;
                    }

                    start += consumed;
                    fields++;
                    if (length < 1)
                    {
                        Fields = fields;
                        break;
                    }
                }
            }
        }