public string PeekChars(int numberOfChars) { if (numberOfChars <= 0) { throw ExceptionUtils.GetArgumentExceptionWithArgName("numberOfChars", "TextFieldParser_NumberOfCharsMustBePositive", new string[] { "numberOfChars" }); } if ((this.m_Reader == null) | (this.m_Buffer == null)) { return(null); } if (this.m_EndOfData) { return(null); } string str = this.PeekNextDataLine(); if (str == null) { this.m_EndOfData = true; return(null); } str = str.TrimEnd(new char[] { '\r', '\n' }); if (str.Length < numberOfChars) { return(str); } StringInfo info = new StringInfo(str); return(info.SubstringByTextElements(0, numberOfChars)); }
public string GetEnvironmentVariable(string name) { string environmentVariable = Environment.GetEnvironmentVariable(name); if (environmentVariable == null) { throw ExceptionUtils.GetArgumentExceptionWithArgName("name", "EnvVarNotFound_Name", new string[] { name }); } return(environmentVariable); }
private void ValidateFieldWidthsOnInput(int[] Widths) { int num = Widths.Length - 1; int num3 = num - 1; for (int i = 0; i <= num3; i++) { if (Widths[i] < 1) { throw ExceptionUtils.GetArgumentExceptionWithArgName("FieldWidths", "TextFieldParser_FieldWidthsMustPositive", new string[] { "FieldWidths" }); } } }
private void CheckCommentTokensForWhitespace(string[] tokens) { if (tokens != null) { foreach (string str in tokens) { if (this.m_WhiteSpaceRegEx.IsMatch(str)) { throw ExceptionUtils.GetArgumentExceptionWithArgName("CommentTokens", "TextFieldParser_WhitespaceInToken", new string[0]); } } } }
private void ValidateDelimiters(string[] delimiterArray) { if (delimiterArray != null) { foreach (string str in delimiterArray) { if (str == "") { throw ExceptionUtils.GetArgumentExceptionWithArgName("Delimiters", "TextFieldParser_DelimiterNothing", new string[] { "Delimiters" }); } if (str.IndexOfAny(new char[] { '\r', '\n' }) > -1) { throw ExceptionUtils.GetArgumentExceptionWithArgName("Delimiters", "TextFieldParser_EndCharsInDelimiter", new string[0]); } } } }
private void InitializeFromStream(Stream stream, Encoding defaultEncoding, bool detectEncoding) { if (stream == null) { throw ExceptionUtils.GetArgumentNullException("stream"); } if (!stream.CanRead) { throw ExceptionUtils.GetArgumentExceptionWithArgName("stream", "TextFieldParser_StreamNotReadable", new string[] { "stream" }); } if (defaultEncoding == null) { throw ExceptionUtils.GetArgumentNullException("defaultEncoding"); } this.m_Reader = new StreamReader(stream, defaultEncoding, detectEncoding); this.ReadToBuffer(); }
private void ValidateAndEscapeDelimiters() { if (this.m_Delimiters == null) { throw ExceptionUtils.GetArgumentExceptionWithArgName("Delimiters", "TextFieldParser_DelimitersNothing", new string[] { "Delimiters" }); } if (this.m_Delimiters.Length == 0) { throw ExceptionUtils.GetArgumentExceptionWithArgName("Delimiters", "TextFieldParser_DelimitersNothing", new string[] { "Delimiters" }); } int length = this.m_Delimiters.Length; StringBuilder builder = new StringBuilder(); StringBuilder builder2 = new StringBuilder(); builder2.Append(this.EndQuotePattern + "("); int num3 = length - 1; for (int i = 0; i <= num3; i++) { if (this.m_Delimiters[i] != null) { if (this.m_HasFieldsEnclosedInQuotes && (this.m_Delimiters[i].IndexOf('"') > -1)) { throw ExceptionUtils.GetInvalidOperationException("TextFieldParser_IllegalDelimiter", new string[0]); } string str = Regex.Escape(this.m_Delimiters[i]); builder.Append(str + "|"); builder2.Append(str + "|"); } } this.m_SpaceChars = this.WhitespaceCharacters; this.m_DelimiterRegex = new Regex(builder.ToString(0, builder.Length - 1), RegexOptions.CultureInvariant); builder.Append("\r|\n"); this.m_DelimiterWithEndCharsRegex = new Regex(builder.ToString(), RegexOptions.CultureInvariant); builder2.Append("\r|\n)|\"$"); }