示例#1
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);
                }
            }
        }
示例#2
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());
            }
        }