コード例 #1
0
Qt::MatchFlags SearchOptions::getMatchFlags() const
{

    // *** match flags ***
    // MatchExactly = 0, Performs QVariant-based matching.
    // MatchContains = 1,
    // MatchStartsWith = 2,
    // MatchEndsWith = 3,
    // MatchRegExp = 4,
    // MatchWildcard = 5,
    // MatchFixedString = 8, Performs string-based matching.
    // MatchCaseSensitive = 16,
    // MatchWrap = 32,
    // MatchRecursive = 64 Searches the entire hierarchy, but I do not have heirarchical data.

  Qt::MatchFlags flags = Qt::MatchExactly;
  if (isMatchEntireString()) flags |= Qt::MatchFixedString;
  if (isContains()) flags |= Qt::MatchContains;
  if (isStartsWith()) flags |= Qt::MatchStartsWith;
  if (isEndsWith()) flags |= Qt::MatchEndsWith;
  //if (isMatchAsString()) flags |= Qt::MatchFixedString;
  if (isRegularExpression()) flags |= Qt::MatchRegExp;
  if (isWildCard()) flags |= Qt::MatchWildcard;
  if (isCaseSensitive()) flags |= Qt::MatchCaseSensitive;
  if (isWrap()) flags |= Qt::MatchWrap;
  return flags;
}
コード例 #2
0
QString SearchOptions::serializeSettings() const
{
  QStringList list;
  if (isMatchEntireString()) list << "MatchEntireString";
  if (isContains()) list << "Contains";
  if (isStartsWith()) list << "StartsWith";
  if (isEndsWith()) list << "EndsWith";

  if (isMatchAsString()) list << "AsString";
  if (isRegularExpression()) list << "RegExp";
  if (isWildCard()) list << "Wildcard";

  list << (isCaseSensitive() ? "CaseSensitive" : "CaseInSensitive");
  list << (isWrap() ? "Wrap" : "NoWrap");
  list << (isBackwards() ? "Backward" : "Forward");
  list << (isAllColumns() ? "AllColumns" : "OneColumn");
  if (isReplace()) list << "Replace";
  if (isReplaceAll()) list << "ReplaceAll";
  return list.join(",");
}
コード例 #3
0
ファイル: scalpel.cpp プロジェクト: Steven-Wright/scalpel
int extractSearchSpecData(struct scalpelState *state, 
                          struct SearchSpecLine *s,
                          char **tokenarray) {

    int err = 0;

    // process one line from config file:
    //     token[0] = suffix
    //     token[1] = case sensitive?
    //     token[2] = maximum carve size
    //     token[3] = begintag
    //     token[4] = endtag
    //     token[5] = search type (optional)

    s->suffix = (char *) malloc(MAX_SUFFIX_LENGTH * sizeof(char));
    checkMemoryAllocation(state, s->suffix, __LINE__, __FILE__, "s->suffix");
    s->begin = (char *) malloc(MAX_STRING_LENGTH * sizeof(char));
    checkMemoryAllocation(state, s->begin, __LINE__, __FILE__, "s->begin");
    s->end = (char *) malloc(MAX_STRING_LENGTH * sizeof(char));
    checkMemoryAllocation(state, s->end, __LINE__, __FILE__, "s->end");
    s->begintext = (char *) malloc(MAX_STRING_LENGTH * sizeof(char));
    checkMemoryAllocation(state, s->begintext, __LINE__, __FILE__,
        "s->begintext");
    s->endtext = (char *) malloc(MAX_STRING_LENGTH * sizeof(char));
    checkMemoryAllocation(state, s->endtext, __LINE__, __FILE__, "s->endtext");

    if (!strncasecmp(tokenarray[0], SCALPEL_NOEXTENSION_SUFFIX,
        strlen(SCALPEL_NOEXTENSION_SUFFIX))) {
            s->suffix[0] = SCALPEL_NOEXTENSION;
            s->suffix[1] = 0;
    } else {
        memcpy(s->suffix, tokenarray[0], MAX_SUFFIX_LENGTH);
    }

    // case sensitivity check
    s->casesensitive = (!strncasecmp(tokenarray[1], "y", 1)
        || !strncasecmp(tokenarray[1], "yes", 3));

    //#ifdef _WIN32
    //    s->length = _atoi64(tokenarray[2]);
    //#else
    //  s->length = atoull(tokenarray[2]);
    //#endif

    char split[MAX_STRING_LENGTH];
    char *maxcarvelength;

    strcpy(split, tokenarray[2]);
    maxcarvelength = strchr(split, ':');
    if (!maxcarvelength) {
        s->minlength = 0;
        s->length = strtoull(split, 0, 10);
    } else {
        *maxcarvelength = 0;
        maxcarvelength++;
        s->minlength = strtoull(split, 0, 10);
        s->length = strtoull(maxcarvelength, 0, 10);
    }

    // determine search type for this needle
    s->searchtype = SEARCHTYPE_FORWARD;
    if (!strncasecmp(tokenarray[5], "REVERSE", strlen("REVERSE"))) {
        s->searchtype = SEARCHTYPE_REVERSE;
    } else if (!strncasecmp(tokenarray[5], "NEXT", strlen("NEXT"))) {
        s->searchtype = SEARCHTYPE_FORWARD_NEXT;
    }
    // FORWARD is the default, but OK if the user defines it explicitly
    else if (!strncasecmp(tokenarray[5], "FORWARD", strlen("FORWARD"))) {
        s->searchtype = SEARCHTYPE_FORWARD;
    }

    // regular expressions must be handled separately

    if (isRegularExpression(tokenarray[3])) {

#ifdef GPU_THREADING
        // GPU execution does not support regex needles.
        std::stringstream ss;
        ss << "ERROR: GPU search for regex headers is not supported!\n";
        ss << "Please modify the config file for non-regex headers only.\n";
        std::string msg = ss.str();
        fprintf(stderr, msg.c_str());
        throw std::runtime_error(msg);
#endif

        // copy RE, zap leading/training '/' and prepare for regular expression compilation
        s->beginisRE = 1;
        strcpy(s->begin, tokenarray[3]);
        strcpy(s->begintext, tokenarray[3]);
        s->beginlength = strlen(tokenarray[3]);
        s->begin[s->beginlength] = 0;
        // compile regular expression
        err = regncomp(&(s->beginstate.re), s->begin + 1, s->beginlength - 2,
            REG_EXTENDED | (REG_ICASE * (!s->casesensitive)));
        if (err) {
            return SCALPEL_ERROR_BAD_HEADER_REGEX;
        }
    } else {
        // non-regular expression header
        s->beginisRE = 0;
        strcpy(s->begintext, tokenarray[3]);
        s->beginlength = translate(tokenarray[3]);
        memcpy(s->begin, tokenarray[3], s->beginlength);
        init_bm_table(s->begin, s->beginstate.bm_table, s->beginlength,
            s->casesensitive);
    }

    if (isRegularExpression(tokenarray[4])) {

#ifdef GPU_THREADING
        // GPU execution does not support regex needles.
        std::stringstream ss;
        ss << "ERROR: GPU search for regex footers is not supported!\n";
        ss << "Please modify the config file for non-regex footers only.\n";
        std::string msg = ss.str();
        fprintf(stderr, msg.c_str());
        throw std::runtime_error(msg);
#endif  

        // copy RE, zap leading/training '/' and prepare for for regular expression compilation
        s->endisRE = 1;
        strcpy(s->end, tokenarray[4]);
        strcpy(s->endtext, tokenarray[4]);
        s->endlength = strlen(tokenarray[4]);
        s->end[s->endlength] = 0;
        // compile regular expression
        err = regncomp(&(s->endstate.re), s->end + 1, s->endlength - 2,
            REG_EXTENDED | (REG_ICASE * (!s->casesensitive)));

        if (err) {
            return SCALPEL_ERROR_BAD_FOOTER_REGEX;
        }
    } else {
        s->endisRE = 0;
        strcpy(s->endtext, tokenarray[4]);
        s->endlength = translate(tokenarray[4]);
        memcpy(s->end, tokenarray[4], s->endlength);
        init_bm_table(s->end, s->endstate.bm_table, s->endlength,
            s->casesensitive);
    }

    return SCALPEL_OK;
}