Add two new utility functions to the common module

This commit is contained in:
Veronica Berglyd Olsen
2022-04-05 22:07:20 +02:00
parent 9c9408d78a
commit 7298e1f438
+13
View File
@@ -184,6 +184,12 @@ def checkIntRange(value, first, last, default):
return default
def getMinMax(value, minVal, maxVal):
"""Make sure an integer is between min and max value (inclusive).
"""
return min(maxVal, max(minVal, value))
def checkIntTuple(value, valid, default):
"""Check that an int is an element of a tuple. If it isn't, return
the default value.
@@ -245,6 +251,13 @@ def formatTime(tS):
# String Functions
# =============================================================================================== #
def simplified(string):
"""Take a string an strip leading and trailing whitespaces, and
replace all occurences of (multiple) whitespaces with a 0x20 space.
"""
return " ".join(str(string).strip().split())
def splitVersionNumber(value):
"""Split a version string on the form aa.bb.cc into major, minor
and patch, and computes an integer value aabbcc.