diff --git a/src/engines/answer/calc.rs b/src/engines/answer/calc.rs
index 387e56a..58725c8 100644
--- a/src/engines/answer/calc.rs
+++ b/src/engines/answer/calc.rs
@@ -3,27 +3,35 @@ use crate::engines::EngineResponse;
use super::regex;
pub fn request(query: &str) -> EngineResponse {
- let Some(result_html) = evaluate(query, true) else {
+ let query = clean_query(query.to_string());
+
+ let Some(result_html) = evaluate(&query, true) else {
return EngineResponse::new();
};
EngineResponse::answer_html(format!(
r#"
{query} =
{result_html}
"#,
- query = html_escape::encode_text(query),
+ query = html_escape::encode_text(&query),
))
}
pub fn request_autocomplete(query: &str) -> Vec {
let mut results = Vec::new();
- if let Some(result) = evaluate(query, false) {
+ let query = clean_query(query.to_string());
+
+ if let Some(result) = evaluate(&query, false) {
results.push(format!("{query}={result}"));
}
results
}
+fn clean_query(query: String) -> String {
+ query.strip_suffix('=').unwrap_or(&query).trim().to_string()
+}
+
fn evaluate(query: &str, html: bool) -> Option {
// at least 3 characters and not one of the short constants
if query.len() < 3 && !matches!(query.to_lowercase().as_str(), "pi" | "e" | "c") {