Preserve case repalce now works

This commit is contained in:
Veronica K. B. Olsen
2020-06-17 17:15:30 +02:00
parent c3c0bd7abe
commit 0ddb7ad1de
2 changed files with 33 additions and 4 deletions
+21
View File
@@ -172,3 +172,24 @@ def splitVersionNumber(vString):
vInt = vMajor*10000 + vMinor*100 + vPatch
return [vMajor, vMinor, vPatch, vInt]
def transferCase(theSource, theTarget):
"""Transfers the case of the source word to the target word. This
will consider all upper or lower, and first char capitalisation.
"""
theResult = theTarget
if not isinstance(theSource, str) or not isinstance(theTarget, str):
return theResult
if len(theTarget) < 1 or len(theSource) < 1:
return theResult
if theSource[0] == theSource[0].upper():
theResult = theTarget[0].upper() + theTarget[1:]
if theSource == theSource.upper():
theResult = theTarget.upper()
elif theSource == theSource.lower():
theResult = theTarget.lower()
return theResult