Ejemplo n.º 1
0
        /// <summary>
        /// Extract the field from the delimited file, removing separators and quotes
        /// and any duplicate quotes within the record
        /// </summary>
        /// <param name="line">line containing record input</param>
        /// <returns>Extract information</returns>
        internal override ExtractedInfo ExtractFieldString(LineInfo line)
        {
            if (IsOptional && line.IsEOL())
            {
                return(ExtractedInfo.Empty);
            }

            if (QuoteChar == '\0')
            {
                return(BasicExtractString(line));
            }
            else
            {
                if (TrimMode == TrimMode.Both || TrimMode == TrimMode.Left)
                {
                    line.TrimStart(TrimChars);
                }

                string quotedStr = QuoteChar.ToString();
                if (line.StartsWith(quotedStr))
                {
                    var res = StringHelper.ExtractQuotedString(line, QuoteChar, QuoteMultiline == MultilineMode.AllowForBoth || QuoteMultiline == MultilineMode.AllowForRead);

                    if (TrimMode == TrimMode.Both || TrimMode == TrimMode.Right)
                    {
                        line.TrimStart(TrimChars);
                    }

                    if (!IsLast && !line.StartsWith(Separator) && !line.IsEOL())
                    {
                        throw new BadUsageException(line, "The field " + this.FieldInfo.Name + " is quoted but the quoted char: " + quotedStr + " not is just before the separator (You can use [FieldTrim] to avoid this error)");
                    }
                    return(res);
                }
                else
                {
                    if (QuoteMode == QuoteMode.OptionalForBoth || QuoteMode == QuoteMode.OptionalForRead)
                    {
                        return(BasicExtractString(line));
                    }
                    else if (line.StartsWithTrim(quotedStr))
                    {
                        throw new BadUsageException(string.Format("The field '{0}' has spaces before the QuotedChar at line {1}. Use the TrimAttribute to by pass this error. Field String: {2}", FieldInfo.Name, line.mReader.LineNumber, line.CurrentString));
                    }
                    else
                    {
                        throw new BadUsageException(string.Format("The field '{0}' not begin with the QuotedChar at line {1}. You can use FieldQuoted(QuoteMode.OptionalForRead) to allow optional quoted field.. Field String: {2}", FieldInfo.Name, line.mReader.LineNumber, line.CurrentString));
                    }
                }
            }
        }
Ejemplo n.º 2
0
		protected override ExtractedInfo ExtractFieldString(LineInfo line)
		{
			if (mIsOptional && line.IsEOL() )
				return ExtractedInfo.Empty;


			if (mQuoteChar == '\0')
				return BasicExtractString(line);
			else
			{
				//TODO: UnComment and Fix

				if (mTrimMode == TrimMode.Both || mTrimMode == TrimMode.Left)
				{

					//int pos = line.mCurrentPos;
					line.TrimStart(mTrimChars);
//					from2 = from.TrimStart(mTrimChars);
					//res.CharsRemoved = line.mCurrentPos - pos;
				}

				string quotedStr = mQuoteChar.ToString();
				if (line.StartsWith(quotedStr))
				{

//					ExtractedInfo res = null;
//					res = new ExtractedInfo(line, line.mCurrentPos);

					return StringHelper.ExtractQuotedString(line, mQuoteChar, mQuoteMultiline == MultilineMode.AllowForBoth || mQuoteMultiline == MultilineMode.AllowForRead);
//					if (mQuoteMultiline == MultilineMode.AllowForBoth || mQuoteMultiline == MultilineMode.AllowForRead)
//					{
//
//						//res.ExtractedString = ei.ExtractedString;
//						//res.CharsRemoved += ei.CharsRemoved;
//						//res.ExtraLines = ei.ExtraLines;
//						//res.NewRestOfLine = ei.NewRestOfLine;
//					}
//					else
//					{
//						return StringHelper.ExtractQuotedString(from2, mQuoteChar, out index);
//						//res.CharsRemoved += index;
//					}

				//	return res;

				}
				else
				{
					if (mQuoteMode == QuoteMode.OptionalForBoth || mQuoteMode == QuoteMode.OptionalForRead)
						return BasicExtractString(line);
					else if (line.StartsWithTrim(quotedStr))
						throw new BadUsageException("The field '" + this.mFieldInfo.Name + "' has spaces before the QuotedChar at line "+ line.mReader.LineNumber.ToString() + ". Use the TrimAttribute to by pass this error. Field String: " + line.CurrentString);
					else
						throw new BadUsageException("The field '" + this.mFieldInfo.Name + "' not begin with the QuotedChar at line "+ line.mReader.LineNumber.ToString() + ". You can use FieldQuoted(QuoteMode.OptionalForRead) to allow optional quoted field.. Field String: " + line.CurrentString);
				}

			}


		}
