BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
StringUtils.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Fit/Tools/StringUtils.h
6 //! @brief Defines a few helper functions
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifdef SWIG
16 #error no need to expose this header to Swig
17 #endif
18 
19 #ifndef USER_API
20 #ifndef BORNAGAIN_FIT_TOOLS_STRINGUTILS_H
21 #define BORNAGAIN_FIT_TOOLS_STRINGUTILS_H
22 
23 #include <iomanip>
24 #include <sstream>
25 #include <string>
26 #include <vector>
27 
28 //! Utility functions to analyze or modify strings.
29 
31 
32 //! Returns true if text matches pattern with wildcards '*' and '?'.
33 bool matchesPattern(const std::string& text, const std::string& wildcardPattern);
34 
35 //! Split string into vector of string using delimeter.
36 std::vector<std::string> split(const std::string& text, const std::string& delimeter);
37 
38 //! Returns scientific string representing given value of any numeric type.
39 template <typename T> std::string scientific(const T value, int n = 10);
40 
41 template <typename T> std::string scientific(const T value, int n)
42 {
43  std::ostringstream out;
44  out << std::scientific << std::setprecision(n) << value;
45  return out.str();
46 }
47 
48 } // namespace mumufit::stringUtils
49 
50 #endif // BORNAGAIN_FIT_TOOLS_STRINGUTILS_H
51 #endif // USER_API
Utility functions to analyze or modify strings.
Definition: StringUtils.h:30
std::vector< std::string > split(const std::string &text, const std::string &delimeter)
Split string into vector of string using delimeter.
Definition: StringUtils.cpp:51
std::string scientific(const T value, int n=10)
Returns scientific string representing given value of any numeric type.
Definition: StringUtils.h:41
bool matchesPattern(const std::string &text, const std::string &wildcardPattern)
Returns true if text matches pattern with wildcards '*' and '?'.
Definition: StringUtils.cpp:22