Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rewrite without using c++11 regex which are not functional in gcc-4.8.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 28 Oct 2017 12:49:14 +0000 (14:49 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 28 Oct 2017 12:49:14 +0000 (14:49 +0200)
src/mc/remote/RemoteClient.cpp

index 32be209..4f87d9a 100644 (file)
@@ -10,7 +10,6 @@
 #include <cerrno>
 #include <cstddef>
 #include <cstdint>
-#include <regex>
 #include <string>
 #include <vector>
 
@@ -111,18 +110,22 @@ static bool is_filtered_lib(const std::string& libname)
 
 static std::string get_lib_name(const std::string& pathname)
 {
-  static const std::regex so_re("\\.so[\\.0-9]*$", std::regex_constants::basic);
-  static const std::regex version_re("-[\\.0-9-]*$", std::regex_constants::basic);
+  constexpr char digits[]  = ".0123456789";
   std::string map_basename = simgrid::xbt::Path(pathname).getBasename();
   std::string libname;
 
-  std::smatch match;
-  if (std::regex_search(map_basename, match, so_re)) {
-    libname = match.prefix();
-
-    // Strip the version suffix:
-    if (std::regex_search(libname, match, version_re))
-      libname = match.prefix();
+  size_t pos = map_basename.rfind(".so");
+  if (pos != std::string::npos && map_basename.find_first_not_of(digits, pos + 3) == std::string::npos) {
+    // strip the extension (matching regex "\.so[.0-9]*$")
+    libname.assign(map_basename, 0, pos);
+
+    // strip the version suffix (matching regex "-[.0-9-]*$")
+    while (true) {
+      pos = libname.rfind('-');
+      if (pos == std::string::npos || libname.find_first_not_of(digits, pos + 1) != std::string::npos)
+        break;
+      libname.erase(pos);
+    }
   }
 
   return libname;