]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix bug in JobIdentifier::base_name. 5554/head
authorCe Qin <qince168@gmail.com>
Thu, 30 Nov 2017 04:35:50 +0000 (12:35 +0800)
committerCe Qin <qince168@gmail.com>
Thu, 30 Nov 2017 04:37:18 +0000 (12:37 +0800)
source/base/job_identifier.cc
tests/base/base_name.cc [new file with mode: 0644]
tests/base/base_name.output [new file with mode: 0644]

index 38abaca93558240fea5193e2ae2b876b38e24ce3..8fedc757605291f97dabc3b88882686081332966 100644 (file)
@@ -54,11 +54,13 @@ std::string
 JobIdentifier::base_name(const char *filename)
 {
   std::string name(filename);
-  std::string::size_type pos = name.find('.');
-  name.erase(pos, name.size());
+  std::string::size_type pos;
   pos = name.rfind('/');
-  if (pos < name.size())
-    name.erase(0,pos);
+  if (pos != std::string::npos)
+    name.erase(0, pos + 1);
+  pos = name.rfind('.');
+  if (pos != std::string::npos)
+    name.erase(pos, name.size());
   return name;
 }
 
diff --git a/tests/base/base_name.cc b/tests/base/base_name.cc
new file mode 100644 (file)
index 0000000..9c15cba
--- /dev/null
@@ -0,0 +1,28 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 1998 - 2017 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+// test the functions of JobIdentifier::base_name
+
+#include "../tests.h"
+
+int main()
+{
+  initlog();
+
+  deallog << dealjobid.base_name("mypath/test.cc") << std::endl;;
+  deallog << dealjobid.base_name("/foo.bar/mypath/test.cc") << std::endl;
+
+  return 0;
+}
diff --git a/tests/base/base_name.output b/tests/base/base_name.output
new file mode 100644 (file)
index 0000000..ade717f
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::test
+DEAL::test

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.