Ejemplo n.º 3
0
        internal override ExtractedInfo ExtractFieldString(LineInfo line)
        {
            if (mIsOptional && line.IsEOL())
            {
                return(ExtractedInfo.Empty);
            }

            if (mQuoteChar == '\0')
            {
                return(BasicExtractString(line));
            }
            else
            {
                if (mTrimMode == TrimMode.Both || mTrimMode == TrimMode.Left)
                {
                    line.TrimStart(mTrimChars);
                }

                string quotedStr = mQuoteChar.ToString();
                if (line.StartsWith(quotedStr))
                {
                    return(StringHelper.ExtractQuotedString(line, mQuoteChar, mQuoteMultiline == MultilineMode.AllowForBoth || mQuoteMultiline == MultilineMode.AllowForRead));
                }
                else
                {
                    if (mQuoteMode == QuoteMode.OptionalForBoth || mQuoteMode == QuoteMode.OptionalForRead)
                    {
                        return(BasicExtractString(line));
                    }
                    else if (line.StartsWithTrim(quotedStr))
                    {
                        throw new BadUsageException(string.Format("The field '{0}' has spaces before the QuotedChar at line {1}. Use the TrimAttribute to by pass this error. Field String: {2}", mFieldInfo.Name, line.mReader.LineNumber, line.CurrentString));
                    }
                    else
                    {
                        throw new BadUsageException(string.Format("The field '{0}' not begin with the QuotedChar at line {1}. You can use FieldQuoted(QuoteMode.OptionalForRead) to allow optional quoted field.. Field String: {2}", mFieldInfo.Name, line.mReader.LineNumber, line.CurrentString));
                    }
                }
            }
        }
