aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
utils_string.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
49#ifndef GUM_UTILS_STRING_H
50#define GUM_UTILS_STRING_H
51
52#include <cctype>
53#include <cstdlib>
54#include <sstream>
55#include <string>
56#include <vector>
57
58#include <agrum/agrum.h>
59
60namespace gum {
63
68 std::string getUniqueFileName();
69
74 std::string toLower(std::string str);
75
80 bool endsWith(std::string const& value, std::string const& ending);
81
88 std::vector< std::string > split(const std::string& orig, const std::string& delimiter);
89
97 std::string replace(const std::string& s, const std::string& val, const std::string& new_val);
98
104 bool isInteger(const std::string& val);
105
111 bool isIntegerWithResult(const std::string& val, int* res);
112
118 bool isNumerical(const std::string& val);
119
125 bool isNumericalWithResult(const std::string& val, double* res);
126
127
132 void ltrim(std::string& s);
133
138 void rtrim(std::string& s);
139
144 void trim(std::string& s);
145
151 std::string trim_copy(const std::string& s);
152
158 std::string remove_newline(const std::string& s);
159
160 template < typename T >
161 inline std::string compact_tostr(T value) {
162 std::ostringstream s;
163 s.precision(7);
164 s << value;
165 return s.str();
166 }
167
169} /* namespace gum */
170
171#ifndef GUM_NO_INLINE
173#endif // GUM_NO_INLINE
174
175#endif /* GUM_UTILS_STRING_H */
std::string getUniqueFileName()
Returns a path to a unique file name.
bool isNumericalWithResult(const std::string &val, double *res)
return true is a string contains a numerical (double) value
std::string replace(const std::string &s, const std::string &val, const std::string &new_val)
not usable for gcc 4.8 std::vector<std::string> split( const std::string& orig, ...
std::string compact_tostr(T value)
Returns a path to a unique file name.
void ltrim(std::string &s)
trim from start (in place)
bool isNumerical(const std::string &val)
return true is a string contains a numerical (double) value
bool isIntegerWithResult(const std::string &val, int *res)
return true is a string contains an integer value
bool isInteger(const std::string &val)
return true is a string contains an integer value
std::string toLower(std::string str)
Returns the lowercase version of str.
void trim(std::string &s)
trim from both ends (in place)
std::string remove_newline(const std::string &s)
remove all newlines in a string
void rtrim(std::string &s)
trim from end (in place)
std::vector< std::string > split(const std::string &str, const std::string &delim)
Split str using the delimiter.
bool endsWith(std::string const &value, std::string const &ending)
Returns true if value ends with ending.
std::string trim_copy(const std::string &s)
trim from both ends (copying)
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Contains usefull methods for random stuff.