mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
hwlm_literal: coerce nocase lits to upper-case
This commit is contained in:
parent
da89f5ef6b
commit
07bb14a84a
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, Intel Corporation
|
* Copyright (c) 2015-2016, Intel Corporation
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
@ -34,13 +34,11 @@
|
|||||||
#include "util/compare.h" // for ourisalpha
|
#include "util/compare.h" // for ourisalpha
|
||||||
#include "util/ue2string.h" // for escapeString
|
#include "util/ue2string.h" // for escapeString
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include <boost/algorithm/cxx11/all_of.hpp>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace boost::algorithm;
|
|
||||||
|
|
||||||
namespace ue2 {
|
namespace ue2 {
|
||||||
|
|
||||||
@ -91,10 +89,17 @@ hwlmLiteral::hwlmLiteral(const std::string &s_in, bool nocase_in,
|
|||||||
assert(msk.size() <= HWLM_MASKLEN);
|
assert(msk.size() <= HWLM_MASKLEN);
|
||||||
assert(msk.size() == cmp.size());
|
assert(msk.size() == cmp.size());
|
||||||
|
|
||||||
DEBUG_PRINTF("literal '%s', msk=%s, cmp=%s\n",
|
// If we've been handled a nocase literal, all letter characters must be
|
||||||
escapeString(s).c_str(), dumpMask(msk).c_str(),
|
// 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());
|
dumpMask(cmp).c_str());
|
||||||
|
|
||||||
|
|
||||||
// Mask and compare vectors MUST be the same size.
|
// Mask and compare vectors MUST be the same size.
|
||||||
assert(msk.size() == cmp.size());
|
assert(msk.size() == cmp.size());
|
||||||
|
|
||||||
@ -102,7 +107,7 @@ hwlmLiteral::hwlmLiteral(const std::string &s_in, bool nocase_in,
|
|||||||
assert(maskIsConsistent(s, nocase, msk, cmp));
|
assert(maskIsConsistent(s, nocase, msk, cmp));
|
||||||
|
|
||||||
// In the name of good hygiene, zap msk/cmp if msk is all zeroes.
|
// In the name of good hygiene, zap msk/cmp if msk is all zeroes.
|
||||||
if (all_of_equal(msk.begin(), msk.end(), 0)) {
|
if (all_of(begin(msk), end(msk), [](u8 val) { return val == 0; })) {
|
||||||
msk.clear();
|
msk.clear();
|
||||||
cmp.clear();
|
cmp.clear();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, Intel Corporation
|
* Copyright (c) 2015-2016, Intel Corporation
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
@ -95,11 +95,6 @@ struct hwlmLiteral {
|
|||||||
*/
|
*/
|
||||||
std::vector<u8> cmp;
|
std::vector<u8> cmp;
|
||||||
|
|
||||||
/** \brief Simple constructor: no group information, no msk/cmp. */
|
|
||||||
hwlmLiteral(const std::string &s_in, bool nocase_in, u32 id_in)
|
|
||||||
: s(s_in), id(id_in), nocase(nocase_in), noruns(false),
|
|
||||||
groups(HWLM_ALL_GROUPS), msk(0), cmp(0) {}
|
|
||||||
|
|
||||||
/** \brief Complete constructor, takes group information and msk/cmp.
|
/** \brief Complete constructor, takes group information and msk/cmp.
|
||||||
*
|
*
|
||||||
* This constructor takes a msk/cmp pair. Both must be vectors of length <=
|
* This constructor takes a msk/cmp pair. Both must be vectors of length <=
|
||||||
@ -107,6 +102,10 @@ struct hwlmLiteral {
|
|||||||
hwlmLiteral(const std::string &s_in, bool nocase_in, bool noruns_in,
|
hwlmLiteral(const std::string &s_in, bool nocase_in, bool noruns_in,
|
||||||
u32 id_in, hwlm_group_t groups_in,
|
u32 id_in, hwlm_group_t groups_in,
|
||||||
const std::vector<u8> &msk_in, const std::vector<u8> &cmp_in);
|
const std::vector<u8> &msk_in, const std::vector<u8> &cmp_in);
|
||||||
|
|
||||||
|
/** \brief Simple constructor: no group information, no msk/cmp. */
|
||||||
|
hwlmLiteral(const std::string &s_in, bool nocase_in, u32 id_in)
|
||||||
|
: hwlmLiteral(s_in, nocase_in, false, id_in, HWLM_ALL_GROUPS, {}, {}) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user