summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--string_utils.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/string_utils.py b/string_utils.py
index 097dc1b..45607f3 100644
--- a/string_utils.py
+++ b/string_utils.py
@@ -861,16 +861,16 @@ def words_count(in_str: str) -> int:
return len(WORDS_COUNT_RE.findall(in_str))
-def generate_uuid(as_hex: bool = False) -> str:
+def generate_uuid(omit_dashes: bool = False) -> str:
"""
Generated an UUID string (using `uuid.uuid4()`).
generate_uuid() # possible output: '97e3a716-6b33-4ab9-9bb1-8128cb24d76b'
- generate_uuid(as_hex=True) # possible output: '97e3a7166b334ab99bb18128cb24d76b'
+ generate_uuid(omit_dashes=True) # possible output: '97e3a7166b334ab99bb18128cb24d76b'
"""
uid = uuid4()
- if as_hex:
+ if omit_dashes:
return uid.hex
return str(uid)
@@ -1553,6 +1553,19 @@ def path_ancestors_before_descendants_sort_key(volume: str) -> Tuple[str]:
return tuple([x for x in volume.split('/') if len(x) > 0])
+def replace_all(in_str: str, replace_set: str, replacement: str) -> str:
+ """Execute several replace operations in a row.
+
+ >>> s = 'this_is a-test!'
+ >>> replace_all(s, ' _-!', '')
+ 'thisisatest'
+
+ """
+ for char in replace_set:
+ in_str = in_str.replace(char, replacement)
+ return in_str
+
+
if __name__ == '__main__':
import doctest
doctest.testmod()