changeset 19:19d2c55c3928

util: introduce skiplines
author Idan Kamara <idankk86@gmail.com>
date Thu, 11 Aug 2011 15:42:58 +0300
parents 518149e32888
children 6a9d16ddae31
files hglib/util.py
diffstat 1 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hglib/util.py	Thu Aug 11 15:20:49 2011 +0300
+++ b/hglib/util.py	Thu Aug 11 15:42:58 2011 +0300
@@ -24,6 +24,27 @@
             return cs.read()
     return ''
 
+def skiplines(s, prefix):
+    """
+    Skip lines starting with prefix in s
+
+    >>> skiplines('a\\nb\\na\\n', 'a')
+    'b\\na\\n'
+    >>> skiplines('a\\na\\n', 'a')
+    ''
+    >>> skiplines('', 'a')
+    ''
+    >>> skiplines('a\\nb', 'b')
+    'a\\nb'
+    """
+    cs = cStringIO.StringIO(s)
+
+    for line in cs:
+        if not line.startswith(prefix):
+            return line + cs.read()
+
+    return ''
+
 def cmdbuilder(name, *args, **kwargs):
     """
     A helper for building the command arguments