|
@@ -9,8 +9,13 @@
|
|
|
|
|
|
void CharMan::validate(void) {
|
|
|
bool valid = true;
|
|
|
+ ZF_LOGE("validate: text_offsets %d", (int)text_offsets.size());
|
|
|
+ ZF_LOGE("validate work size %d, buffer size %d, text size %d",
|
|
|
+ (int)work.size(), (int)buffer.size(), (int)text.size());
|
|
|
+
|
|
|
for (int x = 0; x < text_offsets.size(); ++x) {
|
|
|
int offset = text_offsets[x];
|
|
|
+ ZF_LOGE("%d : %d", x, offset);
|
|
|
|
|
|
if (offset >= 0) {
|
|
|
if (text[x] != work[offset]) {
|
|
@@ -69,10 +74,12 @@ void CharMan::regular_expressions(void) {
|
|
|
for (auto it =
|
|
|
std::sregex_iterator(this->text.begin(), this->text.end(), words);
|
|
|
it != std::sregex_iterator(); ++it) {
|
|
|
- pos_len.push_back(std::make_pair(it->position(), it->length()));
|
|
|
+
|
|
|
int pos = it->position(), len = it->length();
|
|
|
ZF_LOGD("pos %d len %d (%s)", pos, len,
|
|
|
this->text.substr(pos, len).c_str());
|
|
|
+ if (len > 4)
|
|
|
+ pos_len.push_back(std::make_pair(it->position(), it->length()));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -89,9 +96,18 @@ void CharMan::set(int pos, char ch) {
|
|
|
|
|
|
void CharMan::insert(int pos, std::string str) {
|
|
|
int len = str.size();
|
|
|
- int idx = this->text_offsets[pos];
|
|
|
- ZF_LOGE("insert( POS %d, LEN %d, IDX %d, %s)", pos, len, idx, str.c_str());
|
|
|
- diagnostics();
|
|
|
+ // What happens if pos is at the end of the buffer?
|
|
|
+ int idx;
|
|
|
+ if (pos == text_offsets.size()) {
|
|
|
+ // Ok, this is at the very end of the buffer, which is beyond what the
|
|
|
+ // vector is holding.
|
|
|
+ idx = this->text_offsets[pos - 1] + 1;
|
|
|
+ ZF_LOGE("Use %d for idx", idx);
|
|
|
+ } else
|
|
|
+ idx = this->text_offsets[pos];
|
|
|
+
|
|
|
+ // ZF_LOGE("insert( POS %d, LEN %d, IDX %d, %s)", pos, len, idx, str.c_str());
|
|
|
+ // diagnostics();
|
|
|
std::string blank(len, ' ');
|
|
|
// Don't insert into text.
|
|
|
// Insert blank into work.
|
|
@@ -108,8 +124,8 @@ void CharMan::insert(int pos, std::string str) {
|
|
|
*it += len;
|
|
|
}
|
|
|
}
|
|
|
- ZF_LOGE("Indexes updated... check your work");
|
|
|
- diagnostics();
|
|
|
+ // ZF_LOGE("Indexes updated... check your work");
|
|
|
+ // diagnostics();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -214,8 +230,10 @@ int CharMan::word_tangler(std::pair<int, int> pos_len) {
|
|
|
buffer << "^S" << r;
|
|
|
tangle = buffer.str();
|
|
|
std::string reset = "^R0^S0";
|
|
|
+ ZF_LOGD("insert reset %s", reset.c_str());
|
|
|
this->insert(p + len, reset);
|
|
|
this->validate();
|
|
|
+ ZF_LOGD("insert tangle %s", tangle.c_str());
|
|
|
this->insert(p, tangle);
|
|
|
this->validate();
|
|
|
return 1;
|
|
@@ -246,7 +264,7 @@ this->text_offsets = text_offsets;
|
|
|
if (pos_len.size() > 0) {
|
|
|
for (int i = 0; i < pos_len.size(); ++i) {
|
|
|
int active = 0;
|
|
|
- if (random_activate(level * 2)) { // 8
|
|
|
+ if (random_activate((level + 1) / 2)) { // 8
|
|
|
int c = word_mangler(pos_len[i]);
|
|
|
if (c) {
|
|
|
active = 1;
|
|
@@ -255,14 +273,14 @@ this->text_offsets = text_offsets;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (random_activate(level)) { // 4
|
|
|
+ if (random_activate((level + 1) / 2)) { // 4
|
|
|
if (word_wrangler(pos_len[i])) {
|
|
|
this->mangle_count++;
|
|
|
active = 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!active && random_activate(level)) {
|
|
|
+ if (!active && random_activate((level + 1) / 2)) {
|
|
|
if (word_tangler(pos_len[i])) {
|
|
|
this->need_render = 1;
|
|
|
}
|