コード例 #1
0
        internal protected virtual bool ResolvePropertiesTo(FtMetaSequence sequence, FtMetaFieldList fieldList, FtMetaSequenceList existingSequences, out string errorDescription)
        {
            errorDescription = "";
            bool result = false;

            foreach (FtMetaSequence.PropertyId id in Enum.GetValues(typeof(FtMetaSequence.PropertyId)))
            {
                switch (id)
                {
                case FtMetaSequence.PropertyId.Name:
                    result = ResolveName(sequence, existingSequences, out errorDescription);
                    break;

                case FtMetaSequence.PropertyId.Root:
                    result = ResolveRoot(sequence, out errorDescription);
                    break;

                case FtMetaSequence.PropertyId.FieldIndices:
                    result = ResolveFieldIndices(sequence, fieldList, out errorDescription);
                    break;

                default:
                    throw FtInternalException.Create(InternalError.SequenceReadElement_ResolvePropertiesTo_UnsupportedPropertyId, id.ToString());
                }

                if (!result)
                {
                    break;
                }
            }
            return(result);
        }
コード例 #2
0
        protected virtual bool ResolveProperties(FtMetaSequenceItem item, FtMetaFieldList fieldList, out string errorDescription)
        {
            errorDescription = "";
            bool result = true;

            foreach (FtMetaSequenceItem.PropertyId id in Enum.GetValues(typeof(FtMetaSequenceItem.PropertyId)))
            {
                switch (id)
                {
                case FtMetaSequenceItem.PropertyId.Index:
                    // already processed in TryAddOrIgnoreAttribute()
                    break;

                case FtMetaSequenceItem.PropertyId.FieldIndex:
                    result = ResolveFieldIndex(item, fieldList, out errorDescription);
                    break;

                default:
                    throw FtInternalException.Create(InternalError.SequenceItemReadElement_ResolveProperties_UnsupportedPropertyId, id.ToString());
                }

                if (!result)
                {
                    break;
                }
            }
            return(result);
        }
コード例 #3
0
        internal int Peek()
        {
            switch (state)
            {
            case State.Read:
                int readChar = textReader.Read();
                if (readChar == textReaderEofReadResult)
                {
                    state = State.EofPeeked;
                    return(EofReadResult);
                }
                else
                {
                    peekedChar = readChar;
                    state      = State.TextReaderPeeked;
                    return(peekedChar);
                }

            case State.SignaturePeekReread:
            case State.SignaturePeekRereadThenEof:
                return(signaturePeekBuffer[signaturePeekBufferPosition]);

            case State.TextReaderPeeked:
                return(peekedChar);

            case State.EofPeeked:
            case State.Eof:
                return(EofReadResult);

            default:
                throw FtInternalException.Create(InternalError.CharReader_Peek_UnsupportedState, state.ToString());
            }
        }
コード例 #4
0
        private void FinishLine()
        {
            switch (state)
            {
            case State.CommentChar:       // should never happen as detected in reader
            case State.Signature:         // should never happen as cached in charReader
            case State.ValueStuffedQuote: // should never happen as peeked in charReader
                throw FtInternalException.Create(InternalError.DeclarationParser_FinishLine_UnexpectedState, state.ToString());

            case State.ParameterName:
                throw new FtSerializationException(FtSerializationError.DeclarationParameterNameNotTerminated,
                                                   string.Format(Properties.Resources.DeclarationParser_FinishLine_DeclarationParameterNameNotTerminated, nameBuilder.ToString()));

            case State.WaitingValue:
                throw new FtSerializationException(FtSerializationError.DeclarationParameterMissingValue,
                                                   string.Format(Properties.Resources.DeclarationParser_FinishLine_DeclarationParameterMissingValue, nameBuilder.ToString()));

            case State.Value:
                throw new FtSerializationException(FtSerializationError.DeclarationParameterValueNotTerminated,
                                                   string.Format(Properties.Resources.DeclarationParser_FinishLine_DeclarationParameterValueNotTerminated, nameBuilder.ToString()));

            case State.WaitingParameter:
                break;     // all good

            default:
                throw FtInternalException.Create(InternalError.DeclarationParser_FinishLine_UnsupportedState, state.ToString());
            }
        }
コード例 #5
0
        private string CalculateEndOfLineText()
        {
            switch (EndOfLineType)
            {
            case FtEndOfLineType.Char: return(EndOfLineChar.ToString());

            case FtEndOfLineType.CrLf: return(CarriageReturnLineFeedString);

            case FtEndOfLineType.Auto:
                switch (EndOfLineAutoWriteType)
                {
                case FtEndOfLineAutoWriteType.CrLf: return(CarriageReturnLineFeedString);

                case FtEndOfLineAutoWriteType.Cr: return(CarriageReturnChar.ToString());

                case FtEndOfLineAutoWriteType.Lf: return(LineFeedChar.ToString());

                case FtEndOfLineAutoWriteType.Local: return(Environment.NewLine);

                default: throw FtInternalException.Create(InternalError.SerializationWriter_CalculateEndOfLineText_UnsupportedEndOfLineAutoWriteType, EndOfLineAutoWriteType.ToString());
                }

            default: throw FtInternalException.Create(InternalError.SerializationWriter_CalculateEndOfLineText_UnsupportedEndOfLineType, EndOfLineType.ToString());
            }
        }
コード例 #6
0
        internal void SetMetaReference(FtMetaReferenceType type, string reference)
        {
            Remove(MetaFileParameterName);
            Remove(MetaUrlParameterName);
            Remove(MetaEmbeddedParameterName);

            switch (type)
            {
            case FtMetaReferenceType.Embedded:
                Add(MetaEmbeddedParameterName, MetaEmbeddedParameterValue);
                break;

            case FtMetaReferenceType.File:
                Add(MetaFileParameterName, reference);
                break;

            case FtMetaReferenceType.Url:
                Add(MetaUrlParameterName, reference);
                break;

            case FtMetaReferenceType.None:
                break;

            default:
                throw FtInternalException.Create(InternalError.DeclaredParameters_SetMetaReference_UnknownMetaReferenceType, type.ToString());
            }
        }
