summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorGravatar MichalMoskal <unknown>2011-02-15 21:38:18 +0000
committerGravatar MichalMoskal <unknown>2011-02-15 21:38:18 +0000
commitf27cd4a2be87c59d6988feb83533e32a77886e61 (patch)
treebf6d064ae9434caef15d51d5975b12fa44c4eb5f /Source
parentcc665557287b709705414c637298cc3097fe1136 (diff)
Add some extension methods to IEnumberable<T>
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/Util.cs41
1 files changed, 41 insertions, 0 deletions
diff --git a/Source/Core/Util.cs b/Source/Core/Util.cs
index 6bf0da30..6ed01e7f 100644
--- a/Source/Core/Util.cs
+++ b/Source/Core/Util.cs
@@ -8,6 +8,47 @@ namespace Microsoft.Boogie {
using System.IO;
using System.Collections;
using System.Diagnostics.Contracts;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+
+ public static class LinqExtender
+ {
+ public static string Concat(this IEnumerable<string> strings, string separator)
+ {
+ var sb = new StringBuilder();
+ var first = true;
+ foreach (var s in strings) {
+ if (!first)
+ sb.Append(separator);
+ first = false;
+ sb.Append(s);
+ }
+ return sb.ToString();
+ }
+
+ public static string MapConcat<T>(this IEnumerable<T> objects, Func<T,string> toString, string separator)
+ {
+ var sb = new StringBuilder();
+ var first = true;
+ foreach (var s in objects) {
+ if (!first)
+ sb.Append(separator);
+ first = false;
+ sb.Append(toString(s));
+ }
+ return sb.ToString();
+ }
+
+ public static IEnumerable<T> SkipEnd<T>(this IEnumerable<T> source, int count)
+ {
+ var l = source.ToList();
+ if (count >= l.Count)
+ return Enumerable.Empty<T>();
+ l.RemoveRange(l.Count - count, count);
+ return l;
+ }
+ }
public class TokenTextWriter : IDisposable {
string/*!*/ filename;