示例#1
0
/** \brief Complete constructor, takes group information and msk/cmp.
 *
 * This constructor takes a msk/cmp pair. Both must be vectors of length <=
 * \ref HWLM_MASKLEN. */
hwlmLiteral::hwlmLiteral(const std::string &s_in, bool nocase_in,
                         bool noruns_in, u32 id_in, hwlm_group_t groups_in,
                         const vector<u8> &msk_in, const vector<u8> &cmp_in)
    : s(s_in), id(id_in), nocase(nocase_in), noruns(noruns_in),
      groups(groups_in), msk(msk_in), cmp(cmp_in) {
    assert(msk.size() <= HWLM_MASKLEN);
    assert(msk.size() == cmp.size());

    // If we've been handled a nocase literal, all letter characters must be
    // upper-case.
    if (nocase) {
        upperString(s);
    }

    DEBUG_PRINTF("literal '%s'%s, msk=%s, cmp=%s\n", escapeString(s).c_str(),
                 nocase ? " (nocase)" : "", dumpMask(msk).c_str(),
                 dumpMask(cmp).c_str());


    // Mask and compare vectors MUST be the same size.
    assert(msk.size() == cmp.size());

    // We must have been passed a msk/cmp that can be applied to s.
    assert(maskIsConsistent(s, nocase, msk, cmp));

    // In the name of good hygiene, zap msk/cmp if msk is all zeroes.
    if (all_of(begin(msk), end(msk), [](u8 val) {
    return val == 0;
})) {
        msk.clear();
        cmp.clear();
    }
}
示例#2
0
/** \brief Complete constructor, takes group information and msk/cmp.
 *
 * This constructor takes a msk/cmp pair. Both must be vectors of length <=
 * \ref HWLM_MASKLEN. */
hwlmLiteral::hwlmLiteral(const std::string &s_in, bool nocase_in,
                         bool noruns_in, u32 id_in, hwlm_group_t groups_in,
                         const vector<u8> &msk_in, const vector<u8> &cmp_in)
    : s(s_in), id(id_in), nocase(nocase_in), noruns(noruns_in),
      groups(groups_in), msk(msk_in), cmp(cmp_in) {
    assert(msk.size() <= HWLM_MASKLEN);
    assert(msk.size() == cmp.size());

    DEBUG_PRINTF("literal '%s', msk=%s, cmp=%s\n",
                 escapeString(s).c_str(), dumpMask(msk).c_str(),
                 dumpMask(cmp).c_str());

    // Mask and compare vectors MUST be the same size.
    assert(msk.size() == cmp.size());

    // We must have been passed a msk/cmp that can be applied to s.
    assert(maskIsConsistent(s, nocase, msk, cmp));

    // In the name of good hygiene, zap msk/cmp if msk is all zeroes.
    if (all_of_equal(msk.begin(), msk.end(), 0)) {
        msk.clear();
        cmp.clear();
    }
}