コード例 #7
0
        protected virtual bool ResolveProperties(FtMetaSubstitution substitution, out string errorDescription)
        {
            errorDescription = "";
            bool result = false;

            foreach (FtMetaSubstitution.PropertyId id in Enum.GetValues(typeof(FtMetaSubstitution.PropertyId)))
            {
                switch (id)
                {
                case FtMetaSubstitution.PropertyId.Type:
                    result = ResolveType(substitution, out errorDescription);
                    break;

                case FtMetaSubstitution.PropertyId.Token:
                    result = ResolveToken(substitution, out errorDescription);
                    break;

                case FtMetaSubstitution.PropertyId.Value:
                    result = ResolveValue(substitution, out errorDescription);
                    break;

                default:
                    throw FtInternalException.Create(InternalError.SubstitutionReadElement_ResolveProperties_UnsupportedPropertyId, id.ToString());
                }

                if (!result)
                {
                    break;
                }
            }
            return(result);
        }
コード例 #8
0
        internal static void StaticTest()
        {
            if (basicRecArray.Length != Enum.GetNames(typeof(FtBooleanStyles)).Length)
            {
                throw FtInternalException.Create(InternalError.BooleanStylesFormatter_StaticTest_IncorrectBasicRecCount, basicRecArray.Length.ToString());
            }

            if (compositeRecArray.Length != Enum.GetNames(typeof(CompositeStyles)).Length)
            {
                throw FtInternalException.Create(InternalError.BooleanStylesFormatter_StaticTest_IncorrectCompositeRecCount, compositeRecArray.Length.ToString());
            }
        }
コード例 #9
0
 internal static string ToSignatureLineText(DeclaredParameters parameters)
 {
     DeclaredParameters.Rec versionRec;
     if (!parameters.TryGetVersionRec(out versionRec))
     {
         throw FtInternalException.Create(InternalError.DeclaredParametersFormatter_ToSignatureLineText_VersionNotSpecified);
     }
     else
     {
         DeclaredParameters.Rec[] recArray = new DeclaredParameters.Rec[1];
         recArray[0] = versionRec;
         return(ToText(recArray, 1));
     }
 }
コード例 #10
0
 internal static void StaticTest()
 {
     if (formatRecArray.Length != Enum.GetNames(typeof(FtMeta.PropertyId)).Length)
     {
         throw FtInternalException.Create(InternalError.RootPropertyIdFormatter_StaticTest_IncorrectFormatRecCount, formatRecArray.Length.ToString());
     }
     for (int i = 0; i < formatRecArray.Length; i++)
     {
         if ((int)formatRecArray[i].Id != i)
         {
             throw FtInternalException.Create(InternalError.RootPropertyIdFormatter_StaticTest_FormatRecOutOfOrder, formatRecArray[i].Id.ToString());
         }
     }
 }
コード例 #11
0
 internal static void StaticTest()
 {
     if (formatRecArray.Length != Enum.GetNames(typeof(FtQuotedType)).Length)
     {
         throw FtInternalException.Create(InternalError.QuotedTypeFormatter_StaticTest_IncorrectFormatRecCount, formatRecArray.Length.ToString());
     }
     for (int i = 0; i < formatRecArray.Length; i++)
     {
         if ((int)formatRecArray[i].Enumerator != i)
         {
             throw FtInternalException.Create(InternalError.QuotedTypeFormatter_StaticTest_FormatRecOutOfOrder, formatRecArray[i].Enumerator.ToString());
         }
     }
 }
コード例 #12
0
        private void FinishLastLine()
        {
            switch (lineType)
            {
            case FtLineType.Signature:
                declarationParser.FinishSignatureLine();
                break;

            case FtLineType.Declaration2:
                FinishDeclaration();
                break;

            case FtLineType.Comment:
                if (!headerRead)
                {
                    if (metaEmbedded && !embeddedMetaRead)
                    {
                        throw new FtSerializationException(FtSerializationError.EmbeddedMetaNotFound, "End of File encountered");
                    }
                }
                break;

            case FtLineType.EmbeddedMeta:
                if (embeddedMetaParser.Ready)
                {
                    FinishEmbeddedMeta();
                }
                else
                {
                    throw new FtSerializationException(FtSerializationError.IncompleteEmbeddedMeta, "End of File encountered");
                }
                break;

            case FtLineType.Blank:
                break;     // nothing to do

            case FtLineType.Heading:
                FinishHeadingLine();
                break;

            case FtLineType.Record:
                FinishRecord();
                break;

            default:
                throw FtInternalException.Create(InternalError.SerializationReader_FinishLastLine_UnsupportedLineType, lineType.ToString());
            }
        }
コード例 #13
0
        private bool DoesTextRequireQuotes(string text, bool willBeSpacePrefixed)
        {
            string startTrimmedText = text.TrimStart();

            if (startTrimmedText.Length > 0 && startTrimmedText[0] == QuoteChar)
            {
                return(true);
            }
            else
            {
                if (willBeSpacePrefixed && (text.Length == 0 || char.IsWhiteSpace(text[0])))
                {
                    return(true);
                }
                else
                {
                    char[] searchChars;
                    if (!AllowEndOfLineCharInQuotes)
                    {
                        searchChars = new char[1];
                    }
                    else
                    {
                        switch (EndOfLineType)
                        {
                        case FtEndOfLineType.Auto:
                        case FtEndOfLineType.CrLf:
                            searchChars    = new char[3];
                            searchChars[1] = CarriageReturnChar;
                            searchChars[2] = LineFeedChar;
                            break;

                        case FtEndOfLineType.Char:
                            searchChars    = new char[1];
                            searchChars[1] = EndOfLineChar;
                            break;

                        default:
                            throw FtInternalException.Create(InternalError.SerializationWriter_DoesTextRequireQuotes_UnsupportedEndOfLineType, EndOfLineType.ToString());
                        }
                    }
                    searchChars[0] = DelimiterChar;

                    return(startTrimmedText.IndexOfAny(searchChars) >= 0);
                }
            }
        }
