2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
35 /*! \libinternal \file
37 * Declares simple wrapper for regular expression functionality.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
41 * \ingroup module_utility
43 #ifndef GMX_UTILITY_GMXREGEX_H
44 #define GMX_UTILITY_GMXREGEX_H
56 /*! \libinternal \brief
57 * Matches a string with a regular expression.
59 * \param[in] str String to match.
60 * \param[in] regex Regular expression to match.
61 * \returns true if \p regex matches the whole \p str.
63 * Does not throw currently, but this is subject to change if/when better error
64 * handling is implemented (currently, it returns false if the matching fails,
65 * e.g., because of out-of-memory).
67 * \ingroup module_utility
69 bool regexMatch(const char *str, const Regex ®ex);
70 //! \copydoc regexMatch(const char *, const Regex &)
71 bool regexMatch(const std::string &str, const Regex ®ex);
74 /*! \libinternal \brief
75 * Represents a regular expression.
77 * This class provides a simple interface for regular expression construction.
78 * regexMatch() is used to match the regular expression against a string.
79 * POSIX extended regular expression syntax is used.
81 * Currently, isSupported() will return true if either
83 * -# POSIX regular expression header <regex.h> is available, or
84 * -# C++11 header \<regex> is available (e.g., new enough MSVC has this).
86 * In other cases, isSupported() returns false and calling other
87 * constructors than the default constructor throws an exception.
92 * \ingroup module_utility
98 * Returns true if regular expression support has been compiled in.
102 static bool isSupported();
105 * Constructs a regular expression that matches nothing.
111 * Constructs a regular expression from a string.
113 * \param[in] value String to compile into a regular expression.
114 * \throws std::bad_alloc if out of memory.
115 * \throws InvalidInputError if \p value is not a valid regular
119 * Consider whether some other exception type would be better.
121 explicit Regex(const char *value);
122 //! \copydoc Regex(const char *)
123 explicit Regex(const std::string &value);
124 //! Frees memory allocated for the regular expression.
130 PrivateImplPointer<Impl> impl_;
132 friend bool regexMatch(const char *str, const Regex ®ex);
133 friend bool regexMatch(const std::string &str, const Regex ®ex);