2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012, by the GROMACS development team, led by
5 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
6 * others, as listed in the AUTHORS file in the top-level source
7 * 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 false if POSIX regular expression
82 * header is not available (i.e., on Windows). In this case, calling other
83 * constructors than the default constructor throws an exception.
88 * \ingroup module_utility
94 * Returns true if regular expression support has been compiled in.
98 static bool isSupported();
101 * Constructs a regular expression that matches nothing.
107 * Constructs a regular expression from a string.
109 * \param[in] value String to compile into a regular expression.
110 * \throws std::bad_alloc if out of memory.
111 * \throws InvalidInputError if \p value is not a valid regular
115 * Consider whether some other exception type would be better.
117 explicit Regex(const char *value);
118 //! \copydoc Regex(const char *)
119 explicit Regex(const std::string &value);
120 //! Frees memory allocated for the regular expression.
126 PrivateImplPointer<Impl> impl_;
128 friend bool regexMatch(const char *str, const Regex ®ex);
129 friend bool regexMatch(const std::string &str, const Regex ®ex);