public static IEnumerable <string> ParseNewLineSeparatedString([NotNull] string value) { ArgumentUtility.CheckNotNull("value", value); return(value.Split(new[] { '\n' }).Select(s => s.TrimEnd('\r'))); }
public static bool NotNullAndSameType <T> ([CanBeNull] T a, [CanBeNull] T b) where T : class, IEquatable <T> { ArgumentUtility.CheckNotNull("a", a); return((b != null) && a.GetType() == b.GetType()); }
/// <summary> /// Parses a delimiter-separated string into individual elements. /// </summary> /// <remarks> /// This method handles quotes and escaping. A quoted string may contain commas that /// will not be treated as separators. Commas prefixed with a backslash are treated /// like normal commas, double backslashes are treated as single backslashes. /// </remarks> /// <param name="value"> The string to be parsed. Must not be <see langword="null"/>. </param> /// <param name="delimiter"> The character used for list separation. Default is comma (,). </param> /// <param name="openingQuote"> The character used as opening quote. Default is double quote ("). </param> /// <param name="closingQuote"> The character used as closing quote. Default is double quote ("). </param> /// <param name="escapingChar"> The character used to escape quotes and itself. Default is backslash (\). </param> /// <param name="whitespaceCharacters"> A string containing all characters to be considered whitespace. /// Default is space character only. </param> /// <param name="interpretSpecialCharacters"> If true, the escaping character can be followed by the letters /// r, n or t (case sensitive) for line feeds, new lines or tab characters, respectively. Default is true. </param> public static ParsedItem[] ParseSeparatedList( string value, char delimiter, char openingQuote, char closingQuote, char escapingChar, string whitespaceCharacters, bool interpretSpecialCharacters) { ArgumentUtility.CheckNotNull("value", value); string specialCharacters = "rnt"; string specialCharacterResults = "\r\n\t"; StringBuilder current = new StringBuilder(); List <ParsedItem> items = new List <ParsedItem>(); // ArrayList argsArray = new ArrayList(); bool isQuoted = false; // ArrayList isQuotedArray = new ArrayList(); int len = value.Length; int state = 0; // 0 ... between arguments, 1 ... within argument, 2 ... within quotes for (int i = 0; i < len; ++i) { char c = value[i]; if (state == 0) { if (c == openingQuote) { state = 2; isQuoted = true; } else if (c != delimiter && whitespaceCharacters.IndexOf(c) < 0) { state = 1; current.Append(c); } } else if (state == 1) { if (c == openingQuote) { // the string started without quotes, but enters a quoted area now. isQuoted is still false! state = 2; current.Append(c); } else if (c == delimiter) { state = 0; if (current.Length > 0) { items.Add(new ParsedItem(current.ToString(), isQuoted)); current.Length = 0; isQuoted = false; } } else { current.Append(c); } } else if (state == 2) { if (c == closingQuote) { if (!isQuoted) { current.Append(c); } state = 1; } else if (c == escapingChar) { if ((i + 1) < len) { char next = value[i + 1]; if (next == escapingChar || next == openingQuote || next == closingQuote) { current.Append(next); ++i; } else if (interpretSpecialCharacters && specialCharacters.IndexOf(next) >= 0) { current.Append(specialCharacterResults[specialCharacters.IndexOf(next)]); ++i; } else { current.Append('\\'); } } else { state = 1; } } else { current.Append(c); } } } if (current.Length > 0) { items.Add(new ParsedItem(current.ToString(), isQuoted)); } return((ParsedItem[])items.ToArray()); }
public DelegateBasedDisposable(Action disposeAction) { ArgumentUtility.CheckNotNull("disposeAction", disposeAction); _disposeAction = disposeAction; }
public bool IsInstanceOfType(Type attributeType) { ArgumentUtility.CheckNotNull("attributeType", attributeType); return(attributeType.IsInstanceOfType(AttributeInstance)); }
public CompoundComparer(IEnumerable <IComparer <T> > comparers) { ArgumentUtility.CheckNotNull("comparers", comparers); _comparers = comparers.ToArray(); }
public CompoundComparer(params IComparer <T>[] comparers) : this((IEnumerable <IComparer <T> >)ArgumentUtility.CheckNotNull("comparers", comparers)) { }