From ad5bf603b06951acf8152b6c6eb7c5cc65b6ad05 Mon Sep 17 00:00:00 2001 From: Ce Qin Date: Thu, 30 Nov 2017 12:35:50 +0800 Subject: [PATCH] Fix bug in JobIdentifier::base_name. --- source/base/job_identifier.cc | 10 ++++++---- tests/base/base_name.cc | 28 ++++++++++++++++++++++++++++ tests/base/base_name.output | 3 +++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 tests/base/base_name.cc create mode 100644 tests/base/base_name.output diff --git a/source/base/job_identifier.cc b/source/base/job_identifier.cc index 38abaca935..8fedc75760 100644 --- a/source/base/job_identifier.cc +++ b/source/base/job_identifier.cc @@ -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 index 0000000000..9c15cbad86 --- /dev/null +++ b/tests/base/base_name.cc @@ -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 index 0000000000..ade717fddf --- /dev/null +++ b/tests/base/base_name.output @@ -0,0 +1,3 @@ + +DEAL::test +DEAL::test -- 2.39.5