예제 #1
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());
            }
        }
예제 #2
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);
        }
예제 #3
0
        internal void InternalLoadMeta(FtMeta meta)
        {
            sequenceList.Clear();
            substitutionList.Clear();
            fieldList.Clear();
            fieldDefinitionList.Clear();

            string errorMessage;

            if (!meta.Validate(out errorMessage))
            {
                throw new FtSerializationException(FtSerializationError.InvalidMeta, errorMessage);
            }
            else
            {
                culture                         = meta.Culture;
                endOfLineType                   = meta.EndOfLineType;
                endOfLineChar                   = meta.EndOfLineChar;
                endOfLineAutoWriteType          = meta.EndOfLineAutoWriteType;
                lastLineEndedType               = meta.LastLineEndedType;
                quoteChar                       = meta.QuoteChar;
                delimiterChar                   = meta.DelimiterChar;
                lineCommentChar                 = meta.LineCommentChar;
                allowEndOfLineCharInQuotes      = meta.AllowEndOfLineCharInQuotes;
                ignoreBlankLines                = meta.IgnoreBlankLines;
                ignoreExtraChars                = meta.IgnoreExtraChars;
                allowIncompleteRecords          = meta.AllowIncompleteRecords;
                stuffedEmbeddedQuotes           = meta.StuffedEmbeddedQuotes;
                substitutionsEnabled            = meta.SubstitutionsEnabled;
                substitutionChar                = meta.SubstitutionChar;
                headingLineCount                = meta.HeadingLineCount;
                mainHeadingLineIndex            = meta.MainHeadingLineIndex;
                headingConstraint               = meta.HeadingConstraint;
                headingQuotedType               = meta.HeadingQuotedType;
                headingAlwaysWriteOptionalQuote = meta.HeadingAlwaysWriteOptionalQuote;
                headingWritePrefixSpace         = meta.HeadingWritePrefixSpace;
                headingPadAlignment             = meta.HeadingPadAlignment;
                headingPadCharType              = meta.HeadingPadCharType;
                headingPadChar                  = meta.HeadingPadChar;
                headingTruncateType             = meta.HeadingTruncateType;
                headingTruncateChar             = meta.HeadingTruncateChar;
                headingEndOfValueChar           = meta.HeadingEndOfValueChar;

                fieldDefinitionList.Capacity = meta.FieldList.Count;
                fieldList.Capacity           = meta.FieldList.Count;
                for (int i = 0; i < meta.FieldList.Count; i++)
                {
                    FtFieldDefinition fieldDefinition = fieldDefinitionList.New(meta.FieldList[i].DataType);
                    fieldDefinition.LoadMeta(meta.FieldList[i], culture, mainHeadingLineIndex);
                }
                for (int i = 0; i < meta.SubstitutionList.Count; i++)
                {
                    FtSubstitution substitution = substitutionList.New();
                    substitution.LoadMeta(meta.SubstitutionList[i], endOfLineAutoWriteType);
                }

                if (meta.SequenceList.Count == 0)
                {
                    // create a root sequence with all field definitions
                    rootSequence = sequenceList.New(fieldDefinitionList);
                }
                else
                {
                    rootSequence = null;
                    for (int i = 0; i < meta.SequenceList.Count; i++)
                    {
                        FtSequence sequence = sequenceList.New();
                        sequence.LoadMeta(meta.SequenceList[i], meta.FieldList, fieldDefinitionList);

                        if (sequence.Root)
                        {
                            rootSequence = sequence;
                        }
                    }

                    if (rootSequence == null && sequenceList.Count > 0)
                    {
                        rootSequence = sequenceList[0];
                        rootSequence.SetRoot(true);
                    }

                    // must load redirects after ALL sequences are loaded
                    for (int i = 0; i < sequenceList.Count; i++)
                    {
                        sequenceList[i].LoadMetaSequenceRedirects(meta.SequenceList[i], meta.SequenceList, sequenceList);
                    }
                }

                rootFieldCount = rootSequence.ItemList.Count;

                metaLoaded = true;
            }
        }