BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
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 //! Split string into vector of string using delimeter.
33 std::vector<std::string> split(const std::string& text, const std::string& delimiter);
34 
35 //! Returns scientific string representing given value of any numeric type.
36 template <typename T>
37 std::string scientific(T value, int n = 10);
38 
39 template <typename T>
40 std::string scientific(const T value, int n)
41 {
42  std::ostringstream out;
43  out << std::scientific << std::setprecision(n) << value;
44  return out.str();
45 }
46 
47 } // namespace mumufit::stringUtils
48 
49 #endif // BORNAGAIN_FIT_TOOLS_STRINGUTILS_H
50 #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 &delimiter)
Split string into vector of string using delimeter.
Definition: StringUtils.cpp:22
std::string scientific(T value, int n=10)
Returns scientific string representing given value of any numeric type.
Definition: StringUtils.h:40