예제 #1
0
static bool FilterMatch( const char *_filename, const char *_filter )
{
    while (*_filename && tolower(*_filename) == tolower(*_filter)) {
        _filename++;
        _filter++;
    }

    if (tolower(*_filename) == tolower(*_filter))
        return true;

    switch(*_filter++) {
        case '*':
            while (*_filename) {
                _filename++;
                if (FilterMatch(_filename, _filter))
                    return true;
            }
            return false;
        
        case '?':
            if (!*_filename)
                return false;
            _filename++;
            return FilterMatch(_filename, _filter);
            
        default:
            return false;
    }
}
예제 #2
0
bool SmartsMatcher::getMatches(const ROMol &mol,
                               std::vector<FilterMatch> &matchVect) const {
    PRECONDITION(d_pattern.get(), "bad on pattern");

    bool onPatExists = false;
    std::vector<RDKit::MatchVectType> matches;

    if (d_min_count == 1 && d_max_count == UINT_MAX) {
        RDKit::MatchVectType match;
        onPatExists = RDKit::SubstructMatch(mol, *d_pattern.get(), match);
        if (onPatExists) matchVect.push_back(FilterMatch(copy(), match));
    } else {  // need to count
        const bool uniquify = true;
        unsigned int count =
            RDKit::SubstructMatch(mol, *d_pattern.get(), matches, uniquify);
        onPatExists = (count >= d_min_count &&
                       (d_max_count == UINT_MAX || count <= d_max_count));
        if (onPatExists) {
            boost::shared_ptr<FilterMatcherBase> clone = copy();
            for (size_t i = 0; i < matches.size(); ++i) {
                matchVect.push_back(FilterMatch(clone, matches[i]));
            }
        }
    }
    return onPatExists;
}
예제 #3
0
void Styler_SearchHL::DoSearch(unsigned int start, unsigned int end, bool from_last) {
	wxASSERT(0 <= start && start < m_doc.GetLength());
	wxASSERT(start < end && end <= m_doc.GetLength());

	bool matchcase = m_options & FIND_MATCHCASE;

	vector<interval>::iterator next_match = m_matches.begin();
	if (from_last) {
		// Start search from last match
		if (!m_matches.empty())	start = m_matches.back().end;
	}
	else {
		// Find the match before start pos (if there is any)
		for (; next_match != m_matches.end(); ++next_match) {
			if (next_match->end > start) break;
		}
	}

	//wxLogDebug("  DoSearch %u %u %d", start, end, from_last);

	// Search from start until we hit a previous match (or end)
	search_result result = {-1, 0, start};
	while(result.end < end) {
		bool skip = false;
		cxLOCKDOC_READ(m_doc)
			if (m_options & FIND_USE_REGEX) result = doc.RegExFind(m_text, result.end, matchcase, NULL, end);
			else result = doc.Find(m_text, result.end, matchcase, end);
			
			skip = !FilterMatch(result, doc);
		cxENDLOCK

		if (result.error_code < 0 || result.start >= end) break;

		if(!skip) {
			// Add new match to list
			const interval iv(result.start, result.end);
			if (from_last) m_matches.push_back(iv);
			else {
				// Check if we have hit a previous match
				while (next_match != m_matches.end() && result.end > next_match->start) {
					// if not equivalent, replace and continue
					if (next_match->start == result.start && next_match->end == result.end)	break;
					next_match = m_matches.erase(next_match);
				}
	
				next_match = m_matches.insert(next_match, iv);
				++next_match;
			}
		}

		// Avoid never ending loop if zero-length match
		if (result.start == result.end) ++result.end;
	}
}
예제 #4
0
// Finds all the filenames in the specified directory that match the specified
// filter. Directory should be like "data/textures" or "data/textures/".
// Filter can be NULL or "" or "*.bmp" or "map_*" or "map_*.txt"
// Set FullFilename to true if you want results like "data/textures/blah.bmp" 
// or false for "blah.bmp"
LList <char *> *ListDirectory( const char *_dir, const char *_filter, bool _fullFilename )
{
    if(_filter == NULL || _filter[0] == '\0')
    {
        _filter = "*";
    }

    if(_dir == NULL || _dir[0] == '\0')
    {
        _dir = "";
    }

    // Create a DArray for our results
    LList <char *> *result = new LList<char *>();

    // Now add on all files found locally
#ifdef WIN32
    char searchstring [256];
    AppAssert(strlen(_dir) + strlen(_filter) < sizeof(searchstring) - 1);
    sprintf( searchstring, "%s%s", _dir, _filter );

    _finddata_t thisfile;
    long fileindex = _findfirst( searchstring, &thisfile );

    int exitmeplease = 0;

    while( fileindex != -1 && !exitmeplease ) 
    {
        if( strcmp( thisfile.name, "." ) != 0 &&
            strcmp( thisfile.name, ".." ) != 0 &&
            !(thisfile.attrib & _A_SUBDIR) )
        {
            char *newname = NULL;
            if( _fullFilename ) 
            {
                int len = strlen(_dir) + strlen(thisfile.name);
                newname = new char [len + 1];
                sprintf( newname, "%s%s", _dir, thisfile.name );      
            }
            else
            {
                int len = strlen(thisfile.name);
                newname = new char [len + 1];
                sprintf( newname, "%s", thisfile.name );
            }

            result->PutData( newname );
        }

        exitmeplease = _findnext( fileindex, &thisfile );
    }
#else
    DIR *dir = opendir(_dir[0] ? _dir : ".");
    if (dir == NULL)
        return result;
    for (struct dirent *entry; (entry = readdir(dir)) != NULL; ) {
        if (FilterMatch(entry->d_name, _filter)) {
            char fullname[strlen(_dir) + strlen(entry->d_name) + 2];
            sprintf(fullname, "%s%s%s", 
                _dir, 
                _dir[0] ? "/" : "",
                entry->d_name);
            if (!IsDirectory(fullname)) {
                result->PutData( 
                    newStr(_fullFilename ? fullname : entry->d_name));
            }
        }
    }
    closedir(dir);
#endif

    return result;
}