From 5ee3c3b11cf1944e9812e78b06a459198475cb64 Mon Sep 17 00:00:00 2001
From: Etienne Kneuss <ekneuss@gmail.com>
Date: Fri, 21 Aug 2015 14:21:56 +0200
Subject: [PATCH] Fix name lookup w.r.t. encoding

---
 src/main/scala/leon/LeonOption.scala | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/main/scala/leon/LeonOption.scala b/src/main/scala/leon/LeonOption.scala
index 46deafab5..ff68b9e36 100644
--- a/src/main/scala/leon/LeonOption.scala
+++ b/src/main/scala/leon/LeonOption.scala
@@ -112,8 +112,25 @@ object OptionsHelpers {
     val regexPatterns = patterns map { s =>
       import java.util.regex.Pattern
 
-      val p = "(.+\\.)?"+s.replaceAll("\\.", "\\\\.").replaceAll("_", ".+")
-      Pattern.compile(p)
+      // We encode the user query, reverting the encoding for . as those are
+      // not encoded in our fullnames
+      val encoded = scala.reflect.NameTransformer.encode(s).replaceAll("\\$u002E", ".")
+
+      // wildcards become ".*", rest is quoted.
+      var p = encoded.split("_").toList.map(Pattern.quote).mkString(".*")
+
+      // We account for _ at begining and end
+      if (encoded.endsWith("_")) {
+        p += ".*"
+      }
+
+      if (encoded.startsWith("_")) {
+        p = ".*"+p
+      }
+
+      // Finally, we match qualified suffixes (e.g. searching for 'size' will
+      // match 'List.size' but not 'thesize')
+      Pattern.compile("(.+\\.)?"+p)
     }
 
     { (name: String) => regexPatterns.exists(p => p.matcher(name).matches()) }
-- 
GitLab