Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1457)

Unified Diff: Tools/AutoSheriff/string_helpers.py

Issue 398823008: WIP: Add auto-sheriff.appspot.com code to Blink Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Tools/AutoSheriff/string_helpers.py
diff --git a/Tools/AutoSheriff/string_helpers.py b/Tools/AutoSheriff/string_helpers.py
new file mode 100644
index 0000000000000000000000000000000000000000..f2393fb40040c3fd82dd2ee1437702503ca33f4e
--- /dev/null
+++ b/Tools/AutoSheriff/string_helpers.py
@@ -0,0 +1,20 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import itertools
+
+# http://stackoverflow.com/questions/9470611/how-to-do-an-inverse-range-i-e-create-a-compact-range-based-on-a-set-of-numb/9471386#9471386
+def re_range(lst):
+ def sub(x):
+ return x[1] - x[0]
+
+ ranges = []
+ for k, iterable in itertools.groupby(enumerate(sorted(lst)), sub):
+ rng = list(iterable)
+ if len(rng) == 1:
+ s = str(rng[0][1])
+ else:
+ s = "%s-%s" % (rng[0][1], rng[-1][1])
+ ranges.append(s)
+ return ', '.join(ranges)

Powered by Google App Engine
This is Rietveld 408576698