protected String ReadStringStrict(ReadArgs args, bool expectOpenEncl = true) { int readChar = 0; // opening encloser if (expectOpenEncl) { readChar = args.ReadOne(); if (readChar != iStringEncl) { throw Error.UnexpectedChars(Constants.StringFieldEncloser, Convert.ToChar(readChar)); } } while (true) { readChar = args.ReadOne(); if (readChar == iStringEncl) { break; } else if (readChar == iStringEsc) { readChar = args.ReadOne(); if (readChar == iStringEsc) { args.StrAppend(Constants.StringEscapeChar); } else if (readChar == iStringEncl) { args.StrAppend(Constants.StringFieldEncloser); } else if (readChar == -1) { throw new Error(ErrorCode.UnexpectedEOF); } else { throw new Error(ErrorCode.NotEscapeChar).AddData(ErrorDataKeys.Actual, Convert.ToChar(readChar)); } continue; } else if (readChar >= 0) { args.StrAppend((char)readChar); } else { throw new Error(ErrorCode.UnexpectedEOF); } } return(args.StrGet()); }
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); } }