コード例 #14
0
        internal int Read()
        {
            switch (state)
            {
            case State.Read:
                int readResult = textReader.Read();
                position++;
                if (readResult != textReaderEofReadResult)
                {
                    return(readResult);
                }
                else
                {
                    state = State.Eof;
                    return(EofReadResult);
                }

            case State.SignaturePeekReread:
            case State.SignaturePeekRereadThenEof:
                char aChar = signaturePeekBuffer[signaturePeekBufferPosition];
                signaturePeekBufferPosition++;
                if (signaturePeekBufferPosition == signaturePeekBuffer.Length)
                {
                    state = (state == State.SignaturePeekRereadThenEof) ? State.EofPeeked : State.Read;
                }
                position++;
                return((int)aChar);

            case State.TextReaderPeeked:
                int peekResult = (int)peekedChar;
                state = State.Read;
                position++;
                return(peekResult);

            case State.EofPeeked:
                position++;
                state = State.Eof;
                return(EofReadResult);

            case State.Eof:
                return(EofReadResult);

            default:
                throw FtInternalException.Create(InternalError.CharReader_Read_UnsupportedState, state.ToString());
            }
        }
コード例 #15
0
        private void ExitActiveField()
        {
            switch (state)
            {
            case State.InFixedWidthField:
                fixedWidthFieldParser.ExitField();
                break;

            case State.InDelimitedField:
                delimitedFieldParser.ExitField();
                break;

            default:
                throw FtInternalException.Create(InternalError.HeadingLineRecordParser_ExitActiveField_UnsupportedState, state.ToString());
            }
            activeField = null;
        }
コード例 #16
0
        internal void ParseChar(char aChar, bool endOfLineToBeEmbedded, out LineEndedType lineEndedType)
        {
            switch (inLineState)
            {
            case FtLineState.InNextTextOut:
                Debug.Assert(aChar == LineFeedChar && endOfLineToBeEmbedded, ((int)(InternalError.LineParser_ParseChar_InNextTextOut)).ToString());
                inLineState   = FtLineState.InTextOut;
                lineEndedType = LineEndedType.Not;
                break;

            case FtLineState.InTextOut:
                textLineCount++;
                textLineLength = 0;
                inLineState    = FtLineState.In;
                ParseInChar(aChar, endOfLineToBeEmbedded, out lineEndedType);
                break;

            case FtLineState.In:
                ParseInChar(aChar, endOfLineToBeEmbedded, out lineEndedType);
                break;

            case FtLineState.InPendingNextLineFeed:
                Debug.Assert(aChar == LineFeedChar && !endOfLineToBeEmbedded, ((int)(InternalError.LineParser_ParseChar_InPendingNextLineFeed)).ToString());
                inLineState   = FtLineState.Out;
                lineEndedType = LineEndedType.Continued;
                break;

            case FtLineState.Out:
                lineCount++;
                lineLength = 0;
                textLineCount++;
                textLineLength = 0;
                inLineState    = FtLineState.In;
                ParseInChar(aChar, endOfLineToBeEmbedded, out lineEndedType);
                break;

            default:
                throw FtInternalException.Create(InternalError.LineParser_ParseChar_Unsupported_InLineState, inLineState.ToString());
            }

            lineLength++;
            textLineLength++;
        }
コード例 #17
0
        internal void EnterField(FtField aField)
        {
            field = aField;

            // cache field values
            fieldSubstitutionsEnabled = core.SubstitutionsEnabled;
            fieldSubstitutionChar     = core.SubstitutionChar;
            fieldDelimiterChar        = core.DelimiterChar;
            fieldQuoteChar            = core.QuoteChar;

            if (headings)
            {
                fieldQuotedType = field.HeadingQuotedType;
            }
            else
            {
                fieldQuotedType = field.ValueQuotedType;
            }

            switch (fieldQuotedType)
            {
            case FtQuotedType.Never:
                quotedState = QuotedState.NeverOpen;
                break;

            case FtQuotedType.Optional:
                quotedState = QuotedState.CanOpen;
                break;

            case FtQuotedType.Always:
                quotedState = QuotedState.MustOpen;
                break;

            default:
                throw FtInternalException.Create(InternalError.DelimitedFieldParser_EnterField_UnsupportedQuotedType, fieldQuotedType.ToString());
            }


            textBuilder.Clear();
            position  = charReader.Position;
            rawOffset = -1;
            rawLength = 0;
        }
コード例 #18
0
        private string TruncateFixedWidthText(string text, FtFieldDefinition definition, FtTruncateType truncateType, char truncateChar, char nullChar)
        {
            switch (truncateType)
            {
            case FtTruncateType.Left: return(text.Substring(0, definition.Width));

            case FtTruncateType.Right: return(text.Substring(text.Length - definition.Width, definition.Width));

            case FtTruncateType.TruncateChar: return(new string(truncateChar, definition.Width));

            case FtTruncateType.NullChar: return(new string(nullChar, definition.Width));

            case FtTruncateType.Exception:
                throw new FtSerializationException(FtSerializationError.FieldTruncated, string.Format(Properties.Resources.FtField_TruncateText_TextTruncation, text));

            default:
                throw FtInternalException.Create(InternalError.FtField_TruncateText_UnsupportedTruncateType, truncateType.ToString());
            }
        }
