]> git.openstreetmap.org Git - nominatim.git/blobdiff - nominatim/tokenizer/sanitizers/split_name_list.py
sanitizer: move helpers into a configuration class
[nominatim.git] / nominatim / tokenizer / sanitizers / split_name_list.py
index df2c305bbc2e27cf925594c08be1111650c4cdf6..c9db0a9da83b2e7878133dc5e63e4477dfff29e5 100644 (file)
@@ -1,21 +1,21 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# This file is part of Nominatim. (https://nominatim.org)
+#
+# Copyright (C) 2022 by the Nominatim developer community.
+# For a full list of authors see the git log.
 """
-Name processor that splits name values with multiple values into their components.
-"""
-import re
-
-from nominatim.errors import UsageError
+Sanitizer that splits lists of names into their components.
 
-def create(func):
+Arguments:
+    delimiters: Define the set of characters to be used for
+                splitting the list. (default: ',;')
+"""
+def create(config):
     """ Create a name processing function that splits name values with
-        multiple values into their components. The optional parameter
-        'delimiters' can be used to define the characters that should be used
-        for splitting. The default is ',;'.
+        multiple values into their components.
     """
-    delimiter_set = set(func.get('delimiters', ',;'))
-    if not delimiter_set:
-        raise UsageError("Set of delimiters in split-name-list sanitizer is empty.")
-
-    regexp = re.compile('\\s*[{}]\\s*'.format(''.join('\\' + d for d in delimiter_set)))
+    regexp = config.get_delimiter()
 
     def _process(obj):
         if not obj.names: