Skip to content

Commit 118ef46

Browse files
committed
Replace std::regex in codecomplete to use llvm::regex
1 parent 508823a commit 118ef46

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lib/Interpreter/Compatibility.h

+14-6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static inline char* GetEnv(const char* Var_Name) {
7777
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
7878
#include "llvm/Support/Casting.h"
7979
#include "llvm/Support/Path.h"
80+
#include "llvm/Support/Regex.h"
8081

8182
#ifdef USE_CLING
8283

@@ -163,17 +164,24 @@ inline void codeComplete(std::vector<std::string>& Results,
163164
std::vector<std::string> results;
164165
size_t column = complete_column;
165166
I.codeComplete(code, column, results);
167+
std::string error;
168+
// Regex patterns
169+
llvm::Regex removeDefinition("\\[\\#.*\\#\\]");
170+
llvm::Regex removeVariableName("(\\ |\\*)+(\\w+)(\\#\\>)");
171+
llvm::Regex removeTrailingSpace("\\ *(\\#\\>)");
172+
llvm::Regex removeTags("\\<\\#([^#>]*)\\#\\>");
166173

167174
// append cleaned results
168-
for (auto& r : results) {
169-
// remove the definition at the beginning (for example [#int#])
170-
r = std::regex_replace(r, std::regex("\\[\\#.*\\#\\]"), "");
175+
for (auto &r : results) {
176+
// remove the definition at the beginning (e.g., [#int#])
177+
r = removeDefinition.sub("", r, &error);
171178
// remove the variable name in <#type name#>
172-
r = std::regex_replace(r, std::regex("(\\ |\\*)+(\\w+)(\\#\\>)"), "$1$3");
179+
r = removeVariableName.sub("$1$3", r, &error);
173180
// remove unnecessary space at the end of <#type #>
174-
r = std::regex_replace(r, std::regex("\\ *(\\#\\>)"), "$1");
181+
r = removeTrailingSpace.sub("$1", r, &error);
175182
// remove <# #> to keep only the type
176-
r = std::regex_replace(r, std::regex("\\<\\#([^#>]*)\\#\\>"), "$1");
183+
r = removeTags.sub("$1", r, &error);
184+
177185
if (r.find(code) == 0)
178186
Results.push_back(r);
179187
}

0 commit comments

Comments
 (0)