Split lines with many copyright years
[gromacs.git] / src / gromacs / utility / cstringutil.h
blobe2b45501cc98cac56b16fc4b2557e08385d101b6
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2012,2013,2014,2015,2017 by the GROMACS development team.
7 * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
8 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9 * and including many others, as listed in the AUTHORS file in the
10 * top-level source directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
38 /*! \file
39 * \brief Generic C string handling functions.
41 * \inpublicapi
42 * \ingroup module_utility
44 #ifndef GMX_UTILITY_CSTRINGUTIL_H
45 #define GMX_UTILITY_CSTRINGUTIL_H
47 #include <stdio.h>
49 #include "gromacs/utility/basedefinitions.h"
51 /** Continuation character. */
52 #define CONTINUE '\\'
53 /** Standard size for char* string buffers. */
54 #define STRLEN 4096
56 /*! \brief
57 * Strip trailing spaces and if s ends with a ::CONTINUE remove that too.
59 * \returns TRUE if s ends with a CONTINUE, FALSE otherwise.
61 int continuing(char* s);
63 /*! \brief
64 * Reads a line from a stream.
66 * This routine reads a string from stream of max length n, including
67 * \0 and zero terminated, without newlines. \p s should be long
68 * enough (>= \p n)
70 char* fgets2(char* s, int n, FILE* stream);
72 /** Remove portion of a line after a ';' comment sign. */
73 void strip_comment(char* line);
75 /** Make a string uppercase. */
76 void upstring(char* str);
78 /** Remove leading whitespace from a string. */
79 void ltrim(char* str);
81 /** Remove trailing whitespace from a string. */
82 void rtrim(char* str);
84 /** Remove leading and trailing whitespace from a string. */
85 void trim(char* str);
87 /** Version of gmx_strcasecmp() that also ignores '-' and '_'. */
88 int gmx_strcasecmp_min(const char* str1, const char* str2);
89 /** Version of gmx_strncasecmp() that also ignores '-' and '_'. */
90 int gmx_strncasecmp_min(const char* str1, const char* str2, int n);
92 /** Case-insensitive strcmp(). */
93 int gmx_strcasecmp(const char* str1, const char* str2);
94 /** Case-insensitive strncmp(). */
95 int gmx_strncasecmp(const char* str1, const char* str2, int n);
97 /** Creates a duplicate of \p src. */
98 char* gmx_strdup(const char* src);
99 /** Duplicates first \p n characters of \p src. */
100 char* gmx_strndup(const char* src, int n);
102 /*! \brief
103 * Pattern matching with wildcards.
105 * \param[in] pattern Pattern to match against.
106 * \param[in] str String to match.
107 * \returns 0 on match, GMX_NO_WCMATCH if there is no match.
109 * Matches \p str against \p pattern, which may contain * and ? wildcards.
110 * All other characters are matched literally.
111 * Currently, it is not possible to match literal * or ?.
113 int gmx_wcmatch(const char* pattern, const char* str);
115 /** Return value for gmx_wcmatch() when there is no match. */
116 #define GMX_NO_WCMATCH 1
118 /** Magic hash initialization number from Dan J. Bernstein. */
119 extern const unsigned int gmx_string_hash_init;
121 /*! \brief
122 * Return a hash of the string according to Dan J. Bernsteins algorithm.
124 * \param[in] s String to calculate hash for.
125 * \param[in] hash_init Initial (or previous) hash value.
126 * \returns Updated hash value (hash_init combined with string hash).
128 * On the first invocation for a new string, use the constant
129 * gmx_string_hash_init for the second argument. If you want to create a hash
130 * corresponding to several concatenated strings, provide the returned hash
131 * value as hash_init for the second string, etc.
133 unsigned int gmx_string_fullhash_func(const char* s, unsigned int hash_init);
135 /*! \brief
136 * Return a hash of the string according to Dan J. Bernsteins algorithm.
138 * \param[in] s String to calculate hash for.
139 * \param[in] hash_init Initial (or previous) hash value.
140 * \returns Updated hash value (hash_init combined with string hash).
142 * Identical to gmx_string_fullhash_func, except that
143 * this routine only uses characters for which isalnum(c) is true,
144 * and all characters are converted to upper case.
146 unsigned int gmx_string_hash_func(const char* s, unsigned int hash_init);
148 /*! \brief
149 * Wraps lines, optionally indenting lines.
151 * Wraps lines at \p linewidth, indenting all following lines by \p indent
152 * spaces. A temp buffer is allocated and returned, which can be disposed of
153 * if no longer needed.
154 * If \p bIndentFirst is FALSE, then the first line will not be indented, only
155 * the lines that are created due to wapping.
157 char* wrap_lines(const char* buf, int line_width, int indent, gmx_bool bIndentFirst);
159 /*! \brief
160 * Convert a string to int64_t.
162 * This method works as the standard library function strtol(), except that it
163 * does not support different bases.
165 int64_t str_to_int64_t(const char* str, char** endptr);
167 /** Minimum size of buffer to pass to gmx_step_str(). */
168 #define STEPSTRSIZE 22
170 /*! \brief
171 * Prints a int64_t value in buf and returns the pointer to buf.
173 * buf should be large enough to contain i: STEPSTRSIZE (22) chars.
174 * When multiple int64_t values are printed in the same printf call,
175 * be sure to call gmx_step_str with different buffers.
177 char* gmx_step_str(int64_t i, char* buf);
179 #endif