Example #1
0
void Xmlvalidator::mapsCreate(Document *xsd) {
	// Check that the root is a schema
	if (xsd->getRoot()->getName() == "xsd:schema")
	{
		// Get all the childrens
		vector<Item*> children = xsd->getRoot()->getChildren();

		for(vector<Item *>::iterator itElem = children.begin(); itElem != children.end(); itElem++) {
			// Get the actual element name
            string name = ((Tag *) (*itElem))->getAtts().front()->value;

            // Get the contruction node
            Tag * type = (Tag *) ((Tag *) (*itElem))->getChildren().front();
            Tag * construction = (Tag *) type->getChildren().front();

            string regex = createRegex(construction, construction->getName());

			mapRegex.insert(pair<string, string>(name, regex));
			// cout << "Regex added : " << regex << " for " << name << endl;
        }
	}
	else
	{
		cout << "Error: Wrong syntax for the given xsd while creating the maps." << endl;
	}
}
Example #2
0
static unsigned int filterVisualAssist(const FilterEntries& entries, const FilterEntries& names, const char* string, FilterOutput* output)
{
    std::vector<VisualAssistFragment> fragments;

    for (auto& s: split(string, isspace))
    {
		fragments.emplace_back();
        VisualAssistFragment& f = fragments.back();

        f.text = s;
		f.re.reset(createRegex(s.c_str(), getRegexOptions(output->options | SO_LITERAL)));
        f.ispath = s.find_first_of("/\\") != std::string::npos;
    }

	if (fragments.empty()) return dumpEntries(entries, output);

	// sort name components first, path components last, larger components first
	std::sort(fragments.begin(), fragments.end(),
        [](const VisualAssistFragment& lhs, const VisualAssistFragment& rhs) {
            return (lhs.ispath != rhs.ispath) ? lhs.ispath < rhs.ispath : lhs.text.length() > rhs.text.length();
        });

	// gather files by first component
	std::vector<unsigned int> results;

	filterRegex(fragments[0].ispath ? entries : names, fragments[0].re.get(),
		(fragments.size() == 1) ? output->limit : ~0u, [&](unsigned int i) { results.push_back(i); });

	// filter results by subsequent components
	for (size_t i = 1; i < fragments.size(); ++i)
	{
        const VisualAssistFragment& f = fragments[i];

		results.erase(std::remove_if(results.begin(), results.end(), [&](unsigned int i) -> bool {
            const FilterEntries& matchEntries = f.ispath ? entries : names;
            const FilterEntry& me = matchEntries.entries[i];

			return f.re->search(matchEntries.buffer + me.offset, me.length).size == 0; }), results.end());
	}

	// trim results according to limit
	if (results.size() > output->limit)
		results.resize(output->limit);

	// output results
	FilterHighlightBuffer hlbuf;

	for (auto& i: results)
	{
        const FilterEntry& e = entries.entries[i];
        
		if (output->options & SO_HIGHLIGHT_MATCHES)
			processMatchHighlightVisualAssist(fragments, hlbuf, e, entries.buffer, names.entries[i], names.buffer, output);
		else
			processMatch(e, entries.buffer, output);
	}

	return results.size();
}
Example #3
0
static unsigned int filterRegex(const FilterEntries& entries, const FilterEntries& matchEntries, const char* string, FilterOutput* output)
{
	unsigned int result = 0;

	std::unique_ptr<Regex> re(createRegex(string, getRegexOptions(output->options)));

	FilterHighlightBuffer hlbuf;

	filterRegex(matchEntries, re.get(), output->limit,
		[&](unsigned int i) {
            const FilterEntry& e = entries.entries[i];

			if (output->options & SO_HIGHLIGHT_MATCHES)
				processMatchHighlightRegex(re.get(), hlbuf, e, e.length - matchEntries.entries[i].length, entries.buffer, output);
			else
				processMatch(e, entries.buffer, output);

			result++;
		});

	return result;
}
Example #4
0
unsigned int searchProject(Output* output_, const char* file, const char* string, unsigned int options, unsigned int limit, const char* include, const char* exclude)
{
	SearchOutput output(output_, options, limit);
	std::unique_ptr<Regex> regex(createRegex(string, getRegexOptions(options)));
	std::unique_ptr<Regex> includeRe(include ? createRegex(include, RO_IGNORECASE) : 0);
	std::unique_ptr<Regex> excludeRe(exclude ? createRegex(exclude, RO_IGNORECASE) : 0);
	NgramRegex ngregex((options & SO_BRUTEFORCE) ? nullptr : regex.get());
	
	std::string dataPath = replaceExtension(file, ".qgd");
	FileStream in(dataPath.c_str(), "rb");
	if (!in)
	{
		output_->error("Error reading data file %s\n", dataPath.c_str());
		return 0;
	}
	
	DataFileHeader header;
	if (!read(in, header) || memcmp(header.magic, kDataFileHeaderMagic, strlen(kDataFileHeaderMagic)) != 0)
	{
		output_->error("Error reading data file %s: malformed header\n", dataPath.c_str());
		return 0;
	}

	{
		unsigned int chunkIndex = 0;

		// Assume 50% compression ratio (it's usually much better)
		BlockPool chunkPool(kChunkSize * 3 / 2);

		std::vector<unsigned char> index;
		DataChunkHeader chunk;

		WorkQueue queue(WorkQueue::getIdealWorkerCount(), kMaxQueuedChunkData);

		while (!output.isLimitReached() && read(in, chunk))
		{
			if (ngregex.empty() || chunk.indexSize == 0)
			{
				in.skip(chunk.indexSize);
			}
			else
			{
				try
				{
					index.resize(chunk.indexSize);
				}
				catch (const std::bad_alloc&)
				{
					output_->error("Error reading data file %s: malformed chunk\n", dataPath.c_str());
					return 0;
				}

				if (chunk.indexSize && !read(in, &index[0], chunk.indexSize))
				{
					output_->error("Error reading data file %s: malformed chunk\n", dataPath.c_str());
					return 0;
				}

				if (!ngregex.match(index, chunk.indexHashIterations))
				{
					in.skip(chunk.compressedSize);
					continue;
				}
			}

			std::shared_ptr<char> data = chunkPool.allocate(chunk.compressedSize + chunk.uncompressedSize, std::nothrow);

			if (!data || !read(in, data.get(), chunk.compressedSize))
			{
				output_->error("Error reading data file %s: malformed chunk\n", dataPath.c_str());
				return 0;
			}

			queue.push([=, &regex, &output, &includeRe, &excludeRe]() {
				char* compressed = data.get();
				char* uncompressed = data.get() + chunk.compressedSize;

				decompress(uncompressed, chunk.uncompressedSize, compressed, chunk.compressedSize);
				processChunk(regex.get(), &output, chunkIndex, uncompressed, chunk.fileCount, includeRe.get(), excludeRe.get());
			}, chunk.compressedSize + chunk.uncompressedSize);

			chunkIndex++;
		}
	}

	return output.output.getLineCount();
}