示例#1
0
        protected void ReadNumber(ReadArgs args, int readChar)
        {
            long valueLong = 0;
            long multiply  = 1;
            bool isDecimal = false;

            if (readChar == iMinus)
            {
                multiply = -1;
                args.StrAppend((char)readChar);

                readChar = args.ReadOne();
            }

            do
            {
                int digitValue = readChar - iDigit0;
                if (digitValue >= 0 && digitValue < 10)
                {
                    valueLong = (valueLong * 10) + digitValue;
                    args.StrAppend((char)readChar);
                }
                else
                {
                    if (readChar == iDecimal)
                    {
                        args.StrAppend((char)readChar);
                        isDecimal = true;
                    }
                    else if (readChar == iFieldSep)
                    {
                        args.State = ReaderField.Singleton;
                    }
                    else if (readChar == iRecordSep)
                    {
                        args.State = ReaderNewRecord.Singleton;
                    }
                    else if (readChar == -1)
                    {
                        args.State = ReaderEnd.Singleton;
                    }
                    else
                    {
                        throw Error.Unexpected(ErrorCode.UnexpectedChars, iDigit0, readChar);
                    }
                    break;
                }
                readChar = args.ReadOne();
            } while (true);

            ValueRecord vr = args.ValueRec;

            if (!isDecimal)
            {
                valueLong *= multiply;
                args.AddValue(valueLong);
                args.Read.GetReadValue().ReadValue(vr, args.valPos, valueLong);
                args.StrReset();
            }
            else
            {
                // get a double value
                do
                {
                    readChar = args.ReadOne();
                    int digitValue = readChar - iDigit0;
                    if (digitValue >= 0 && digitValue < 10)
                    {
                        args.StrAppend((char)readChar);
                    }
                    else
                    {
                        if (readChar == iFieldSep)
                        {
                            args.State = ReaderField.Singleton;
                        }
                        else if (readChar == iRecordSep)
                        {
                            args.State = ReaderNewRecord.Singleton;
                        }
                        else if (readChar == -1)
                        {
                            args.State = ReaderEnd.Singleton;
                        }
                        else
                        {
                            throw Error.Unexpected(ErrorCode.UnexpectedChars, iDigit0, readChar);
                        }
                        break;
                    }
                } while (true);

                double realValue = double.Parse(args.StrGet());
                args.AddValue(realValue);
                args.Read.GetReadValue().ReadValue(vr, args.valPos, realValue);
            }
        }
示例#2
0
 public void SetupRecord(Record rec)
 {
     dcRecords[rec.SequenceNo] = rec;
     this.ValueRec             = rec as ValueRecord;
 }
示例#3
0
        public override void Read(ReadArgs args)
        {
            IReadValue  rv = args.Read.GetReadValue();
            ValueRecord vr = args.ValueRec;

            int readChar = args.ReadOne();

            switch (readChar)
            {
            case iBoolTrue:
                args.AddValue(true);
                rv.ReadValue(vr, args.valPos, true);
                break;

            case iBoolFalse:
                args.AddValue(false);
                rv.ReadValue(vr, args.valPos, false);
                break;

            case iStringEncl:
                String str = base.ReadStringStrict(args, false);
                args.AddValue(str);
                rv.ReadValue(vr, args.valPos, str);
                break;

            case iRefPrefix:
                Record rc = base.ReadRef(args, false);
                if (rc.RecType != RecordType.Instance && rc.RecType != RecordType.Array)
                {
                    throw Error.UnexpectedRecordType(RecordType.Instance, rc.RecType);
                }
                args.AddValue(rc);
                rv.ReadValue(vr, args.valPos, rc);
                return;

            case iDateTimePrefix:
                DateTime dt = new DateTime(
                    ReadDateTimeDigits(args, 4),
                    ReadDateTimeDigits(args, 2),
                    ReadDateTimeDigits(args, 2),
                    ReadSkipOne(args, iDateTimeT).ReadDateTimeDigits(args, 2),
                    ReadDateTimeDigits(args, 2),
                    ReadDateTimeDigits(args, 2),
                    ReadDateTimeDigits(args, 3)
                    );
                args.AddValue(dt);
                rv.ReadValue(vr, args.valPos, dt);
                break;

            case iFieldSep:
                args.AddValue(null);
                rv.ReadValueNull(vr, args.valPos);
                return;

            case iRecordSep:
                args.AddValue(null);
                rv.ReadValueNull(vr, args.valPos);
                args.State = ReaderNewRecord.Singleton;
                return;

            case -1:
                args.AddValue(null);
                rv.ReadValueNull(vr, args.valPos);
                args.State = ReaderEnd.Singleton;
                return;

            default:
                ReadNumber(args, readChar);
                return;
            }

            // fixed width values (bool, datetime) or values with delimiter (string)
            // still have one extra character to read in order to determine next step
            readChar = args.ReadOne();
            if (readChar == iFieldSep)
            {
                args.State = ReaderField.Singleton;
            }
            else if (readChar == iRecordSep)
            {
                args.State = ReaderNewRecord.Singleton;
            }
            else if (readChar == -1)
            {
                args.State = ReaderEnd.Singleton;
            }
            else
            {
                throw Error.UnexpectedChars(Constants.FieldSeparator, (char)readChar);
            }
        }