summaryrefslogtreecommitdiff
path: root/monkey/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'monkey/util.py')
-rw-r--r--monkey/util.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/monkey/util.py b/monkey/util.py
index 655cca9..3940f84 100644
--- a/monkey/util.py
+++ b/monkey/util.py
@@ -63,6 +63,18 @@ def get_line(text, n):
return lines[n]
return None
+# Does sequence [a] begin with sequence [b]?
+def startswith(a, b):
+ if len(a) < len(b):
+ return False
+ return all(x == y for x, y in zip(a, b))
+
+# Does sequence [a] end with sequence [b]?
+def endswith(a, b):
+ if len(a) < len(b):
+ return False
+ return all(x == y for x, y in zip(reversed(a), reversed(b)))
+
# Indent each line in [text] by [indent] spaces.
def indent(text, indent=2):
return '\n'.join([' '*indent+line for line in text.split('\n')])