get_text_context
This commit is contained in:
@@ -96,3 +96,28 @@ def get_paginated_list(items: List[Any], page: int, page_size: int) -> List[Any]
|
||||
start_idx = (page - 1) * page_size
|
||||
end_idx = start_idx + page_size
|
||||
return items[start_idx:end_idx]
|
||||
|
||||
def parse_indices(indices_str: str) -> List[int]:
|
||||
"""
|
||||
Parses a string like '11, 31-33, 44' into a list of 1-based indices.
|
||||
Preserves the order specified in the string.
|
||||
"""
|
||||
indices = []
|
||||
parts = [p.strip() for p in indices_str.split(',')]
|
||||
for part in parts:
|
||||
if not part:
|
||||
continue
|
||||
if '-' in part:
|
||||
try:
|
||||
start, end = map(int, part.split('-'))
|
||||
step = 1 if start <= end else -1
|
||||
for i in range(start, end + step, step):
|
||||
indices.append(i)
|
||||
except ValueError:
|
||||
raise ToolError(f"Invalid range format: {part}")
|
||||
else:
|
||||
try:
|
||||
indices.append(int(part))
|
||||
except ValueError:
|
||||
raise ToolError(f"Invalid index format: {part}")
|
||||
return indices
|
||||
|
||||
Reference in New Issue
Block a user