From c81248b5c2eb42bfe0abfa7894615207bc73a1dc Mon Sep 17 00:00:00 2001 From: Kazi Sohan Date: Sun, 27 Mar 2022 13:12:09 +0600 Subject: [PATCH] Check whether prefix or suffix exist before replacing --- summa/preprocessing/util.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/summa/preprocessing/util.py b/summa/preprocessing/util.py index 0daad9d..fb0b8b3 100644 --- a/summa/preprocessing/util.py +++ b/summa/preprocessing/util.py @@ -10,6 +10,9 @@ def suffix_replace(original, old, new): """ Replaces the old suffix of the original string by a new suffix """ + if not original.endswith(old): + print("'{}' is not found as suffix in '{}'".format(old, original)) + return original return original[: -len(old)] + new @@ -21,4 +24,7 @@ def prefix_replace(original, old, new): :param new: string :return: string """ - return new + original[len(old) :] + if not original.startswith(old): + print("'{}' is not found as prefix in '{}'".format(old, original)) + return original + return new + original[len(old) :] \ No newline at end of file