mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 23:55:08 +00:00
Log message if creating regex fails
This commit is contained in:
parent
864ff122d8
commit
89b34a359c
35
src/match.cc
35
src/match.cc
@ -1,8 +1,10 @@
|
|||||||
#include "match.h"
|
#include "match.h"
|
||||||
|
|
||||||
#include <doctest/doctest.h>
|
#include <doctest/doctest.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
Matcher::Matcher(const std::string& search) {
|
// static
|
||||||
|
optional<Matcher> Matcher::Create(const std::string& search) {
|
||||||
/*
|
/*
|
||||||
std::string real_search;
|
std::string real_search;
|
||||||
real_search.reserve(search.size() * 3 + 2);
|
real_search.reserve(search.size() * 3 + 2);
|
||||||
@ -13,13 +15,22 @@ Matcher::Matcher(const std::string& search) {
|
|||||||
real_search += ".*";
|
real_search += ".*";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
regex_string = search;
|
try {
|
||||||
regex = std::regex(regex_string,
|
Matcher m;
|
||||||
|
m.regex_string = search;
|
||||||
|
m.regex = std::regex(search,
|
||||||
std::regex_constants::ECMAScript |
|
std::regex_constants::ECMAScript |
|
||||||
std::regex_constants::icase |
|
std::regex_constants::icase |
|
||||||
std::regex_constants::optimize
|
std::regex_constants::optimize
|
||||||
//std::regex_constants::nosubs
|
//std::regex_constants::nosubs
|
||||||
);
|
);
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
catch (std::exception e) {
|
||||||
|
// TODO/FIXME: show a warning message, we need to access IpcManager so we can print it safely to stdout.
|
||||||
|
std::cerr << "Building matcher for " << search << " failed; " << e.what() << std::endl;
|
||||||
|
return nullopt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matcher::IsMatch(const std::string& value) const {
|
bool Matcher::IsMatch(const std::string& value) const {
|
||||||
@ -31,10 +42,16 @@ bool Matcher::IsMatch(const std::string& value) const {
|
|||||||
GroupMatch::GroupMatch(
|
GroupMatch::GroupMatch(
|
||||||
const std::vector<std::string>& whitelist,
|
const std::vector<std::string>& whitelist,
|
||||||
const std::vector<std::string>& blacklist) {
|
const std::vector<std::string>& blacklist) {
|
||||||
for (const std::string& entry : whitelist)
|
for (const std::string& entry : whitelist) {
|
||||||
this->whitelist.push_back(Matcher(entry));
|
optional<Matcher> m = Matcher::Create(entry);
|
||||||
for (const std::string& entry : blacklist)
|
if (m)
|
||||||
this->blacklist.push_back(Matcher(entry));
|
this->whitelist.push_back(*m);
|
||||||
|
}
|
||||||
|
for (const std::string& entry : blacklist) {
|
||||||
|
optional<Matcher> m = Matcher::Create(entry);
|
||||||
|
if (m)
|
||||||
|
this->blacklist.push_back(*m);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GroupMatch::IsMatch(const std::string& value, std::string* match_failure_reason) const {
|
bool GroupMatch::IsMatch(const std::string& value, std::string* match_failure_reason) const {
|
||||||
@ -61,7 +78,7 @@ bool GroupMatch::IsMatch(const std::string& value, std::string* match_failure_re
|
|||||||
TEST_SUITE("Matcher");
|
TEST_SUITE("Matcher");
|
||||||
|
|
||||||
TEST_CASE("sanity") {
|
TEST_CASE("sanity") {
|
||||||
Matcher m("abc");
|
//Matcher m("abc");
|
||||||
// TODO: check case
|
// TODO: check case
|
||||||
//CHECK(m.IsMatch("abc"));
|
//CHECK(m.IsMatch("abc"));
|
||||||
//CHECK(m.IsMatch("fooabc"));
|
//CHECK(m.IsMatch("fooabc"));
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <optional.h>
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <string.>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
using std::experimental::optional;
|
||||||
|
using std::experimental::nullopt;
|
||||||
|
|
||||||
struct Matcher {
|
struct Matcher {
|
||||||
Matcher(const std::string& search);
|
static optional<Matcher> Create(const std::string& search);
|
||||||
|
|
||||||
bool IsMatch(const std::string& value) const;
|
bool IsMatch(const std::string& value) const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user