Ejemplo n.º 4
0
        internal override ExtractedInfo ExtractFieldString(LineInfo line)
        {
            if (IsOptional && line.IsEOL() )
                return ExtractedInfo.Empty;

            if (QuoteChar == '\0')
                return BasicExtractString(line);
            else
            {
                if (TrimMode == TrimMode.Both || TrimMode == TrimMode.Left)
                {
                    line.TrimStart(TrimChars);
                }

                string quotedStr = QuoteChar.ToString();
                if (line.StartsWith(quotedStr))
                {
                    return StringHelper.ExtractQuotedString(line, QuoteChar, QuoteMultiline == MultilineMode.AllowForBoth || QuoteMultiline == MultilineMode.AllowForRead);
                }
                else
                {
                    if (QuoteMode == QuoteMode.OptionalForBoth || QuoteMode == QuoteMode.OptionalForRead)
                        return BasicExtractString(line);
                    else if (line.StartsWithTrim(quotedStr))
                        throw new BadUsageException(string.Format("The field '{0}' has spaces before the QuotedChar at line {1}. Use the TrimAttribute to by pass this error. Field String: {2}", FieldInfo.Name, line.mReader.LineNumber, line.CurrentString));
                    else
                        throw new BadUsageException(string.Format("The field '{0}' not begin with the QuotedChar at line {1}. You can use FieldQuoted(QuoteMode.OptionalForRead) to allow optional quoted field.. Field String: {2}", FieldInfo.Name, line.mReader.LineNumber, line.CurrentString));
                }

            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Extract the field from the delimited file, removing separators and quotes
        /// and any duplicate quotes within the record
        /// </summary>
        /// <param name="line">line containing record input</param>
        /// <returns>Extract information</returns>
        internal override ExtractedInfo ExtractFieldString(LineInfo line)
        {
            if (IsOptional && line.IsEOL())
                return ExtractedInfo.Empty;

            if (QuoteChar == '\0')
                return BasicExtractString(line);
            else {
                if (TrimMode == TrimMode.Both ||
                    TrimMode == TrimMode.Left)
                    line.TrimStart(TrimChars);

                string quotedStr = QuoteChar.ToString();
                if (line.StartsWith(quotedStr)) {
                    var res = StringHelper.ExtractQuotedString(line,
                        QuoteChar,
                        QuoteMultiline == MultilineMode.AllowForBoth || QuoteMultiline == MultilineMode.AllowForRead);

                    if (TrimMode == TrimMode.Both ||
                        TrimMode == TrimMode.Right)
                        line.TrimStart(TrimChars);

                    if (!IsLast &&
                        !line.StartsWith(Separator) &&
                        !line.IsEOL()) {
                        throw new BadUsageException(line,
                            "The field " + this.FieldInfo.Name + " is quoted but the quoted char: " + quotedStr +
                            " not is just before the separator (You can use [FieldTrim] to avoid this error)");
                    }
                    return res;
                }
                else {
                    if (QuoteMode == QuoteMode.OptionalForBoth ||
                        QuoteMode == QuoteMode.OptionalForRead)
                        return BasicExtractString(line);
                    else if (line.StartsWithTrim(quotedStr)) {
                        throw new BadUsageException(
                            string.Format(
                                "The field '{0}' has spaces before the QuotedChar at line {1}. Use the TrimAttribute to by pass this error. Field String: {2}",
                                FieldInfo.Name,
                                line.mReader.LineNumber,
                                line.CurrentString));
                    }
                    else {
                        throw new BadUsageException(
                            string.Format(
                                "The field '{0}' does not begin with the QuotedChar at line {1}. You can use FieldQuoted(QuoteMode.OptionalForRead) to allow optional quoted field. Field String: {2}",
                                FieldInfo.Name,
                                line.mReader.LineNumber,
                                line.CurrentString));
                    }
                }
            }
        }
Ejemplo n.º 6
0
        protected override ExtractedInfo ExtractFieldString(LineInfo line)
        {
            if (mIsOptional && line.IsEOL())
            {
                return(ExtractedInfo.Empty);
            }


            if (mQuoteChar == '\0')
            {
                return(BasicExtractString(line));
            }
            else
            {
                //TODO: UnComment and Fix

                if (mTrimMode == TrimMode.Both || mTrimMode == TrimMode.Left)
                {
                    //int pos = line.mCurrentPos;
                    line.TrimStart(mTrimChars);
//					from2 = from.TrimStart(mTrimChars);
                    //res.CharsRemoved = line.mCurrentPos - pos;
                }

                string quotedStr = mQuoteChar.ToString();
                if (line.StartsWith(quotedStr))
                {
//					ExtractedInfo res = null;
//					res = new ExtractedInfo(line, line.mCurrentPos);

                    return(StringHelper.ExtractQuotedString(line, mQuoteChar, mQuoteMultiline == MultilineMode.AllowForBoth || mQuoteMultiline == MultilineMode.AllowForRead));
//					if (mQuoteMultiline == MultilineMode.AllowForBoth || mQuoteMultiline == MultilineMode.AllowForRead)
//					{
//
//						//res.ExtractedString = ei.ExtractedString;
//						//res.CharsRemoved += ei.CharsRemoved;
//						//res.ExtraLines = ei.ExtraLines;
//						//res.NewRestOfLine = ei.NewRestOfLine;
//					}
//					else
//					{
//						return StringHelper.ExtractQuotedString(from2, mQuoteChar, out index);
//						//res.CharsRemoved += index;
//					}

                    //	return res;
                }
                else
                {
                    if (mQuoteMode == QuoteMode.OptionalForBoth || mQuoteMode == QuoteMode.OptionalForRead)
                    {
                        return(BasicExtractString(line));
                    }
                    else if (line.StartsWithTrim(quotedStr))
                    {
                        throw new BadUsageException("The field '" + this.mFieldInfo.Name + "' has spaces before the QuotedChar at line " + line.mReader.LineNumber.ToString() + ". Use the TrimAttribute to by pass this error. Field String: " + line.CurrentString);
                    }
                    else
                    {
                        throw new BadUsageException("The field '" + this.mFieldInfo.Name + "' not begin with the QuotedChar at line " + line.mReader.LineNumber.ToString() + ". You can use FieldQuoted(QuoteMode.OptionalForRead) to allow optional quoted field.. Field String: " + line.CurrentString);
                    }
                }
            }
        }