1. Python / Говнокод #25639

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    def parse_cmd(cmd):
        output = []
        state = 0
        current_arg = ''
        prev_c = ''
        for c in cmd:
            if c == ' ':
                if state == 0:
                    if len(current_arg) > 0:
                        output += [current_arg]
                    current_arg = ''
                elif state == 1:
                    current_arg += c
            elif c == '"' and prev_c != '\\':
                if len(current_arg) > 0 or state == 1:
                    output += [current_arg]
                current_arg = ''
                state = int(not state)
            else:
                current_arg += c
            prev_c = c
        if len(current_arg) > 0:
            output += [current_arg]
        return output

    Какой FSM )))

    Запостил: gost, 24 Мая 2019

    Комментарии (35) RSS

    Добавить комментарий