aboutsummaryrefslogtreecommitdiff
path: root/src/CommandParser.cpp
blob: ccb84bcc1a6c1a93d90c2ead28d73753503c1831 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <QtCore/qnamespace.h>
#include <QtCore>

#include "CommandParser.hpp"

CommandParser::CommandParser() {}

Cmd CommandParser::parse(QString input) {
  auto parts = input.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);

  if (parts.isEmpty())
    return Cmd();

  auto cmd = toCommandType(parts.first());
  parts.removeFirst();
  return Cmd(cmd, parts);
}

CommandType CommandParser::toCommandType(QString cmd) {
  if (cmd == "lua")
    return LuaEval;
  if (cmd == "open")
    return Open;
  if (cmd == "tabopen")
    return TabOpen;
  if (cmd == "bn" || cmd == "bnext")
    return TabNext;
  if (cmd == "bp" || cmd == "bprevious")
    return TabPrev;

  return Noop;
}