check_include_files(io.h HAVE_IO_H)
check_include_files(sched.h HAVE_SCHED_H)
-check_include_files(regex.h HAVE_POSIX_REGEX)
-# TODO: It could be nice to inform the user if no regex support is found,
-# as selections won't be fully functional.
-
include(CheckCXXSymbolExists)
check_cxx_symbol_exists(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
check_cxx_symbol_exists(sysconf unistd.h HAVE_SYSCONF)
include(gmxTestPipes)
gmx_test_pipes(HAVE_PIPES)
-check_include_file_cxx(regex HAVE_CXX11_REGEX)
-
include(gmxTestXDR)
gmx_test_xdr(GMX_SYSTEM_XDR)
# Darwin has system XDR, but it uses a three-argument flavour of
/* Define to 1 if xmmintrin.h is present, otherwise 0 */
#cmakedefine01 HAVE_XMMINTRIN_H
-/* Define to 1 if you have the POSIX <regex.h> header file. */
-#cmakedefine01 HAVE_POSIX_REGEX
-
-/* Define to 1 if you have the C++11 <regex> header file. */
-#cmakedefine01 HAVE_CXX11_REGEX
-
/* Define to 1 if you have the sysconf() function */
#cmakedefine HAVE_SYSCONF
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
}
if (bRegExp)
{
- if (!gmx::Regex::isSupported())
- {
- std::string message
- = gmx::formatString("No regular expression support, "
- "cannot match \"%s\"", str);
- GMX_THROW(gmx::InvalidInputError(message));
- }
regex_ = std::make_shared<gmx::Regex>(str);
}
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
}, gmx::InvalidInputError);
}
-TEST_F(SelectionCollectionTest, HandlesUnsupportedRegularExpressions)
-{
- if (!gmx::Regex::isSupported())
- {
- ASSERT_NO_FATAL_FAILURE(loadTopology("simple.gro"));
- EXPECT_THROW_GMX({
- sc_.parseFromString("resname \"R[AD]\"");
- sc_.compile();
- }, gmx::InvalidInputError);
- }
-}
-
TEST_F(SelectionCollectionTest, HandlesMissingMethodParamValue)
{
EXPECT_THROW_GMX(sc_.parseFromString("mindist from atomnr 1 cutoff"),
"resname \"R[BD]\"",
"resname ~ \"R[BD]\""
};
- if (gmx::Regex::isSupported())
- {
- runTest("simple.gro", selections);
- }
+ runTest("simple.gro", selections);
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
* that needs to include omp.h for OpenMP functions.
*
* The header gmxregex.h declares gmx::Regex and regexMatch() for basic regular
- * expression matching using an interface similar to C++11.
+ * expression matching using an interface similar to C++11 std::regex.
*
* The header messagestringcollector.h declares a gmx::MessageStringCollector
* class for composing messages with context information.
#include "gmxregex.h"
-#include "config.h"
-
-#if HAVE_POSIX_REGEX
-# include <sys/types.h>
-// old Mac needs sys/types.h before regex.h
-# include <regex.h>
-#else
-# include <regex>
-#endif
+#include <regex>
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/stringutil.h"
namespace gmx
{
-// static
-bool Regex::isSupported() //TODO: Remove
-{
- return true;
-}
-
-#if HAVE_POSIX_REGEX
-class Regex::Impl
-{
- public:
- explicit Impl(const char *value)
- {
- compile(value);
- }
- explicit Impl(const std::string &value)
- {
- compile(value.c_str());
- }
- ~Impl()
- {
- regfree(®ex_);
- }
-
- bool match(const char *value) const
- {
- int rc = regexec(®ex_, value, 0, nullptr, 0);
- if (rc != 0 && rc != REG_NOMATCH)
- {
- // TODO: Handle errors.
- }
- return (rc == 0);
- }
-
- private:
- void compile(const char *value)
- {
- std::string buf(formatString("^%s$", value));
- int rc = regcomp(®ex_, buf.c_str(), REG_EXTENDED | REG_NOSUB);
- if (rc != 0)
- {
- // TODO: Better error messages.
- GMX_THROW(InvalidInputError(formatString(
- "Error in regular expression \"%s\"", value)));
- }
- }
-
- regex_t regex_;
-};
-#else
class Regex::Impl
{
public:
private:
std::regex regex_;
};
-#endif
Regex::Regex()
: impl_(nullptr)
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2012,2013,2014,2018, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2018,2019, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
//! \endcond
/*! \libinternal \brief
- * Represents a regular expression.
+ * Represents a regular expression compatible with std::regex
*
* This class provides a simple interface for regular expression construction.
* regexMatch() is used to match the regular expression against a string.
* POSIX extended regular expression syntax is used.
*
- * Currently, isSupported() will return true if either
- *
- * -# POSIX regular expression header <regex.h> is available, or
- * -# C++11 header \<regex> is available (e.g., new enough MSVC has this).
- *
- * In other cases, isSupported() returns false and calling other
- * constructors than the default constructor throws an exception.
- *
* \see regexMatch()
*
* \inlibraryapi
class Regex
{
public:
- /*! \brief
- * Returns true if regular expression support has been compiled in.
- *
- * Does not throw.
- */
- static bool isSupported();
-
/*! \brief
* Constructs a regular expression that matches nothing.
*
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
/*! \internal \file
* \brief Tests for gmx::Regex
*
- * These tests ensure that basic regex operations work. We have
- * two different underlying implementations, so we need to prove
- * to ourselves that these work the same on the range of operations
- * we try to use.
+ * These tests ensure that basic regex operations work.
*
* \author Mark Abraham <mark.j.abraham@gmail.com>
* \ingroup module_utility
TEST(RegexBasicTest, BasicMatchesWorkWhenSupported)
{
- if (!Regex::isSupported())
- {
- return;
- }
-
EXPECT_TRUE(regexMatch("dog", Regex("dog")));
EXPECT_TRUE(regexMatch("dog", Regex("^dog")));
EXPECT_TRUE(regexMatch("dog", Regex("dog$")));
TEST(RegexBasicTest, MatchesForCharacterClassesWorkWhenSupported)
{
- if (!Regex::isSupported())
- {
- return;
- }
-
EXPECT_TRUE(regexMatch("Dog", Regex("[[:alpha:]]+")));
EXPECT_TRUE(regexMatch("dog", Regex("[[:lower:]]+")));
EXPECT_TRUE(regexMatch("DOG", Regex("[[:upper:]]+")));