From 8f2ec5bf199c1dfff4f70df6d065bda74e2f2770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Luttringer?= Date: Thu, 20 Jun 2013 18:39:11 +0200 Subject: [PATCH] Add strcspn in tools --- installsystems/tools.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/installsystems/tools.py b/installsystems/tools.py index 0dcc04b..2e5b2fc 100644 --- a/installsystems/tools.py +++ b/installsystems/tools.py @@ -32,6 +32,7 @@ import time import urllib2 from subprocess import call, check_call, CalledProcessError +from itertools import takewhile import installsystems from progressbar import Widget, ProgressBar, Percentage @@ -733,3 +734,9 @@ def argv(): return [unicode(x, encoding=locale.getpreferredencoding()) for x in sys.argv] except UnicodeDecodeError as e: raise ISError("Invalid character encoding in command line") + +def strcspn(string, pred): + ''' + Python implementation of libc strcspn + ''' + return len(list(takewhile(lambda x: x not in pred, string))) -- GitLab