RepList::~RepList() { for (auto& i : dat) { delete i;
}
}
int RepList::find(constchar* word) { int p1 = 0; int p2 = dat.size() - 1; int ret = -1; while (p1 <= p2) { int m = ((unsigned)p1 + (unsigned)p2) >> 1; int c = strncmp(word, dat[m]->pattern.c_str(), dat[m]->pattern.size()); if (c < 0)
p2 = m - 1; elseif (c > 0)
p1 = m + 1; else { // scan in the right half for a longer match
ret = m;
p1 = m + 1;
}
} return ret;
}
std::string RepList::replace(const size_t wordlen, int ind, bool atstart) { int type = atstart ? 1 : 0; if (wordlen == dat[ind]->pattern.size())
type = atstart ? 3 : 2; while (type && dat[ind]->outstrings[type].empty())
type = (type == 2 && !atstart) ? 0 : type - 1; return dat[ind]->outstrings[type];
}
int RepList::add(const std::string& in_pat1, const std::string& pat2) { if (in_pat1.empty() || pat2.empty()) { return1;
} // analyse word context int type = 0;
std::string pat1(in_pat1); if (pat1[0] == '_') {
pat1.erase(0, 1);
type = 1;
} if (!pat1.empty() && pat1[pat1.size() - 1] == '_') {
type = type + 2;
pat1.erase(pat1.size() - 1);
}
mystrrep(pat1, "_", " ");
// find existing entry int m = find(pat1.c_str()); if (m >= 0 && dat[m]->pattern == pat1) { // since already used
dat[m]->outstrings[type] = pat2;
mystrrep(dat[m]->outstrings[type], "_", " "); return0;
}
// make a new entry if none exists
replentry* r = new replentry;
r->pattern = std::move(pat1);
r->outstrings[type] = pat2;
mystrrep(r->outstrings[type], "_", " ");
dat.push_back(r); // sort to the right place in the list
size_t i; for (i = dat.size() - 1; i > 0; --i) { if (strcmp(r->pattern.c_str(), dat[i - 1]->pattern.c_str()) < 0) {
dat[i] = dat[i - 1];
} else break;
}
dat[i] = r; return0;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.