From 234ab243f15cd025e323396e479bc771398b63a8 Mon Sep 17 00:00:00 2001 From: Michael Lockwood Date: Wed, 6 Nov 2024 07:52:23 +0000 Subject: [PATCH] Additional comments and spelling corrections for util functions --- web/domains/case/export/forms.py | 2 +- web/utils/__init__.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/web/domains/case/export/forms.py b/web/domains/case/export/forms.py index 9eb444bdb..87ffe0476 100644 --- a/web/domains/case/export/forms.py +++ b/web/domains/case/export/forms.py @@ -947,5 +947,5 @@ def _normalize_address(address: str) -> str: # Strip trailing comma address = address.rstrip(",") - # Replace comma without a following whitespace charatcer with a comma and a space + # Replace comma without a following whitespace character with a comma and a space return re.sub(r",(?=\S)", ", ", address) diff --git a/web/utils/__init__.py b/web/utils/__init__.py index 6956af16c..c1fb5b2cf 100644 --- a/web/utils/__init__.py +++ b/web/utils/__init__.py @@ -38,8 +38,13 @@ def newlines_to_commas(field: str) -> str: "123 Sesame St\nSesame Land\n\nSesame" -> "123 Sesame St, Sesame Land, Sesame" "123 Sesame St,\nSesame Land,\n\n Sesame" -> "123 Sesame St, Sesame Land, Sesame" """ + # Replace all newlines with commas. Strip all spaces and commas before the newline field = re.sub(r"(\s+)?(,)?(\s+)?(\n+)", ", ", field.strip()) + + # Replace all whitespace with a single space and strip commas from the ends of the text field = clean_whitespace(field.strip(",")) + + # Replace double commas and commas separated by a space with a single comma return re.sub(r"(,)(( ,)+|(,)+)", ",", field)