summaryrefslogtreecommitdiffstats
path: root/sphinx/util/index_entries.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:25:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:25:40 +0000
commitcf7da1843c45a4c2df7a749f7886a2d2ba0ee92a (patch)
tree18dcde1a8d1f5570a77cd0c361de3b490d02c789 /sphinx/util/index_entries.py
parentInitial commit. (diff)
downloadsphinx-cf7da1843c45a4c2df7a749f7886a2d2ba0ee92a.tar.xz
sphinx-cf7da1843c45a4c2df7a749f7886a2d2ba0ee92a.zip
Adding upstream version 7.2.6.upstream/7.2.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sphinx/util/index_entries.py')
-rw-r--r--sphinx/util/index_entries.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/sphinx/util/index_entries.py b/sphinx/util/index_entries.py
new file mode 100644
index 0000000..1004684
--- /dev/null
+++ b/sphinx/util/index_entries.py
@@ -0,0 +1,27 @@
+from __future__ import annotations
+
+
+def split_index_msg(entry_type: str, value: str) -> list[str]:
+ # new entry types must be listed in util/nodes.py!
+ if entry_type == 'single':
+ try:
+ return _split_into(2, 'single', value)
+ except ValueError:
+ return _split_into(1, 'single', value)
+ if entry_type == 'pair':
+ return _split_into(2, 'pair', value)
+ if entry_type == 'triple':
+ return _split_into(3, 'triple', value)
+ if entry_type in {'see', 'seealso'}:
+ return _split_into(2, 'see', value)
+ msg = f'invalid {entry_type} index entry {value!r}'
+ raise ValueError(msg)
+
+
+def _split_into(n: int, type: str, value: str) -> list[str]:
+ """Split an index entry into a given number of parts at semicolons."""
+ parts = [x.strip() for x in value.split(';', n - 1)]
+ if len(list(filter(None, parts))) < n:
+ msg = f'invalid {type} index entry {value!r}'
+ raise ValueError(msg)
+ return parts