コード例 #19
0
        private string PadFixedWidthText(string text, FtFieldDefinition definition, FtPadAlignment padAlignment, FtPadCharType padCharType, char padChar, char endOfValueChar)
        {
            bool leftPad;

            switch (padAlignment)
            {
            case FtPadAlignment.Auto:
                leftPad = definition.AutoLeftPad;
                break;

            case FtPadAlignment.Left:
                leftPad = true;
                break;

            case FtPadAlignment.Right:
                leftPad = false;
                break;

            default:
                throw FtInternalException.Create(InternalError.FtField_PadText_UnsupportedPadAlignment, padAlignment.ToString());
            }

            int    padLength;
            string padText;
            string result;

            switch (padCharType)
            {
            case FtPadCharType.Auto:
            case FtPadCharType.Specified:
                char usePadChar;
                if (padCharType == FtPadCharType.Auto)
                {
                    usePadChar = definition.AutoPadChar;
                }
                else
                {
                    usePadChar = padChar;
                }

                padLength = definition.Width - text.Length;
                padText   = new string(usePadChar, padLength);

                if (leftPad)
                {
                    result = padText + text;
                }
                else
                {
                    result = text + padText;
                }
                break;

            case FtPadCharType.EndOfValue:
                padLength = definition.Width - text.Length - 1;
                padText   = new string(padChar, padLength);
                if (leftPad)
                {
                    result = padText + endOfValueChar.ToString() + text;
                }
                else
                {
                    result = text + endOfValueChar.ToString() + padText;
                }
                break;

            default:
                throw FtInternalException.Create(InternalError.FtField_PadText_UnsupportedPadCharType, padCharType.ToString());
            }

            return(result);
        }
コード例 #20
0
        private void WriteRecordField(FtField field, int recordIndex)
        {
            OnFieldValueWriteReady(field, recordIndex);

            if (field.FixedWidth)
            {
                if (field.IsNull())
                {
                    writer.Write(field.Definition.FixedWidthNullValueText);
                }
                else
                {
                    string valueText = field.GetAsNonNullValueText();
                    string rawText   = EncodeFixedWidthValueText(valueText, field);
                    writer.Write(rawText);
                }
            }
            else
            {
                if (field.IsNull())
                {
                    writer.Write("");
                }
                else
                {
                    string valueText = field.GetAsNonNullValueText();

                    bool fieldQuoted;
                    switch (field.ValueQuotedType)
                    {
                    case FtQuotedType.Never:
                        fieldQuoted = false;
                        break;

                    case FtQuotedType.Always:
                        fieldQuoted = true;
                        break;

                    case FtQuotedType.Optional:
                        if (field.ValueAlwaysWriteOptionalQuote)
                        {
                            fieldQuoted = true;
                        }
                        else
                        {
                            fieldQuoted = DoesTextRequireQuotes(valueText, field.ValueWritePrefixSpace);
                        }
                        break;

                    default:
                        throw FtInternalException.Create(InternalError.SerializationWriter_WriteRecordField_UnsupportedQuotedType, field.HeadingQuotedType.ToString());
                    }

                    if (field.ValueWritePrefixSpace)
                    {
                        writer.Write(PrefixSpaceChar);
                    }

                    if (fieldQuoted)
                    {
                        writer.Write(QuoteChar);
                    }

                    string rawText = EncodeDelimitValueHeadingText(valueText, fieldQuoted);
                    writer.Write(rawText);

                    if (fieldQuoted)
                    {
                        writer.Write(QuoteChar);
                    }
                }
            }

            if (!field.Constant && !field.ValueAssigned)
            {
                // Field was not assigned a value (or null) so it will be null but any null sequence redirects will not have been processed yet. Do so now.
                Debug.Assert(field.IsNull());
                int fieldsAffectedFromIndex;
                field.CheckNullSequenceRedirect(out fieldsAffectedFromIndex);
            }
        }
コード例 #21
0
        private void WriteHeadingField(FtField field, int headingLineIndex)
        {
            string headingText = field.Headings[headingLineIndex];

            if (headingText == null)
            {
                headingText = "";
            }

            if (field.FixedWidth)
            {
                string rawText = EncodeFixedWidthHeadingText(headingText, field);
                writer.Write(rawText);
            }
            else
            {
                bool fieldQuoted;
                switch (field.HeadingQuotedType)
                {
                case FtQuotedType.Never:
                    fieldQuoted = false;
                    break;

                case FtQuotedType.Always:
                    fieldQuoted = true;
                    break;

                case FtQuotedType.Optional:
                    if (field.HeadingAlwaysWriteOptionalQuote)
                    {
                        fieldQuoted = true;
                    }
                    else
                    {
                        fieldQuoted = DoesTextRequireQuotes(headingText, field.HeadingWritePrefixSpace);
                    }
                    break;

                default:
                    throw FtInternalException.Create(InternalError.SerializationWriter_WriteHeadingField_UnsupportedQuotedType, field.HeadingQuotedType.ToString());
                }

                if (field.HeadingWritePrefixSpace)
                {
                    writer.Write(PrefixSpaceChar);
                }

                if (fieldQuoted)
                {
                    writer.Write(QuoteChar);
                }

                string rawText = EncodeDelimitValueHeadingText(headingText, fieldQuoted);
                writer.Write(rawText);

                if (fieldQuoted)
                {
                    writer.Write(QuoteChar);
                }
            }
        }
コード例 #22
0
        private void ParseChar(char aChar)
        {
            if (!lineParser.InLine)
            {
                // new line starting
                // calculate initial lineType and check if first char is ok

                lineBuilder.Clear();

                lineType = CalculateStartLineType(aChar);
                switch (lineType)
                {
                case FtLineType.Signature:
                    declarationParser.StartLine();
                    SetLineCommentChar(aChar);
                    break;

                case FtLineType.Declaration2:
                    declarationParser.StartLine();
                    break;

                case FtLineType.Comment:
                    if (!headerRead)
                    {
                        if (metaEmbedded && !embeddedMetaRead)
                        {
                            embeddedMetaParser.StartLine();
                        }
                    }
                    break;

                case FtLineType.EmbeddedMeta:
                    embeddedMetaParser.StartLine();
                    break;

                case FtLineType.Heading:
                    InvokeRootSequence();
                    int headingLineReadIndex = headingLineReadCount++;
                    headingLineParser.Start(headingLineReadIndex);
                    OnHeadingLineStarted(headingLineReadIndex);
                    break;
                }
            }

            bool endOfLineToBeEmbedded = recordParser.IsEndOfLineToBeEmbedded();

            LineParser.LineEndedType lineEndedType;
            lineParser.ParseChar(aChar, endOfLineToBeEmbedded, out lineEndedType);

            if (lineEndedType != LineParser.LineEndedType.Continued)
            {
                bool lineEndInitiated;
                if (lineEndedType == LineParser.LineEndedType.Initiated)
                {
                    lineEndInitiated = true;
                }
                else
                {
                    lineEndInitiated = false;
                    lineBuilder.Append(aChar);
                }

                switch (lineType)
                {
                case FtLineType.Signature:
                    if (!lineEndInitiated)
                    {
                        declarationParser.ParseSignatureLineChar(aChar);
                    }
                    else
                    {
                        declarationParser.FinishSignatureLine();
                    }
                    break;

                case FtLineType.Declaration2:
                    if (!lineEndInitiated)
                    {
                        declarationParser.ParseDeclaration2LineChar(aChar);
                    }
                    else
                    {
                        FinishDeclaration();
                    }
                    break;

                case FtLineType.Comment:
                    if (!headerRead)
                    {
                        if (metaEmbedded && !embeddedMetaRead)
                        {
                            if (!lineEndInitiated)
                            {
                                // see if embedded Meta started in this line
                                bool embeddedMetaPresent;
                                embeddedMetaParser.ParseNotYetDetectedChar(aChar, out embeddedMetaPresent);
                                if (embeddedMetaPresent)
                                {
                                    lineType = FtLineType.EmbeddedMeta;
                                }
                            }
                        }
                    }
                    break;

                case FtLineType.EmbeddedMeta:
                    if (!lineEndInitiated)
                    {
                        embeddedMetaParser.ParseChar(aChar);
                    }
                    else
                    {
                        embeddedMetaParser.AppendLine();
                        if (embeddedMetaParser.Ready)
                        {
                            FinishEmbeddedMeta();
                        }
                    }
                    break;

                case FtLineType.Blank:
                    if (!headerRead)
                    {
                        if (!lineEndInitiated)
                        {
                            // must be a heading line
                            lineType = FtLineType.Heading;
                            if (metaEmbedded && !embeddedMetaRead)
                            {
                                // error if expecting embedded Meta
                                throw new FtSerializationException(FtSerializationError.EmbeddedMetaNotFound, Properties.Resources.SerializationReader_ParseChar_EmbeddedMetaLineNotBlankOrComment);
                            }
                            else
                            {
                                Debug.Assert(HeadingLineCount > 0 && !headingLinesRead);
                                InvokeRootSequence();
                                int headingLineReadIndex = headingLineReadCount++;
                                headingLineParser.Start(headingLineReadIndex);
                                OnHeadingLineStarted(headingLineReadIndex);
                                headingLineParser.ParseChar(aChar);
                            }
                        }
                    }
                    else
                    {
                        if (!lineEndInitiated)
                        {
                            // is actually a record line
                            lineType = FtLineType.Record;
                            if (newTableStarted)
                            {
                                PreviousRecordSequenceInvokationList.Assign(SequenceInvokationList);
                                newTableStarted = false;
                            }
                            InvokeRootSequence();
                            int recordIndex = recordCount++;
                            recordParser.Start(recordIndex);
                            OnRecordStarted(recordIndex);
                            recordParser.ParseChar(aChar);
                        }
                        else
                        {
                            if (!IgnoreBlankLines)
                            {
                                throw new FtSerializationException(FtSerializationError.RecordNotEnoughFields, Properties.Resources.SerializationReader_ParseChar_BlankRecordsNotAllowed);
                            }
                        }
                    }

                    break;

                case FtLineType.Heading:
                    if (!lineEndInitiated)
                    {
                        headingLineParser.ParseChar(aChar);
                    }
                    else
                    {
                        FinishHeadingLine();
                    }
                    break;

                case FtLineType.Record:
                    if (!lineEndInitiated)
                    {
                        recordParser.ParseChar(aChar);
                    }
                    else
                    {
                        FinishRecord();
                    }
                    break;

                default:
                    throw FtInternalException.Create(InternalError.SerializationReader_ParseChar_UnsupportedLineType, lineType.ToString());
                }
            }
        }
コード例 #23
0
        private void ParseChar(char aChar)
        {
            switch (state)
            {
            case State.WaitingParameter:
                // ignore whitespace
                if (!char.IsWhiteSpace(aChar))
                {
                    if (aChar == NameValueSeparatorChar)
                    {
                        throw new FtSerializationException(FtSerializationError.DeclarationParameterNameIsZeroLength,
                                                           string.Format(Properties.Resources.DeclarationParser_ParseChar_DeclarationParameterNameIsZeroLength, parameters.Count));
                    }
                    else
                    {
                        nameBuilder.Clear();
                        nameBuilder.Append(aChar);
                        state = State.ParameterName;
                    }
                }
                break;

            case State.ParameterName:
                if (aChar != NameValueSeparatorChar)
                {
                    nameBuilder.Append(aChar);
                }
                else
                {
                    state = State.WaitingValue;
                }
                break;

            case State.WaitingValue:
                // ignore initial whitespace
                if (!char.IsWhiteSpace(aChar))
                {
                    if (aChar != ValueQuoteChar)
                    {
                        throw new FtSerializationException(FtSerializationError.DeclarationParameterValueNotQuoted,
                                                           string.Format(Properties.Resources.DeclarationParser_ParseChar_DeclarationParameterValueNotQuoted, nameBuilder.ToString()));
                    }
                    else
                    {
                        valueBuilder.Clear();
                        state = State.Value;
                    }
                }
                break;

            case State.Value:
                if (aChar != ValueQuoteChar)
                {
                    valueBuilder.Append(aChar);
                }
                else
                {
                    if (charReader.Peek() == ValueQuoteChar)
                    {
                        state = State.ValueStuffedQuote;
                    }
                    else
                    {
                        parameters.Add(nameBuilder.ToString().Trim(), valueBuilder.ToString());
                        state = State.WaitingParameter;
                    }
                }
                break;

            case State.ValueStuffedQuote:
                valueBuilder.Append(ValueQuoteChar);
                state = State.Value;
                break;

            default:
                throw FtInternalException.Create(InternalError.DeclarationParser_ParseChar_UnsupportedState, state.ToString());
            }
        }
