VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
StringUtil.h
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
34#ifndef STRINGUTIL_H
35#define STRINGUTIL_H
36
37#include <algorithm>
38#include <iostream>
39#include <sstream>
40#include <string>
41#include <vector>
42
43
44
45#define SSTR(x) static_cast<std::ostringstream &>((std::ostringstream() << std::dec << x)).str()
46
48{
49public:
50 static std::string findAndReplace(const std::string &source, const std::string &find,
51 const std::string &replace);
52 static std::string makeUpper(const std::string &instring);
53 static std::string makeLower(const std::string &instring);
54 static std::vector<std::string> split(const std::string &input, const std::string &delim = " ");
55 static bool contains(const std::string &source, const char *find);
56 static std::string pad(const std::string &input, char pad, int length);
57 static std::string trim(const std::string &input, const std::string &trim = std::string(" \t\n"));
58 static int toInt(const std::string &input);
59 static float toFloat(const std::string &input);
60 static double toDouble(const std::string &input);
61 static bool toBool(const std::string &input);
62 static std::vector<int> toIntVector(const std::string &s);
63 static std::vector<unsigned int> toUintVector(const std::string &s);
64 static std::vector<bool> toBoolVector(const std::string &s);
65 static std::vector<std::string> toStringVector(const std::string &s);
66 static std::vector<double> toDoubleVector(const std::string &s);
67 template <typename T>
68 static std::string toString(const T &t);
69
70 static bool endsWith(const std::string &input, const std::string &end);
71
72
73 template<class T>
74 static T fromString(const std::string& s)
75 {
76 std::istringstream stream (s);
77 T t;
78 stream >> t;
79 return t;
80 }
81
82private:
83 StringUtil() = default;
84
85 StringUtil(const StringUtil &) = default;
86
87 virtual ~StringUtil() = default;
88
89
90 static bool toBool(bool &t, const std::string &input, std::ios_base &(*f)(std::ios_base &));
91};
92
93#endif
94
static T fromString(const std::string &s)
Definition StringUtil.h:74
static std::string trim(const std::string &input, const std::string &trim=std::string(" \t\n"))
static std::vector< double > toDoubleVector(const std::string &s)
static std::vector< int > toIntVector(const std::string &s)
static std::string makeUpper(const std::string &instring)
static std::vector< unsigned int > toUintVector(const std::string &s)
static std::string makeLower(const std::string &instring)
static std::vector< std::string > split(const std::string &input, const std::string &delim=" ")
static bool endsWith(const std::string &input, const std::string &end)
static std::string pad(const std::string &input, char pad, int length)
static int toInt(const std::string &input)
static bool toBool(const std::string &input)
static std::string findAndReplace(const std::string &source, const std::string &find, const std::string &replace)
static double toDouble(const std::string &input)
static std::vector< bool > toBoolVector(const std::string &s)
static bool contains(const std::string &source, const char *find)
static float toFloat(const std::string &input)
static std::string toString(const T &t)
static std::vector< std::string > toStringVector(const std::string &s)
std::shared_ptr< T > SPtr