| 218 | } |
| 219 | |
| 220 | function parsePageRange(spec: string, total: number): Set<number> { |
| 221 | const wanted = new Set<number>(); |
| 222 | for (const part of spec.split(/[,\s]+/).filter(Boolean)) { |
| 223 | const dash = part.indexOf('-'); |
| 224 | if (dash !== -1) { |
| 225 | const a = parseInt(part.slice(0, dash), 10); |
| 226 | const b = parseInt(part.slice(dash + 1), 10); |
| 227 | if (!isNaN(a) && !isNaN(b)) { |
| 228 | for (let i = a; i <= b && i <= total; i++) wanted.add(i); |
| 229 | } |
| 230 | } else { |
| 231 | const n = parseInt(part, 10); |
| 232 | if (!isNaN(n) && n >= 1 && n <= total) wanted.add(n); |
| 233 | } |
| 234 | } |
| 235 | return wanted; |
| 236 | } |
| 237 | |
| 238 | export class PdfReadTool extends Tool<z.infer<typeof PdfReadArgs>> { |
| 239 | name = 'pdf_read'; |