r"""Split a leading file path token from trailing free-form text. Supports quoted paths and backslash-escaped spaces so callers can accept inputs like: /tmp/pic.png describe this ~/storage/shared/My\ Photos/cat.png what is this? "/storage/emulated/0/DCIM/Camera/cat 1.png"
(raw: str)
| 2686 | |
| 2687 | |
| 2688 | def _split_path_input(raw: str) -> tuple[str, str]: |
| 2689 | r"""Split a leading file path token from trailing free-form text. |
| 2690 | |
| 2691 | Supports quoted paths and backslash-escaped spaces so callers can accept |
| 2692 | inputs like: |
| 2693 | /tmp/pic.png describe this |
| 2694 | ~/storage/shared/My\ Photos/cat.png what is this? |
| 2695 | "/storage/emulated/0/DCIM/Camera/cat 1.png" summarize |
| 2696 | """ |
| 2697 | raw = str(raw or "").strip() |
| 2698 | if not raw: |
| 2699 | return "", "" |
| 2700 | |
| 2701 | if raw[0] in {'"', "'"}: |
| 2702 | quote = raw[0] |
| 2703 | pos = 1 |
| 2704 | while pos < len(raw): |
| 2705 | ch = raw[pos] |
| 2706 | if ch == '\\' and pos + 1 < len(raw): |
| 2707 | pos += 2 |
| 2708 | continue |
| 2709 | if ch == quote: |
| 2710 | token = raw[1:pos] |
| 2711 | remainder = raw[pos + 1 :].strip() |
| 2712 | return token, remainder |
| 2713 | pos += 1 |
| 2714 | return raw[1:], "" |
| 2715 | |
| 2716 | pos = 0 |
| 2717 | while pos < len(raw): |
| 2718 | ch = raw[pos] |
| 2719 | if ch == '\\' and pos + 1 < len(raw) and raw[pos + 1] == ' ': |
| 2720 | pos += 2 |
| 2721 | elif ch == ' ': |
| 2722 | break |
| 2723 | else: |
| 2724 | pos += 1 |
| 2725 | |
| 2726 | token = raw[:pos].replace('\\ ', ' ') |
| 2727 | remainder = raw[pos:].strip() |
| 2728 | return token, remainder |
| 2729 | |
| 2730 | |
| 2731 | def _resolve_attachment_path(raw_path: str) -> Path | None: |
no test coverage detected