diff --git a/src/binding/node_data_interface.h b/src/binding/node_data_interface.h index 40d7c796..212f39f9 100644 --- a/src/binding/node_data_interface.h +++ b/src/binding/node_data_interface.h @@ -36,7 +36,7 @@ template <> Napi::Object get_at(const Napi::Array &candidates, const size_t ind) template <> size_t get_size(const Napi::Array &candidates) { return candidates.Length(); } template <> void set_at(Napi::Array &candidates, CandidateString &&value, const size_t iCandidate) { - candidates.Set(iCandidate, move(value)); + candidates.Set(iCandidate, move(string(value))); } template <> void set_at(Napi::Array &candidates, Napi::Number &&value, const uint32_t iCandidate) { @@ -78,7 +78,7 @@ template <> Napi::Array copy(const Napi::Array &arr, const Napi::Env &env) { return arr_copy; } -template <> CandidateString get_at(const Napi::Object &candidates, const string ind) { +template <> string get_at(const Napi::Object &candidates, const string ind) { return candidates.Get(ind).ToString().Utf8Value(); } @@ -98,6 +98,10 @@ template <> void set_at(Napi::Object &candidates, const string &value, const str candidates.Set(index, value); } +template <> void set_at(Napi::Object &candidates, const string_view &value, const string index) { + candidates.Set(index, string(value)); +} + template <> void set_at(Napi::Object &candidates, const size_t &value, const string index) { candidates.Set(index, value); } diff --git a/src/common.h b/src/common.h index db874808..90bd9dac 100644 --- a/src/common.h +++ b/src/common.h @@ -34,8 +34,8 @@ class SafeString : public std::string { using Element = SafeString; using CandidateString = SafeString; #else -using Element = string; -using CandidateString = string; +using Element = string_view; +using CandidateString = string_view; #endif using CandidateIndex = size_t; @@ -44,10 +44,10 @@ using Score = float; struct PreparedQuery { Element query; - Element query_lw; - Element core; - Element core_lw; - Element core_up; + string query_lw; + string core; + string core_lw; + string core_up; int depth = 0; Element ext; std::set charCodes{}; @@ -55,13 +55,13 @@ struct PreparedQuery { explicit PreparedQuery(const Element &q, const char pathSeparator); }; -Element ToLower(const Element &s) { +string ToLower(const Element &s) { auto snew = string(s.size(), ' '); // new string std::transform(s.begin(), s.end(), snew.begin(), ::tolower); return snew; } -Element ToUpper(const Element &s) { +string ToUpper(const Element &s) { auto snew = string(s.size(), ' '); // new string std::transform(s.begin(), s.end(), snew.begin(), ::toupper); return snew; diff --git a/src/matcher.h b/src/matcher.h index d5f837cc..10b7deb0 100644 --- a/src/matcher.h +++ b/src/matcher.h @@ -246,7 +246,7 @@ void get_wrap(const CandidateString &string, const Element &query, const Options const auto tagClose = ""s; if (string == query) { - *out = tagOpen + string + tagClose; + *out = tagOpen + std::string(string) + tagClose; return; } diff --git a/src/query.h b/src/query.h index c4a8c32f..fddedb66 100644 --- a/src/query.h +++ b/src/query.h @@ -10,7 +10,7 @@ namespace zadeh { // Optional chars // Those char improve the score if present, but will not block the match (score=0) if absent. -Element coreChars(Element query) { +auto coreChars(string query) { for (const auto ch : " _-:/\\") { query.erase(std::remove(query.begin(), query.end(), ch), query.end()); } @@ -33,7 +33,8 @@ std::set getCharCodes(const Element &str) { } PreparedQuery::PreparedQuery(const Element &q, const char pathSeparator) - : query(q), query_lw(ToLower(q)), core(coreChars(q)), core_lw(ToLower(core)), core_up(ToUpper(core)) { + : query(q), query_lw(ToLower(q)), core(coreChars(string(q))), core_lw(ToLower(core)), + core_up(ToUpper(core)) { depth = countDir(query, query.size(), pathSeparator); ext = getExtension(query_lw); charCodes = getCharCodes(query_lw);