feat: added wildcard support for patterns
This commit is contained in:
parent
03835248c4
commit
5fe4ba4cdd
2 changed files with 12 additions and 7 deletions
|
|
@ -40,7 +40,9 @@ bool Sentence::check_match_at(Vector2i at, Ref<Sentence> pattern) {
|
|||
}
|
||||
for (Vector2i itr{ 0, 0 }; itr.y < pattern_size.y; ++itr.y) {
|
||||
for (; itr.x < pattern_size.x; ++itr.x) {
|
||||
if (get_at(at + itr) != pattern->get_at(itr)) {
|
||||
Symbol a{ get_at(at + itr) };
|
||||
Symbol b{ pattern->get_at(itr) };
|
||||
if (a != b && (b != U'*' || a == U'u')) {
|
||||
return false; // difference found
|
||||
}
|
||||
}
|
||||
|
|
@ -52,7 +54,10 @@ bool Sentence::check_match_at(Vector2i at, Ref<Sentence> pattern) {
|
|||
void Sentence::write_subsentence(Vector2i at, Ref<Sentence> sentence) {
|
||||
for (Vector2i pos{ 0, 0 }; pos.y < sentence->get_size().y; ++pos.y) {
|
||||
for (; pos.x < sentence->get_size().x; ++pos.x) {
|
||||
set_at(at + pos, sentence->get_at(pos));
|
||||
Symbol write{ sentence->get_at(pos) };
|
||||
if (write != U'*') { // wildcards don't write
|
||||
set_at(at + pos, write);
|
||||
}
|
||||
}
|
||||
pos.x = 0;
|
||||
}
|
||||
|
|
@ -62,7 +67,7 @@ void Sentence::set_symbols_string(String value) {
|
|||
int size{ this->size.x * this->size.y };
|
||||
int writer{ 0 };
|
||||
for (int reader{ 0 }; writer < size; ++reader) {
|
||||
char32_t c{ reader < value.length() ? value[reader] : U'B' };
|
||||
char32_t c{ reader < value.length() ? value.get(reader) : U'u' };
|
||||
if (c != U'\n') {
|
||||
this->symbols.set(writer, c);
|
||||
++writer;
|
||||
|
|
|
|||
|
|
@ -39,23 +39,23 @@ symbols_string = "ppp"
|
|||
size = Vector2i(5, 3)
|
||||
symbols_string = "uuuuu
|
||||
uuuuu
|
||||
xpxpx"
|
||||
*pxp*"
|
||||
|
||||
[sub_resource type="Sentence" id="Sentence_yc5ro"]
|
||||
size = Vector2i(5, 3)
|
||||
symbols_string = "uuuuu
|
||||
upxpu
|
||||
xpupx"
|
||||
*pup*"
|
||||
|
||||
[sub_resource type="Sentence" id="Sentence_7f72c"]
|
||||
size = Vector2i(5, 3)
|
||||
symbols_string = "xpxpx
|
||||
symbols_string = "*pxp*
|
||||
uuuuu
|
||||
uuuuu"
|
||||
|
||||
[sub_resource type="Sentence" id="Sentence_pbld3"]
|
||||
size = Vector2i(5, 3)
|
||||
symbols_string = "xpupx
|
||||
symbols_string = "*pup*
|
||||
upxpu
|
||||
uuuuu"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue