(args)
| 590 | |
| 591 | |
| 592 | def str_to_args_windows(args): |
| 593 | # See https://docs.microsoft.com/en-us/cpp/c-language/parsing-c-command-line-arguments. |
| 594 | # |
| 595 | # Implemetation ported from DebugPlugin.parseArgumentsWindows: |
| 596 | # https://github.com/eclipse/eclipse.platform.debug/blob/master/org.eclipse.debug.core/core/org/eclipse/debug/core/DebugPlugin.java |
| 597 | |
| 598 | result = [] |
| 599 | |
| 600 | DEFAULT = 0 |
| 601 | ARG = 1 |
| 602 | IN_DOUBLE_QUOTE = 2 |
| 603 | |
| 604 | state = DEFAULT |
| 605 | backslashes = 0 |
| 606 | buf = "" |
| 607 | |
| 608 | args_len = len(args) |
| 609 | for i in range(args_len): |
| 610 | ch = args[i] |
| 611 | if ch == "\\": |
| 612 | backslashes += 1 |
| 613 | continue |
| 614 | elif backslashes != 0: |
| 615 | if ch == '"': |
| 616 | while backslashes >= 2: |
| 617 | backslashes -= 2 |
| 618 | buf += "\\" |
| 619 | if backslashes == 1: |
| 620 | if state == DEFAULT: |
| 621 | state = ARG |
| 622 | |
| 623 | buf += '"' |
| 624 | backslashes = 0 |
| 625 | continue |
| 626 | # else fall through to switch |
| 627 | else: |
| 628 | # false alarm, treat passed backslashes literally... |
| 629 | if state == DEFAULT: |
| 630 | state = ARG |
| 631 | |
| 632 | while backslashes > 0: |
| 633 | backslashes -= 1 |
| 634 | buf += "\\" |
| 635 | # fall through to switch |
| 636 | if ch in (" ", "\t"): |
| 637 | if state == DEFAULT: |
| 638 | # skip |
| 639 | continue |
| 640 | elif state == ARG: |
| 641 | state = DEFAULT |
| 642 | result.append(buf) |
| 643 | buf = "" |
| 644 | continue |
| 645 | |
| 646 | if state in (DEFAULT, ARG): |
| 647 | if ch == '"': |
| 648 | state = IN_DOUBLE_QUOTE |
| 649 | else: |
no test coverage detected