コード例 #24
0
        private FtLineType CalculateStartLineType(char startChar)
        {
            if (headerRead)
            {
                return((startChar == LineCommentChar) ? FtLineType.Comment : FtLineType.Blank);  // if not comment, assume blank - if got chars, then will be changed to Rec
            }
            else
            {
                if (declared && lineParser.LineCount < 2)
                {
                    // Declaration Line Type
                    switch (lineParser.LineCount)
                    {
                    case 0: return(FtLineType.Signature);

                    case 1: return(FtLineType.Declaration2);

                    default:
                        throw FtInternalException.Create(InternalError.SerializationReader_ParseChar_UnexpectedDeclarationLineCount, lineParser.LineCount.ToString());
                    }
                }
                else
                {
                    if (metaEmbedded && !embeddedMetaRead)
                    {
                        // Expecting or in Embedded Meta lines
                        if (lineType == FtLineType.EmbeddedMeta)
                        {
                            return(FtLineType.EmbeddedMeta);
                        }
                        else
                        {
                            if (startChar == LineCommentChar)
                            {
                                return(FtLineType.Comment);
                            }
                            else
                            {
                                return(FtLineType.Blank); // the only other thing it could be
                            }
                        }
                    }
                    else
                    {
                        // if Declaration done or not present and Embedded Meta done or not present, then only reason
                        // still in header is to read heading lines.

                        Debug.Assert(HeadingLineCount > 0 && !headingLinesRead);

                        if (lineType == FtLineType.Heading)
                        {
                            return(FtLineType.Heading);
                        }
                        else
                        {
                            if (startChar == LineCommentChar)
                            {
                                return(FtLineType.Comment);
                            }
                            else
                            {
                                return(FtLineType.Blank); // assume this - may also be first heading line
                            }
                        }
                    }
                }
            }
        }
コード例 #25
0
        private void ParseInChar(char aChar, bool embedEndOfLine, out LineEndedType lineEndedType)
        {
            switch (core.EndOfLineType)
            {
            case FtEndOfLineType.Auto:
                switch (aChar)
                {
                case CarriageReturnChar:
                    if (embedEndOfLine)
                    {
                        if (charReader.Peek() == LineFeedChar)
                        {
                            inLineState = FtLineState.InNextTextOut;
                        }
                        else
                        {
                            inLineState = FtLineState.InTextOut;
                        }
                        lineEndedType = LineEndedType.Not;
                    }
                    else
                    {
                        inLineState   = (charReader.Peek() == LineFeedChar) ? FtLineState.InPendingNextLineFeed : FtLineState.Out;
                        lineEndedType = LineEndedType.Initiated;
                    }
                    break;

                case LineFeedChar:
                    if (embedEndOfLine)
                    {
                        inLineState   = FtLineState.InTextOut;
                        lineEndedType = LineEndedType.Not;
                    }
                    else
                    {
                        inLineState   = FtLineState.Out;
                        lineEndedType = LineEndedType.Initiated;
                    }
                    break;

                default:
                    lineLength++;
                    textLineLength++;
                    lineEndedType = LineEndedType.Not;
                    break;
                }
                break;

            case FtEndOfLineType.CrLf:
                if (aChar != CarriageReturnChar)
                {
                    lineEndedType = LineEndedType.Not;
                }
                else
                {
                    if (embedEndOfLine)
                    {
                        if (charReader.Peek() == LineFeedChar)
                        {
                            inLineState = FtLineState.InNextTextOut;
                        }
                        else
                        {
                            inLineState = FtLineState.InTextOut;
                        }
                        lineEndedType = LineEndedType.Not;
                    }
                    else
                    {
                        if (charReader.Peek() != LineFeedChar)
                        {
                            lineEndedType = LineEndedType.Not;
                        }
                        else
                        {
                            inLineState   = FtLineState.InPendingNextLineFeed;
                            lineEndedType = LineEndedType.Initiated;
                        }
                    }
                }
                break;

            case FtEndOfLineType.Char:
                if (embedEndOfLine)
                {
                    inLineState   = FtLineState.InTextOut;
                    lineEndedType = LineEndedType.Not;
                }
                else
                {
                    inLineState   = FtLineState.Out;
                    lineEndedType = LineEndedType.Initiated;
                }
                break;

            default:
                throw FtInternalException.Create(InternalError.LineParser_ParseInChar_UnsupportedEndOfLineType, core.EndOfLineType.ToString());
            }
        }
