Skip to content

Commit a2e5ed3

Browse files
committed
extract func name
1 parent ad996ce commit a2e5ed3

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

src/webxtension_extension.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,42 @@ static bool ContainsMacroDefinition(const std::string &content) {
8080
return false;
8181
}
8282

83+
// Parse Function Name
84+
static std::string ExtractMacroName(const std::string &macro_sql) {
85+
try {
86+
// Convert to uppercase for case-insensitive matching
87+
std::string upper_sql = StringUtil::Upper(macro_sql);
88+
89+
// Find the MACRO keyword
90+
size_t macro_pos = upper_sql.find("MACRO");
91+
if (macro_pos == std::string::npos) {
92+
return "unknown";
93+
}
94+
95+
// Find the start of the name (after MACRO and any whitespace)
96+
size_t name_start = macro_pos + 5; // length of "MACRO"
97+
while (name_start < upper_sql.length() && std::isspace(upper_sql[name_start])) {
98+
name_start++;
99+
}
100+
101+
// Find the end of the name (before the opening parenthesis)
102+
size_t name_end = upper_sql.find('(', name_start);
103+
if (name_end == std::string::npos) {
104+
return "unknown";
105+
}
106+
107+
// Trim any trailing whitespace
108+
while (name_end > name_start && std::isspace(upper_sql[name_end - 1])) {
109+
name_end--;
110+
}
111+
112+
// Get the original case version of the name from the input string
113+
return macro_sql.substr(name_start, name_end - name_start);
114+
} catch (...) {
115+
return "unknown";
116+
}
117+
}
118+
83119
// Function to fetch and create macro from URL
84120
static void LoadMacroFromUrlFunction(DataChunk &args, ExpressionState &state, Vector &result, DatabaseInstance *db_instance) {
85121
auto &context = state.GetContext();
@@ -129,7 +165,10 @@ static void LoadMacroFromUrlFunction(DataChunk &args, ExpressionState &state, Ve
129165
throw std::runtime_error("Failed loading Macro: " + query_result->GetError());
130166
}
131167

132-
return StringVector::AddString(result, "Successfully loaded macro");
168+
// Extract macro name before executing
169+
std::string macro_name = ExtractMacroName(macro_sql);
170+
171+
return StringVector::AddString(result, "Successfully loaded macro: " + macro_name);
133172

134173
} catch (std::exception &e) {
135174
std::string error_msg = "Error: " + std::string(e.what());

0 commit comments

Comments
 (0)