| 1939 | } |
| 1940 | |
| 1941 | void InteractiveConsole::Execute(const std::string& s) |
| 1942 | { |
| 1943 | arguments_t argv; |
| 1944 | argv.reserve(8); |
| 1945 | |
| 1946 | const utf8* start = s.c_str(); |
| 1947 | const utf8* end; |
| 1948 | bool inQuotes = false; |
| 1949 | do |
| 1950 | { |
| 1951 | while (*start == ' ') |
| 1952 | start++; |
| 1953 | |
| 1954 | if (*start == '"') |
| 1955 | { |
| 1956 | inQuotes = true; |
| 1957 | start++; |
| 1958 | } |
| 1959 | else |
| 1960 | { |
| 1961 | inQuotes = false; |
| 1962 | } |
| 1963 | |
| 1964 | end = start; |
| 1965 | while (*end != 0) |
| 1966 | { |
| 1967 | if (*end == ' ' && !inQuotes) |
| 1968 | break; |
| 1969 | if (*end == '"' && inQuotes) |
| 1970 | break; |
| 1971 | end++; |
| 1972 | } |
| 1973 | size_t length = end - start; |
| 1974 | |
| 1975 | if (length > 0) |
| 1976 | { |
| 1977 | argv.emplace_back(start, length); |
| 1978 | } |
| 1979 | |
| 1980 | start = end; |
| 1981 | } while (*end != 0); |
| 1982 | |
| 1983 | if (argv.empty()) |
| 1984 | return; |
| 1985 | |
| 1986 | bool validCommand = false; |
| 1987 | for (const auto& c : console_command_table) |
| 1988 | { |
| 1989 | if (argv[0] == c.command) |
| 1990 | { |
| 1991 | argv.erase(argv.begin()); |
| 1992 | c.func(*this, argv); |
| 1993 | validCommand = true; |
| 1994 | break; |
| 1995 | } |
| 1996 | } |
| 1997 | |
| 1998 | if (!validCommand) |
no test coverage detected