public static IEnumerable <string> Words(this TextReader self, TextReaderRocksOptions options) { Check.Self(self); CheckOptions(options); return(Tokens(self, options, (p, c) => !char.IsWhiteSpace(c))); }
public static IEnumerable <string> MatchValues(this string self, string regex, RegexOptions options) { Check.Self(self); return(Matches(self, regex, options) .Select(m => m.Value)); }
public static IEnumerable <string> Lines(this TextReader self, TextReaderRocksOptions options) { Check.Self(self); CheckOptions(options); return(CreateLineIterator(self, options)); }
public static IEnumerable <string> Captures(this string self, string regex, RegexOptions options) { Check.Self(self); return(Matches(self, regex, options) .SelectMany(m => m.Groups.Cast <Group> ().Skip(1)) .Select(g => g.Value)); }
public static IEnumerable <IEnumerable <TSource> > Rows <TSource> (this TSource[,] self) { Check.Self(self); int rows = self.GetLength(0); int cols = self.GetLength(1); return(CreateRowsIterator(self, rows, cols)); }
public static ValueReader <TSource> Read <TSource, TValue> (this ValueReader <TSource> self, out TValue value) { Check.Self(self); value = Either.TryParse <TSource, TValue> (self.GetNextItem()) .Fold <TValue> (v => v, v => { throw v; }); return(self); }
public static IEnumerable <string> Tokens(this TextReader self, params Func <char?, char, bool>[] categories) { Check.Self(self); Check.Categories(categories); if (categories.Length == 0) { throw new ArgumentException("categories", "Must provide at least one catagory"); } return(Tokens(self, TextReaderRocksOptions.CloseReader, categories)); }
public static IEnumerable <KeyValuePair <TSource, TResult> > TraverseBreadthFirstWithParent <TSource, TResult>( this TSource self, Func <TSource, TResult> valueSelector, Func <TSource, IEnumerable <TSource> > childrenSelector) { Check.Self(self); Check.ValueSelector(valueSelector); Check.ChildrenSelector(childrenSelector); return(CreateTraverseBreadthFirstWithParentIterator(self, valueSelector, childrenSelector)); }
public static TAttribute GetCustomAttribute <TAttribute> (this ICustomAttributeProvider self) where TAttribute : Attribute { Check.Self(self); var attributes = self.GetCustomAttributes <TAttribute> (); if (attributes == null || attributes.Length == 0) { return(null); } return(attributes [0]); }
public static bool IsNullable(this Type self) { Check.Self(self); if (!self.IsValueType || !self.IsGenericType) { return(false); } return(self.IsGenericTypeDefinition ? false : self.GetGenericTypeDefinition() == typeof(Nullable <>)); }
public static StreamConverter Write <TValue> (this StreamConverter self, TValue value) { Check.Self(self); byte[] data = new byte [Marshal.SizeOf(typeof(TValue))]; GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); try { Marshal.StructureToPtr(value, handle.AddrOfPinnedObject(), false); } finally { handle.Free(); } return(self.Write(data)); }
public static StreamConverter Read <TValue> (this StreamConverter self, out TValue value) { Check.Self(self); byte[] data = new byte [Marshal.SizeOf(typeof(TValue))]; self.Read(data); GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); try { value = (TValue)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(TValue)); } finally { handle.Free(); } return(self); }
public static void WriteTo(this Stream self, Stream destination) { Check.Self(self); Check.Destination(destination); int size = self.CanSeek ? (int)System.Math.Min(self.Length - self.Position, 4096) : 4096; byte[] buf = new byte [size]; int r; while ((r = self.Read(buf, 0, buf.Length)) > 0) { destination.Write(buf, 0, r); } }
public static string Remove(this string self, params string[] targets) { Check.Self(self); if (targets == null) { throw new ArgumentNullException("targets"); } StringBuilder builder = new StringBuilder(self); for (int i = 0; i < targets.Length; ++i) { builder.Replace(targets[i], String.Empty); } return(builder.ToString()); }
public static string Slice(this string self, int start, int end) { Check.Self(self); if (start < 0 || start >= self.Length) { throw new ArgumentOutOfRangeException("start"); } if (end < 0) { end += self.Length + 1; } if (end < start || end > self.Length) { throw new ArgumentOutOfRangeException("end"); } return(self.Substring(start, end - start)); }
public static string Implode <TSource> (this IEnumerable <TSource> self, string separator, Func <TSource, string> selector) { Check.Self(self); Check.Selector(selector); var c = self as ICollection <TSource>; string[] values = new string [c != null ? c.Count : 10]; int i = 0; foreach (var e in self) { if (values.Length == i) { Array.Resize(ref values, i * 2); } values [i++] = selector(e); } if (i < values.Length) { Array.Resize(ref values, i); } return(string.Join(separator, values)); }
public static StreamConverter WithSystemConverter(this Stream self) { Check.Self(self); return(new SystemStreamConverter(self)); }
public static IEnumerable <IEnumerable <TSource> > Rows <TSource> (this TSource[][] self) { Check.Self(self); return(self); }
public static IEnumerable <string> Captures(this string self, string regex) { Check.Self(self); return(Captures(self, regex, RegexOptions.None)); }
public static TAttribute [] GetCustomAttributes <TAttribute> (this ICustomAttributeProvider self) where TAttribute : Attribute { Check.Self(self); return((TAttribute [])self.GetCustomAttributes(typeof(TAttribute), true)); }
public static IEnumerable <string> Tokens(this string self, params Func <char?, char, bool>[] categories) { Check.Self(self); return(new StringReader(self).Tokens(categories)); }
public static TEnum ToEnum <TEnum> (this string self) { Check.Self(self); return((TEnum)Enum.Parse(typeof(TEnum), self)); }
public static ILookup <string, string> CaptureNamedGroups(this string self, string regex) { Check.Self(self); return(CaptureNamedGroups(self, regex, RegexOptions.None)); }
public static ILookup <string, string> CaptureNamedGroups(this string self, string regex, RegexOptions options) { Check.Self(self); return(CreateCaptureNamedGroupsIterator(self, regex, options).ToLookup(s => s.Key, s => s.Value)); }
public static IEnumerable <string> Lines(this string self) { Check.Self(self); return(new StringReader(self).Lines()); }
public static IEnumerable <Match> Matches(this string self, string regex, RegexOptions options) { Check.Self(self); return(new Regex(regex, options).Matches(self).Cast <Match> ()); }