CommandMap: allow adding entries with control characters
This commit is contained in:
parent
928817f8e4
commit
2fb1cf38da
@ -5,13 +5,27 @@
|
|||||||
void CommandMap::add(const char * s, uint32_t id,
|
void CommandMap::add(const char * s, uint32_t id,
|
||||||
std::shared_ptr<CommandMap> next_map, bool following_char)
|
std::shared_ptr<CommandMap> next_map, bool following_char)
|
||||||
{
|
{
|
||||||
Node * node = &m_root_node;
|
|
||||||
size_t length = strlen(s);
|
size_t length = strlen(s);
|
||||||
|
if (length < 1u)
|
||||||
|
return;
|
||||||
|
std::vector<uint32_t> v(length);
|
||||||
|
for (size_t i = 0u; i < length; i++)
|
||||||
|
{
|
||||||
|
v[i] = s[i];
|
||||||
|
}
|
||||||
|
add(v, id, next_map, following_char);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommandMap::add(const std::vector<uint32_t> & s, uint32_t id,
|
||||||
|
std::shared_ptr<CommandMap> next_map, bool following_char)
|
||||||
|
{
|
||||||
|
Node * node = &m_root_node;
|
||||||
|
size_t length = s.size();
|
||||||
if (length < 1u)
|
if (length < 1u)
|
||||||
return;
|
return;
|
||||||
for (size_t i = 0u; i < length; i++)
|
for (size_t i = 0u; i < length; i++)
|
||||||
{
|
{
|
||||||
uint32_t c = (uint32_t)s[i];
|
const uint32_t c = s[i];
|
||||||
auto it = node->next_chars.find(c);
|
auto it = node->next_chars.find(c);
|
||||||
if (it != node->next_chars.end())
|
if (it != node->next_chars.end())
|
||||||
{
|
{
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <vector>
|
||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
|
|
||||||
class CommandMap
|
class CommandMap
|
||||||
@ -18,6 +19,8 @@ public:
|
|||||||
|
|
||||||
void add(const char * s, uint32_t id, std::shared_ptr<CommandMap> next_map,
|
void add(const char * s, uint32_t id, std::shared_ptr<CommandMap> next_map,
|
||||||
bool following_char);
|
bool following_char);
|
||||||
|
void add(const std::vector<uint32_t> & s, uint32_t id,
|
||||||
|
std::shared_ptr<CommandMap> next_map, bool following_char);
|
||||||
uint8_t lookup_command(const uint32_t * command_characters, size_t length,
|
uint8_t lookup_command(const uint32_t * command_characters, size_t length,
|
||||||
Command & command) const;
|
Command & command) const;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user