Commit 34daf35c authored by Michael Büsch's avatar Michael Büsch

common: Add strEqual() helper for case insensitive string compare

Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent f92b6682
......@@ -57,6 +57,7 @@ __all__ = [
"envClearLang",
"isInteger",
"isString",
"strEqual",
"isiterable",
"getfirst",
"getany",
......@@ -306,6 +307,18 @@ def __isString_python3(value):
isString = py23(__isString_python2,
__isString_python3)
def strEqual(string0, string1, caseSensitive=True):
"""Compare string0 to string1.
If caseSensitive is False, case is ignored.
Returns True, if both strings are equal.
"""
if not caseSensitive:
if hasattr(string0, "casefold"):
string0, string1 = string0.casefold(), string1.casefold()
else:
string0, string1 = string0.lower(), string1.lower()
return string0 == string1
def isiterable(obj):
"""Check if an object is iterable.
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment