mirror of
https://github.com/gbdev/rgbds.git
synced 2026-05-08 10:59:36 +00:00
Use charmapEntry to simplify charmap_HasChar
This commit is contained in:
+7
-20
@@ -170,43 +170,25 @@ void charmap_Add(std::string const &mapping, std::vector<int32_t> &&value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Charmap &charmap = *currentCharmap;
|
Charmap &charmap = *currentCharmap;
|
||||||
size_t nodeIdx = 0;
|
|
||||||
|
|
||||||
|
size_t nodeIdx = 0;
|
||||||
for (char c : mapping) {
|
for (char c : mapping) {
|
||||||
nodeIdx = charmap.nextIndexOrAdd(nodeIdx, c);
|
nodeIdx = charmap.nextIndexOrAdd(nodeIdx, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
CharmapNode &node = charmap.nodes[nodeIdx];
|
CharmapNode &node = charmap.nodes[nodeIdx];
|
||||||
|
|
||||||
if (node.isTerminal()) {
|
if (node.isTerminal()) {
|
||||||
warning(WARNING_CHARMAP_REDEF, "Overriding charmap mapping");
|
warning(WARNING_CHARMAP_REDEF, "Overriding charmap mapping");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::swap(node.value, value);
|
std::swap(node.value, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool charmap_HasChar(std::string const &mapping) {
|
|
||||||
Charmap const &charmap = *currentCharmap;
|
|
||||||
size_t nodeIdx = 0;
|
|
||||||
|
|
||||||
for (char c : mapping) {
|
|
||||||
nodeIdx = charmap.nodes[nodeIdx].nextIndex(c);
|
|
||||||
|
|
||||||
if (!nodeIdx) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return charmap.nodes[nodeIdx].isTerminal();
|
|
||||||
}
|
|
||||||
|
|
||||||
static CharmapNode const *charmapEntry(std::string const &mapping) {
|
static CharmapNode const *charmapEntry(std::string const &mapping) {
|
||||||
Charmap const &charmap = *currentCharmap;
|
Charmap const &charmap = *currentCharmap;
|
||||||
size_t nodeIdx = 0;
|
|
||||||
|
|
||||||
|
size_t nodeIdx = 0;
|
||||||
for (char c : mapping) {
|
for (char c : mapping) {
|
||||||
nodeIdx = charmap.nodes[nodeIdx].nextIndex(c);
|
nodeIdx = charmap.nodes[nodeIdx].nextIndex(c);
|
||||||
|
|
||||||
if (!nodeIdx) {
|
if (!nodeIdx) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@@ -215,6 +197,11 @@ static CharmapNode const *charmapEntry(std::string const &mapping) {
|
|||||||
return &charmap.nodes[nodeIdx];
|
return &charmap.nodes[nodeIdx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool charmap_HasChar(std::string const &mapping) {
|
||||||
|
CharmapNode const *node = charmapEntry(mapping);
|
||||||
|
return node && node->isTerminal();
|
||||||
|
}
|
||||||
|
|
||||||
size_t charmap_CharSize(std::string const &mapping) {
|
size_t charmap_CharSize(std::string const &mapping) {
|
||||||
CharmapNode const *node = charmapEntry(mapping);
|
CharmapNode const *node = charmapEntry(mapping);
|
||||||
return node && node->isTerminal() ? node->value.size() : 0;
|
return node && node->isTerminal() ? node->value.size() : 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user