From 7298e1f438b3110a81d2f31e4d92a6be827ab910 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 5 Apr 2022 22:07:20 +0200 Subject: [PATCH] Add two new utility functions to the common module --- novelwriter/common.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/novelwriter/common.py b/novelwriter/common.py index 8e17a7ee..30ac0f2e 100644 --- a/novelwriter/common.py +++ b/novelwriter/common.py @@ -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.