mirror of
https://github.com/MaskRay/ccls.git
synced 2025-04-16 05:42:17 +00:00
Change some API const std::string& -> std::string_view
This commit is contained in:
parent
4c895bef0b
commit
3e16055b31
@ -8,7 +8,7 @@
|
|||||||
// text documents.
|
// text documents.
|
||||||
// We use a UTF-8 iterator to approximate UTF-16 in the specification (weird).
|
// We use a UTF-8 iterator to approximate UTF-16 in the specification (weird).
|
||||||
// This is good enough and fails only for UTF-16 surrogate pairs.
|
// This is good enough and fails only for UTF-16 surrogate pairs.
|
||||||
int GetOffsetForPosition(lsPosition position, const std::string& content) {
|
int GetOffsetForPosition(lsPosition position, std::string_view content) {
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (; position.line > 0 && i < content.size(); i++)
|
for (; position.line > 0 && i < content.size(); i++)
|
||||||
if (content[i] == '\n')
|
if (content[i] == '\n')
|
||||||
@ -23,7 +23,7 @@ int GetOffsetForPosition(lsPosition position, const std::string& content) {
|
|||||||
return int(i);
|
return int(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
lsPosition CharPos(const std::string& search,
|
lsPosition CharPos(std::string_view search,
|
||||||
char character,
|
char character,
|
||||||
int character_offset) {
|
int character_offset) {
|
||||||
lsPosition result;
|
lsPosition result;
|
||||||
@ -216,7 +216,7 @@ std::string LexWordAroundPos(lsPosition position, const std::string& content) {
|
|||||||
return content.substr(start, end - start + 1);
|
return content.substr(start, end - start + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SubsequenceMatch(const std::string& search, const std::string& content) {
|
bool SubsequenceMatch(std::string_view search, std::string_view content) {
|
||||||
size_t j = 0;
|
size_t j = 0;
|
||||||
for (size_t i = 0; i < search.size(); i++) {
|
for (size_t i = 0; i < search.size(); i++) {
|
||||||
char search_char = tolower(search[i]);
|
char search_char = tolower(search[i]);
|
||||||
|
@ -2,13 +2,15 @@
|
|||||||
|
|
||||||
#include "language_server_api.h"
|
#include "language_server_api.h"
|
||||||
|
|
||||||
|
#include <string_view.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
// Utility method to map |position| to an offset inside of |content|.
|
// Utility method to map |position| to an offset inside of |content|.
|
||||||
int GetOffsetForPosition(lsPosition position, const std::string& content);
|
int GetOffsetForPosition(lsPosition position, std::string_view content);
|
||||||
// Utility method to find a position for the given character.
|
// Utility method to find a position for the given character.
|
||||||
lsPosition CharPos(const std::string& search,
|
lsPosition CharPos(std::string_view search,
|
||||||
char character,
|
char character,
|
||||||
int character_offset = 0);
|
int character_offset = 0);
|
||||||
|
|
||||||
@ -27,4 +29,4 @@ void LexFunctionDeclaration(const std::string& buffer_content,
|
|||||||
std::string LexWordAroundPos(lsPosition position, const std::string& content);
|
std::string LexWordAroundPos(lsPosition position, const std::string& content);
|
||||||
|
|
||||||
// Case-insensitive subsequence matching.
|
// Case-insensitive subsequence matching.
|
||||||
bool SubsequenceMatch(const std::string& search, const std::string& content);
|
bool SubsequenceMatch(std::string_view search, std::string_view content);
|
||||||
|
@ -26,7 +26,7 @@ REGISTER_IPC_MESSAGE(Ipc_CqueryMemberHierarchyExpand);
|
|||||||
struct Out_CqueryMemberHierarchy
|
struct Out_CqueryMemberHierarchy
|
||||||
: public lsOutMessage<Out_CqueryMemberHierarchy> {
|
: public lsOutMessage<Out_CqueryMemberHierarchy> {
|
||||||
struct Entry {
|
struct Entry {
|
||||||
std::string name;
|
std::string_view name;
|
||||||
size_t type_id;
|
size_t type_id;
|
||||||
lsLocation location;
|
lsLocation location;
|
||||||
};
|
};
|
||||||
@ -47,7 +47,7 @@ BuildInitial(QueryDatabase* db, WorkingFiles* working_files, QueryTypeId root) {
|
|||||||
return {};
|
return {};
|
||||||
|
|
||||||
Out_CqueryMemberHierarchy::Entry entry;
|
Out_CqueryMemberHierarchy::Entry entry;
|
||||||
entry.name = std::string(root_type.def->ShortName());
|
entry.name = root_type.def->ShortName();
|
||||||
entry.type_id = root.id;
|
entry.type_id = root.id;
|
||||||
entry.location = *def_loc;
|
entry.location = *def_loc;
|
||||||
return {entry};
|
return {entry};
|
||||||
@ -63,7 +63,7 @@ ExpandNode(QueryDatabase* db, WorkingFiles* working_files, QueryTypeId root) {
|
|||||||
for (auto& var_id : root_type.def->vars) {
|
for (auto& var_id : root_type.def->vars) {
|
||||||
QueryVar& var = db->vars[var_id.id];
|
QueryVar& var = db->vars[var_id.id];
|
||||||
Out_CqueryMemberHierarchy::Entry entry;
|
Out_CqueryMemberHierarchy::Entry entry;
|
||||||
entry.name = std::string(var.def->ShortName());
|
entry.name = var.def->ShortName();
|
||||||
entry.type_id =
|
entry.type_id =
|
||||||
var.def->variable_type ? var.def->variable_type->id : size_t(-1);
|
var.def->variable_type ? var.def->variable_type->id : size_t(-1);
|
||||||
if (var.def->definition_spelling) {
|
if (var.def->definition_spelling) {
|
||||||
|
Loading…
Reference in New Issue
Block a user