123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #include <regex>
- #include <string>
- #include <vector>
- #include "charman.h"
- #include "zf_log.h"
- void CharMan::validate(void) {
- bool valid = true;
- for (int x = 0; x < text_offsets.size(); ++x) {
- int offset = text_offsets[x];
- if (offset >= 0) {
- if (text[x] != buffer[offset]) {
- ZF_LOGE("validate: %d off %d [%c != %c]", x, offset, text[x],
- buffer[offset]);
- valid = false;
- }
- if (text[x] != work[offset]) {
- ZF_LOGE("validate: %d off %d [%c != %c]", x, offset, text[x],
- work[offset]);
- valid = false;
- }
- }
- }
- if (!valid) {
- ZF_LOGE("* NOT VALID* Somethings hosed.");
- }
- }
- void CharMan::regular_expressions(void) {
- std::regex words("[a-zA-Z]+( [a-zA-Z]+)+");
- // I need position and length.
- 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()));
- ZF_LOGD("pos %d len %d", (int)it->position(), (int)it->length());
- }
- }
- CharMan::CharMan(std::string &buffer, std::string &work, std::string &text,
- std::vector<int> &text_offsets)
- : buffer(buffer), work(work), text(text), text_offsets(text_offsets) {
- /*
- this->buffer = buffer;
- this->work = work;
- this->text = text;
- this->text_offsets = text_offsets;
- */
- validate();
- regular_expressions();
- ZF_LOGD("Found %d word groups", pos_len.size());
- };
- CharMan::~CharMan() { validate(); }
|