Add two new utility functions to the common module
This commit is contained in:
@@ -184,6 +184,12 @@ def checkIntRange(value, first, last, default):
|
|||||||
return 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):
|
def checkIntTuple(value, valid, default):
|
||||||
"""Check that an int is an element of a tuple. If it isn't, return
|
"""Check that an int is an element of a tuple. If it isn't, return
|
||||||
the default value.
|
the default value.
|
||||||
@@ -245,6 +251,13 @@ def formatTime(tS):
|
|||||||
# String Functions
|
# 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):
|
def splitVersionNumber(value):
|
||||||
"""Split a version string on the form aa.bb.cc into major, minor
|
"""Split a version string on the form aa.bb.cc into major, minor
|
||||||
and patch, and computes an integer value aabbcc.
|
and patch, and computes an integer value aabbcc.
|
||||||
|
|||||||
Reference in New Issue
Block a user