3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
9 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11 * Copyright (c) 2001-2009, The GROMACS development team,
12 * check out http://www.gromacs.org for more information.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * If you want to redistribute modifications, please consider that
20 * scientific software is very special. Version control is crucial -
21 * bugs must be traceable. We will be happy to consider code for
22 * inclusion in the official distribution, but derived work must not
23 * be called official GROMACS. Details are found in the README & COPYING
24 * files - if they are missing, get the official version at www.gromacs.org.
26 * To help us fund GROMACS development, we humbly ask that you cite
27 * the papers on the package - you can find them in the top README file.
29 * For more info, check our website at http://www.gromacs.org
31 /*! \libinternal \file
33 * Declares simple wrapper for regular expression functionality.
35 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
37 * \ingroup module_utility
39 #ifndef GMX_UTILITY_GMXREGEX_H
40 #define GMX_UTILITY_GMXREGEX_H
52 /*! \libinternal \brief
53 * Matches a string with a regular expression.
55 * \param[in] str String to match.
56 * \param[in] regex Regular expression to match.
57 * \returns true if \p regex matches the whole \p str.
59 * Does not throw currently, but this is subject to change if/when better error
60 * handling is implemented (currently, it returns false if the matching fails,
61 * e.g., because of out-of-memory).
63 * \ingroup module_utility
65 bool regexMatch(const char *str, const Regex ®ex);
66 //! \copydoc regexMatch(const char *, const Regex &)
67 bool regexMatch(const std::string &str, const Regex ®ex);
70 /*! \libinternal \brief
71 * Represents a regular expression.
73 * This class provides a simple interface for regular expression construction.
74 * regexMatch() is used to match the regular expression against a string.
75 * POSIX extended regular expression syntax is used.
77 * Currently, isSupported() will return false if POSIX regular expression
78 * header is not available (i.e., on Windows). In this case, calling other
79 * constructors than the default constructor throws an exception.
84 * \ingroup module_utility
90 * Returns true if regular expression support has been compiled in.
94 static bool isSupported();
97 * Constructs a regular expression that matches nothing.
103 * Constructs a regular expression from a string.
105 * \param[in] value String to compile into a regular expression.
106 * \throws std::bad_alloc if out of memory.
107 * \throws InvalidInputError if \p value is not a valid regular
111 * Consider whether some other exception type would be better.
113 explicit Regex(const char *value);
114 //! \copydoc Regex(const char *)
115 explicit Regex(const std::string &value);
116 //! Frees memory allocated for the regular expression.
122 PrivateImplPointer<Impl> impl_;
124 friend bool regexMatch(const char *str, const Regex ®ex);
125 friend bool regexMatch(const std::string &str, const Regex ®ex);