コード例 #26
0
        protected virtual bool ResolveProperties(FtMeta meta, out string errorDescription)
        {
            errorDescription                = "";
            lastLineEndedTypeSpecified      = false;
            allowIncompleteRecordsSpecified = false;
            bool result = false;

            foreach (FtMeta.PropertyId id in Enum.GetValues(typeof(FtMeta.PropertyId)))
            {
                switch (id)
                {
                case FtMeta.PropertyId.AllowEndOfLineCharInQuotes:
                    result = ResolveAllowEndOfLineCharInQuotes(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.Culture:
                    result = ResolveCulture(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.DelimiterChar:
                    result = ResolveDelimiterChar(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.EndOfLineAutoWriteType:
                    result = ResolveEndOfLineAutoWriteType(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.EndOfLineChar:
                    result = ResolveEndOfLineChar(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.EndOfLineType:
                    result = ResolveEndOfLineType(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.LastLineEndedType:
                    result = ResolveLastLineEndedType(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.HeadingAlwaysWriteOptionalQuote:
                    result = ResolveHeadingAlwaysWriteOptionalQuote(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.HeadingConstraint:
                    result = ResolveHeadingConstraint(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.HeadingEndOfValueChar:
                    result = ResolveHeadingEndOfValueChar(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.HeadingLineCount:
                    result = ResolveHeadingLineCount(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.HeadingPadAlignment:
                    result = ResolveHeadingPadAlignment(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.HeadingPadChar:
                    result = ResolveHeadingPadChar(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.HeadingPadCharType:
                    result = ResolveHeadingPadCharType(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.HeadingQuotedType:
                    result = ResolveHeadingQuotedType(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.HeadingTruncateChar:
                    result = ResolveHeadingTruncateChar(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.HeadingTruncateType:
                    result = ResolveHeadingTruncateType(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.HeadingWritePrefixSpace:
                    result = ResolveHeadingWritePrefixSpace(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.IgnoreBlankLines:
                    result = ResolveIgnoreBlankLines(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.IgnoreExtraChars:
                    result = ResolveIgnoreExtraChars(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.AllowIncompleteRecords:
                    result = ResolveAllowIncompleteRecords(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.LineCommentChar:
                    result = ResolveLineCommentChar(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.MainHeadingLineIndex:
                    result = ResolveMainHeadingLineIndex(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.QuoteChar:
                    result = ResolveQuoteChar(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.StuffedEmbeddedQuotes:
                    result = ResolveStuffedEmbeddedQuotes(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.SubstitutionChar:
                    result = ResolveSubstitutionChar(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.SubstitutionsEnabled:
                    result = ResolveSubstitutionsEnabled(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.LegacyEndOfLineIsSeparator:
                    result = ResolveLegacyEndOfLineIsSeparator(meta, out errorDescription);
                    break;

                case FtMeta.PropertyId.LegacyIncompleteRecordsAllowed:
                    result = ResolveLegacyIncompleteRecordsAllowed(meta, out errorDescription);
                    break;

                default:
                    throw FtInternalException.Create(InternalError.FieldedTextReadElement_ResolveProperties_UnsupportedPropertyId, id.ToString());
                }

                if (!result)
                {
                    break;
                }
            }
            return(result);
        }
コード例 #27
0
        internal void ParseChar(char aChar)
        {
            switch (state)
            {
            case State.Out:
                throw FtInternalException.Create(InternalError.HeadingLineRecordParser_ParseChar_OutState);

            case State.InOutField:
                if (fieldCount < core.FieldList.Count)
                {
                    EnterField(core.FieldList[fieldCount]);
                }
                else
                {
                    FtSerializationError error = headingLines ? FtSerializationError.HeadingLineTooManyFields : FtSerializationError.RecordTooManyFields;
                    string formatString        = headingLines ? Properties.Resources.HeadingLineRecordParser_ParseChar_HeadingLineTooManyFields : Properties.Resources.HeadingLineRecordParser_ParseChar_RecordTooManyFields;
                    throw new FtSerializationException(error, string.Format(formatString, core.FieldList.Count));
                }
                ParseChar(aChar);
                break;

            case State.InFixedWidthField:
                bool previousFieldFinished;
                fixedWidthFieldParser.ParseChar(aChar, out previousFieldFinished);
                if (previousFieldFinished)
                {
                    if (!core.Seeking)
                    {
                        LoadFixedWidthHeadingValue();
                    }

                    ExitActiveField();

                    if (fieldCount < core.FieldList.Count || !core.IgnoreExtraChars)
                    {
                        state = State.InOutField;
                    }
                    else
                    {
                        state = State.OutIgnoreChars;
                        ignoreExtraCharsStartPosition = charReader.Position;
                    }
                    ParseChar(aChar);
                }
                break;

            case State.InDelimitedField:
                bool fieldFinished;
                delimitedFieldParser.ParseChar(aChar, out fieldFinished);
                if (fieldFinished)
                {
                    // aChar was delimiter
                    if (!core.Seeking)
                    {
                        LoadDelimitedHeadingValue();
                    }

                    ExitActiveField();

                    if (fieldCount < core.FieldList.Count || !core.IgnoreExtraChars)
                    {
                        state = State.InOutField;
                    }
                    else
                    {
                        state = State.OutIgnoreChars;
                        ignoreExtraCharsStartPosition = charReader.Position;
                    }
                }
                break;

            case State.OutIgnoreChars:
                // nothing to do
                break;

            default:
                throw FtInternalException.Create(InternalError.HeadingLineRecordParser_ParseChar_UnsupportedState, state.ToString());
            }
        }
コード例 #28
0
        internal protected virtual bool ResolveItemsTo(FtMetaSequence sequence, FtMetaFieldList fieldList, FtMetaSequenceList sequenceList, out string errorDescription)
        {
            ItemSorter.Rec[]          sorterRecArray = new ItemSorter.Rec[itemList.Count + fieldIndices.Length];
            SequenceItemReadElement[] sortedItemElements;

            for (int i = 0; i < itemList.Count; i++)
            {
                SequenceItemReadElement itemElement = itemList[i];

                sorterRecArray[i].Target   = itemElement;
                sorterRecArray[i].Implicit = i;
                sorterRecArray[i].Explicit = itemElement.ExplicitIndex;
            }

            int elementallyDefinedItemCount = itemList.Count;

            for (int i = 0; i < fieldIndices.Length; i++)
            {
                SequenceItemReadElement itemElement = new SequenceItemReadElement();
                // Add FieldIndex to element as if it were read from an attribute.
                int    fieldIndex     = fieldIndices[i];
                string attributeName  = SequenceItemPropertyIdFormatter.ToAttributeName(FtMetaSequenceItem.PropertyId.FieldIndex);
                string attributeValue = FtStandardText.Get(fieldIndex);
                if (!itemElement.TryAddOrIgnoreAttribute(attributeName, attributeValue, out errorDescription))
                {
                    throw FtInternalException.Create(InternalError.SequenceReadElement_ResolveItemsTo_TryAddOrIgnoreAttribute, errorDescription); // program error
                }
                else
                {
                    int implicitIndex = elementallyDefinedItemCount + i;
                    sorterRecArray[implicitIndex].Target   = itemElement;
                    sorterRecArray[implicitIndex].Implicit = implicitIndex;
                    sorterRecArray[implicitIndex].Explicit = -1;
                }
            }

            int duplicateExplicitIndex;

            if (!ItemSorter.TrySort(sorterRecArray, out sortedItemElements, out duplicateExplicitIndex))
            {
                errorDescription = string.Format(Properties.Resources.SequenceReadElement_ResolveItemsTo_DuplicateExplicitIndex, duplicateExplicitIndex);
                return(false);
            }
            else
            {
                errorDescription = "";
                bool result = true;

                for (int i = 0; i < sortedItemElements.Length; i++)
                {
                    SequenceItemReadElement itemElement = sortedItemElements[i];
                    FtMetaSequenceItem      item        = sequence.ItemList.New();
                    if (!itemElement.ResolveTo(item, fieldList, sequenceList, out errorDescription))
                    {
                        result = false;
                        break;
                    }
                }

                return(result);
            }
        }
コード例 #29
0
        internal void Finish()
        {
            switch (state)
            {
            case State.Out:
                // nothing to do
                break;

            case State.InOutField:
                state = State.Out;
                break;

            case State.InFixedWidthField:
                if (!core.Seeking)
                {
                    LoadFixedWidthHeadingValue();
                }
                ExitActiveField();
                state = State.Out;
                break;

            case State.InDelimitedField:
                if (!core.Seeking)
                {
                    LoadDelimitedHeadingValue();
                }
                ExitActiveField();
                state = State.Out;
                break;

            case State.OutIgnoreChars:
                state = State.Out;
                break;

            default:
                throw FtInternalException.Create(InternalError.HeadingLineRecordParser_Finish_UnsupportedState, state.ToString());
            }

            if (fieldCount < core.FieldList.Count)
            {
                if (!core.AllowIncompleteRecords)
                {
                    FtSerializationError error = headingLines ? FtSerializationError.HeadingLineNotEnoughFields : FtSerializationError.RecordNotEnoughFields;
                    string formatString        = headingLines ? Properties.Resources.HeadingLineRecordParser_Finish_HeadingLineNotEnoughFields : Properties.Resources.HeadingLineRecordParser_Finish_RecordNotEnoughFields;
                    throw new FtSerializationException(error, string.Format(formatString, fieldCount, core.FieldList.Count));
                }
                else
                {
                    for (int i = fieldCount; i < core.FieldList.Count; i++)
                    {
                        activeField.LoadPosition(-1, -1, -1, -1);
                        if (headingLines)
                        {
                            activeField.LoadHeading(index, "");
                        }
                        else
                        {
                            activeField.LoadNullValue();
                        }
                    }
                }
            }
        }
コード例 #30
0
        internal void ParseChar(char aChar, out bool previousFieldFinished)
        {
            if (fieldLength >= fieldWidth)
            {
                previousFieldFinished = true;
            }
            else
            {
                previousFieldFinished = false;

                fieldLength++;

                switch (state)
                {
                case State.WaitingLeftEndOfValue:
                    if (aChar != fieldEndOfValueChar)
                    {
                        textBuilder.Append(aChar);     // may not encounter any EndOfValue char
                    }
                    else
                    {
                        textBuilder.Clear();
                        rawOffset = fieldLength;
                        state     = State.NoMorePadding;
                    }
                    break;

                case State.LeftPadding:
                    if (aChar != fieldPadChar)
                    {
                        textBuilder.Append(aChar);
                        rawOffset = fieldLength - 1;
                        state     = State.NoMorePadding;
                    }
                    break;

                case State.NoMorePadding:
                    textBuilder.Append(aChar);
                    break;

                case State.WaitingRightEndOfValue:
                    if (aChar != fieldEndOfValueChar)
                    {
                        textBuilder.Append(aChar);     // may not encounter any EndOfValue char
                    }
                    else
                    {
                        state = State.RestIsPadding;
                    }
                    break;

                case State.WaitingRightPadding:
                    if (aChar != fieldPadChar)
                    {
                        textBuilder.Append(aChar);
                    }
                    else
                    {
                        rightPaddingCharCount = 1;
                        state = State.RightPadding;
                    }
                    break;

                case State.RightPadding:
                    if (aChar == fieldPadChar)
                    {
                        rightPaddingCharCount++;
                    }
                    else
                    {
                        // Prematurely identified right padding previous start.  Still not started
                        textBuilder.Append(new string(fieldPadChar, rightPaddingCharCount));     // add chars previously thought to be padding
                        textBuilder.Append(aChar);
                        rightPaddingCharCount = 0;
                        state = State.WaitingRightPadding;
                    }
                    break;

                case State.RestIsPadding:
                    break;

                default:
                    throw FtInternalException.Create(InternalError.FixedWidthFieldParser_ParseChar_UnsupportedState, state.ToString());
                }
            }
        }