zabgrab.ui.selection

Parsing of multiple-choice answers such as 1,3,5-8 or all.

Functions

parse_selection(text, count)

Parse a selection of 1-based option numbers into 0-based indices.

zabgrab.ui.selection.parse_selection(text, count)[source]

Parse a selection of 1-based option numbers into 0-based indices.

Accepts comma-separated numbers and inclusive ranges (1,3,5-8), or all. Indices are returned in the order given, without duplicates.

Parameters:
  • text (str) – The answer.

  • count (int) – How many options there are.

Returns:

list of int – The indices of the options chosen.

Raises:

ValueError – With a message suitable for showing to the user.

Return type:

list[int]

Examples

>>> parse_selection("3,1-2,2", 5)
[2, 0, 1]