Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
string.h
Go to the documentation of this file.
1#pragma once
2#include <misc/gen/Locale.h>
3#include <misc/gen/math.h>
4#include <misc/global.h>
5#include <string>
6
7namespace sf
8{
9
18_MISC_FUNC char* decimal_separator_fix(char* buffer, size_t len);
19
25_MISC_FUNC size_t strncspn(const char* s, size_t n, const char* reject);
26
31_MISC_FUNC size_t strnspn(const char* s, size_t n, const char* accept);
32
37_MISC_FUNC const char* strnstr(const char* s, const char* find, size_t n);
38
42_MISC_FUNC std::string demangle(const char* name);
43
48
52_MISC_FUNC size_t stringHex(const char* hexstr, void* buffer, size_t sz);
53
57_MISC_FUNC std::string hexString(const void* buffer, size_t sz);
58
62_MISC_FUNC std::string bitToString(unsigned long wrd, size_t count);
63
71_MISC_FUNC std::string escape(const std::string& str, char delimiter = '\0');
72
80_MISC_FUNC std::string unescape(const std::string& str);
81
85_MISC_FUNC std::string filter(std::string str, const std::string& filter);
86
90_MISC_FUNC std::string toLower(std::string s);
91
95_MISC_FUNC std::string toUpper(std::string s);
96
100_MISC_FUNC std::string trim(std::string s, const std::string& t = " ");
101
105_MISC_FUNC std::string trimLeft(std::string s, const std::string& t = " ");
106
110_MISC_FUNC std::string trimRight(std::string s, const std::string& t = " ");
111
115_MISC_FUNC int wildcmp(const char* wild, const char* str, bool case_s);
116
120inline int wildcmp(const std::string& wild, const std::string& str, bool case_s);
121
125_MISC_FUNC std::string error_string(int error_num);
126
130_MISC_FUNC std::string stringf(const char* fmt, ...);
131
139_MISC_FUNC std::string replaceAll(const std::string& s, const std::string& from, const std::string& to);
140
144template<typename... Args>
145std::string string_format(const std::string& format, Args&&... args);
146
158template<typename T>
159char* gcvt(T value, int ndigits, char* buf, size_t len);
160
169template<typename T>
170std::string gcvtString(T value, int ndigits = 0);
171
185template<typename T>
186char* itoa(T value, char* buffer, int base = 10);
187
196template<typename T>
197std::string itostr(T value, int base = 10);
198
206template<typename T>
207T toFloat(const char* ptr, char** end_ptr = nullptr);
215template<typename T, typename S = std::string>
216T toNumber(const S& s, size_t* idx = nullptr);
217
225template<typename T, typename S = std::string>
226T toNumberDefault(const S& s, T def);
235template<typename T>
236std::string toString(T value, int digits = 0);
237
245template<typename T>
246std::string toStringPrecision(T value, int prec = std::numeric_limits<int>::max());
256_MISC_FUNC std::string numberString(double value, int digits, bool sign_on = true);
257
265_MISC_FUNC std::istream& read_to_delimiter(std::istream& is, std::string& s, char delimiter);
266
281template<typename T>
282int fcvt_r(T value, int ndigit, int* decpt, int* sign, char* buf, size_t len);
283
304template<typename T>
305int ecvt_r(T value, int ndigit, int* decpt, int* sign, char* buf, size_t len);
306
307}// namespace sf
308
309#include <misc/gen/string.hpp>
#define _MISC_FUNC
Definition misc/global.h:39
Definition Application.h:10
_MISC_FUNC std::string bitToString(unsigned long wrd, size_t count)
Converts an integer value to bit string '0' and '1' characters where the first character is the first...
std::string string_format(const std::string &format, Args &&... args)
Better implementation of 'stringf' ?
_MISC_FUNC std::string escape(const std::string &str, char delimiter='\0')
Escapes all control and non ascii characters.
_MISC_FUNC std::string hexString(const void *buffer, size_t sz)
Converts a block of data to a hexadecimal string.
_MISC_FUNC std::string trimRight(std::string s, const std::string &t=" ")
Trims a passed string right and returns it.
_MISC_FUNC size_t strnspn(const char *s, size_t n, const char *accept)
The strncspn() function calculates the length of the initial segment of 's' which consists entirely o...
_MISC_FUNC std::istream & read_to_delimiter(std::istream &is, std::string &s, char delimiter)
Read a stream until a given delimiter.
_MISC_FUNC std::string demangle(const char *name)
Returns the unmangled function name returned by type ID.
_MISC_FUNC std::string numberString(double value, int digits, bool sign_on=true)
String formats a floating point or integer value using scientific notation. where the exponent is alw...
std::string toStringPrecision(T value, int prec=std::numeric_limits< int >::max())
Converts any floating point value in to a string with a given precision. The default precision shows ...
_MISC_FUNC const char * strnstr(const char *s, const char *find, size_t n)
Find the first occurrence of find in s, where the search is limited to the first slen characters of s...
T toFloat(const char *ptr, char **end_ptr=nullptr)
A locale independent template version for std::strtof(), std::strtod() and std::strtold() functions w...
T toNumberDefault(const S &s, T def)
Converts a std::string to a T value and when not possible it returns the passed default.
_MISC_FUNC std::string stringf(const char *fmt,...)
Creates a formatted string and returns it in a string class instance.
_MISC_FUNC std::string trim(std::string s, const std::string &t=" ")
Trims a passed string at both sides and returns it.
int fcvt_r(T value, int ndigit, int *decpt, int *sign, char *buf, size_t len)
Function identical to ecvt(), except that 'ndigits' specifies the number of digits after the decimal ...
_MISC_FUNC char * decimal_separator_fix(char *buffer, size_t len)
Replaces a decimal comma for a point. This instead of changing the global locale. Used by template fu...
_MISC_FUNC char hexCharValue(char ch)
Returns numeric the value of the passed hexadecimal character.
_MISC_FUNC size_t strncspn(const char *s, size_t n, const char *reject)
The strncspn() function calculates the length of the initial segment of 's' which consists entirely o...
_MISC_FUNC std::string error_string(int error_num)
Thread safe version strerror_r() or strerror_s() when cross compiling for Windows.
std::string itostr(T value, int base=10)
Converts an integer type value to a std::string.
_MISC_FUNC std::string toUpper(std::string s)
Converts the passed string into an upper case one and returns it.
_MISC_FUNC std::string unescape(const std::string &str)
Unescapes the passed string escaped by the escape() function.
_MISC_FUNC int digits(double value)
Returns the amount of digits which are significant for the value. When the value is 12300....
_MISC_FUNC std::string trimLeft(std::string s, const std::string &t=" ")
Trims a passed string left and returns it.
_MISC_FUNC std::string toLower(std::string s)
Converts the passed string into a lower case one and returns it.
std::string gcvtString(T value, int ndigits=0)
Converts a floating-point number to a string always using a decimal point.
T toNumber(const S &s, size_t *idx=nullptr)
Converts a std::string to a T value and whe not possible it returns the passed default.
char * gcvt(T value, int ndigits, char *buf, size_t len)
Converts a floating-point number to a string always using a decimal point. It produces 'digits' signi...
_MISC_FUNC int wildcmp(const char *wild, const char *str, bool case_s)
Matches a string against a wildcard string such as "*.*" or "bl?h.*" etc.
int ecvt_r(T value, int ndigit, int *decpt, int *sign, char *buf, size_t len)
Converts number to a null-terminated string of 'ndigits' digits. where 'ndigits' is reduced to a syst...
_MISC_FUNC std::string filter(std::string str, const std::string &filter)
Filters all characters from the passed string and returns the resulting string.
std::string toString(T value, int digits=0)
The function converts number to a minimal length. It produces 'digits' significant digits in either p...
_MISC_FUNC size_t stringHex(const char *hexstr, void *buffer, size_t sz)
Converts a hexadecimal string to a block of data.
_MISC_FUNC std::string replaceAll(const std::string &s, const std::string &from, const std::string &to)
Replaces all occurrences of 'from' substring and replaces them with 'to' string.
char * itoa(T value, char *buffer, int base=10)
Converts an integer type value to a buffer. The itoa function converts value to a null-terminated buf...