From fe1697928988ac3bf9acca853009585fb4e660c5 Mon Sep 17 00:00:00 2001 From: eidheim Date: Tue, 14 May 2024 12:10:26 +0200 Subject: [PATCH] ctags: location.symbol and location.source should now correspond with respect to escaping --- src/ctags.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/ctags.cpp b/src/ctags.cpp index 1541dbc..f8288a8 100644 --- a/src/ctags.cpp +++ b/src/ctags.cpp @@ -102,7 +102,21 @@ Ctags::Location Ctags::get_location(const std::string &line_, bool add_markup, b auto symbol_end = line.find('\t'); if(symbol_end == std::string::npos) return location; - location.symbol = line.substr(0, symbol_end); + + // Unescape symbol + if(symbol_end > 0) { + location.symbol.reserve(symbol_end); + bool escaped = false; + for(size_t i = 0; i < symbol_end; ++i) { + if(!escaped && line[i] == '\\') { + escaped = true; + continue; + } + escaped = false; + location.symbol += line[i]; + } + } + if(9 < location.symbol.size() && location.symbol[8] == ' ' && starts_with(location.symbol, "operator")) { auto &chr = location.symbol[9]; if(!((chr >= 'A' && chr <= 'Z') || (chr >= 'a' && chr <= 'z') || (chr >= '0' && chr <= '9') || chr == '_' || chr == '$' || static_cast(chr) >= 128))