NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
stringtools.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2021 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#ifndef STRINGTOOLS_HPP
20#define STRINGTOOLS_HPP
21
22#include <string>
23#include <complex>
24#include <vector>
25
26#include "datetimetools.hpp"
27
28// Forward declaration
29class Settings;
30class StringView;
31
33{
39};
40
42{
47};
48
50{
51 TD_NONE = 0x0,
52 TD_HHMMSS = 0x1,
53 TD_HHMM = 0x2,
54
55 TD_YYMMDD = 0x100,
56 TD_DDMMYY = 0x200,
57 TD_DDMM = 0x400,
58
59 TD_UTC = 0x10000,
60
61 TD_SEP_COLON = 0x100000,
62 TD_SEP_DOT = 0x200000,
63 TD_SEP_MINUS = 0x400000,
64 TD_SEP_SLASH = 0x800000
65};
66
67std::string toString(int nNumber, const Settings& _option);
68std::string toString(double dNumber, const Settings& _option);
69std::string toString(double dNumber, int nPrecision = 7);
70std::string toString(const std::complex<double>& dNumber, int nPrecision = 7);
71std::string toString(int);
72std::string toString(__time64_t tTime, int timeStampFlags);
73std::string toString(sys_time_point tp, int timeStampFlags);
74std::string toString(long long int nNumber);
75std::string toString(size_t nNumber);
76std::string toCmdString(double dNumber);
77std::string toCmdString(const std::complex<double>& dNumber);
78std::string toString(bool bBoolean);
79std::string toHexString(int nNumber);
80
90template <class T>
91std::string toString(const std::vector<T>& vVector)
92{
93 std::string sString;
94
95 for (size_t i = 0; i < vVector.size(); i++)
96 {
97 sString += toString(vVector[i]) + ",";
98 }
99
100 if (!sString.size())
101 return "{}";
102
103 sString.back() = '}';
104
105 return "{" + sString;
106}
107
108std::vector<std::string> toStrVector(std::string sString);
109std::vector<int> toIntVector(std::string sString);
110std::string condenseText(const std::string& sText);
111std::string truncString(const std::string& sText, size_t nMaxChars);
112
113std::string wcstombs(const std::wstring& wStr);
114void StripSpaces(std::string&);
115
116std::string toInternalString(std::string sStr);
117std::string toExternalString(std::string sStr);
118
119std::string toLowerCase(const std::string& sUpperCase);
120std::string toUpperCase(const std::string& sLowerCase);
121int StrToInt(const std::string&);
122double StrToDb(const std::string&);
123double StrToLogical(const std::string&);
124std::complex<double> StrToCmplx(const std::string&);
125sys_time_point StrToTime(const std::string&);
126size_t versionToInt(std::string);
127std::string intToVersion(size_t);
128
129bool isConvertible(const std::string& sStr, ConvertibleType type = CONVTYPE_VALUE);
130int detectTimeDateFormat(const std::string&);
131
132std::string toSystemCodePage(std::string sOutput);
133std::string fromSystemCodePage(std::string sOutput);
134
135void replaceAll(std::string& sToModify, const std::string& sToRep, const std::string& sNewValue, size_t nStart = 0, size_t nEnd = std::string::npos);
136void replaceAll(std::string& sToModify, const char* sToRep, const char* sNewValue, size_t nStart = 0, size_t nEnd = std::string::npos);
137std::string replaceControlCharacters(std::string sToModify);
138std::string utf8parser(const std::string& sString);
139
140std::string replacePathSeparator(const std::string& __sPath);
141std::string getTimeStamp(bool bGetStamp = true);
142std::vector<std::string> split(const std::string& sStr, char cSplit);
143std::string ellipsize(const std::string& sLongString, size_t nMaxStringLength = 1024);
144
145bool isEqualStripped(StringView str1, StringView str2);
146
147#endif // STRINGTOOLS_HPP
148
149
This class manages the setting values of the internal (kernel) settings of this application.
Definition: settings.hpp:663
This class is the immutable (const) version of a string view. It can be constructed from a MutableStr...
std::chrono::time_point< std::chrono::system_clock, std::chrono::microseconds > sys_time_point
This is a typedef for a custom system_clock time_point with microseconds precision.
std::vector< int > toIntVector(std::string sString)
This function converts a std::string into a std::vector, where the string shall be passed as "{x,...
std::vector< std::string > toStrVector(std::string sString)
This function converts a std::string into a std::vector, where the string shall be passed as "{x,...
int detectTimeDateFormat(const std::string &)
Detects the contained date-time format and returns it as a bitflag composition.
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
TimeDateFormat
Definition: stringtools.hpp:50
@ TD_YYMMDD
Definition: stringtools.hpp:55
@ TD_SEP_SLASH
Definition: stringtools.hpp:64
@ TD_DDMM
Definition: stringtools.hpp:57
@ TD_SEP_COLON
Definition: stringtools.hpp:61
@ TD_HHMM
Definition: stringtools.hpp:53
@ TD_SEP_DOT
Definition: stringtools.hpp:62
@ TD_HHMMSS
Definition: stringtools.hpp:52
@ TD_UTC
Definition: stringtools.hpp:59
@ TD_NONE
Definition: stringtools.hpp:51
@ TD_SEP_MINUS
Definition: stringtools.hpp:63
@ TD_DDMMYY
Definition: stringtools.hpp:56
std::string toInternalString(std::string sStr)
Converts a string literal to the internal representation in tables and clusters.
std::string toString(int nNumber, const Settings &_option)
Converts an integer to a string.
Definition: stringtools.cpp:43
sys_time_point StrToTime(const std::string &)
Convert a string to a sys_time_point.
ConvertibleType
Definition: stringtools.hpp:42
@ CONVTYPE_DATE_TIME
Definition: stringtools.hpp:45
@ CONVTYPE_LOGICAL
Definition: stringtools.hpp:46
@ CONVTYPE_NONE
Definition: stringtools.hpp:43
@ CONVTYPE_VALUE
Definition: stringtools.hpp:44
std::string toHexString(int nNumber)
Converts an integer to a hexadecimal number printed as string.
std::string intToVersion(size_t)
Converts a multi-digit integer into a verison string.
TIMESTAMP
Definition: stringtools.hpp:33
@ GET_AS_TIMESTAMP
Definition: stringtools.hpp:35
@ GET_ONLY_TIME
Definition: stringtools.hpp:34
@ GET_FULL_PRECISION
Definition: stringtools.hpp:38
@ GET_MILLISECONDS
Definition: stringtools.hpp:37
@ GET_WITH_TEXT
Definition: stringtools.hpp:36
std::string truncString(const std::string &sText, size_t nMaxChars)
This function truncates the string to the passed max length (including a trailing ellipsis) or return...
std::string toLowerCase(const std::string &sUpperCase)
Converts uppercase to lowercase letters.
bool isConvertible(const std::string &sStr, ConvertibleType type=CONVTYPE_VALUE)
This function checks, whether a string can be converted to the selected ConvertibleType.
std::string replaceControlCharacters(std::string sToModify)
This function is a simple wrapper for replaceAll() and specialized to remove control characters from ...
std::vector< std::string > split(const std::string &sStr, char cSplit)
Splits a vector at the selected characters.
int StrToInt(const std::string &)
Converts a string into an integer.
std::string toExternalString(std::string sStr)
Converts an internal string to the external representation in the terminal.
double StrToDb(const std::string &)
Converts a string into a double.
void replaceAll(std::string &sToModify, const std::string &sToRep, const std::string &sNewValue, size_t nStart=0, size_t nEnd=std::string::npos)
This function replaces all occurences of the string sToRep in the string sToModify with the new value...
bool isEqualStripped(StringView str1, StringView str2)
Returns true, if the contents of the strings are equal, if all surrounding whitespaces will be stripp...
std::string fromSystemCodePage(std::string sOutput)
Transforms the system code page to the internal one.
size_t versionToInt(std::string)
Converts a version string into a multi-digit integer.
std::string ellipsize(const std::string &sLongString, size_t nMaxStringLength=1024)
Shortens the passed string by introducing a ellipsis in the middle of the string, if the string is lo...
std::string utf8parser(const std::string &sString)
Transforms a UTF8 encoded string into a standard ASCII string in the internal code page representatio...
std::string toUpperCase(const std::string &sLowerCase)
Converts lowercase letters to uppercase ones.
std::string toCmdString(double dNumber)
Converts a numerical value into a "full" precision string.
std::string toSystemCodePage(std::string sOutput)
Converts an internal to an external string. Does nothing currently.
std::complex< double > StrToCmplx(const std::string &)
Converts a string into a complex number.
std::string replacePathSeparator(const std::string &__sPath)
This function replaces the Windows style path sparators to UNIX style.
std::string condenseText(const std::string &sText)
Removes vowels and umlauts from the passed string.
std::string wcstombs(const std::wstring &wStr)
This function is a wrapper for the usual wcstombs function, which can handle wstrings.
double StrToLogical(const std::string &)
Converts a string into a double considering logical values.
std::string getTimeStamp(bool bGetStamp=true)
This function simple returns the current time as a default timestamp.