1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
/***********************************************/
/**
* @file string.h
*
* @brief Miscellaneous string functions.
*
* @author Torsten Mayer-Guerr
* @author Sebastian Strasser
* @date 2019-09-04
*
*/
/***********************************************/
#ifndef __GROOPS_STRING__
#define __GROOPS_STRING__
/***********************************************/
#include "base/importStd.h"
#include <regex>
/***** CLASS ***********************************/
/**
* @brief Miscellaneous string functions.
* @ingroup base */
namespace String
{
/** @brief The @p str is converted to upper case. */
std::string upperCase(const std::string &str);
/** @brief The @p str is converted to lower case. */
std::string lowerCase(const std::string &str);
/** @brief Remove all leading and trailing spaces from @p str. */
std::string trim(const std::string &str);
/** @brief Remove all trailing spaces from @p str. */
std::string trimRight(const std::string &str);
/** @brief Remove all leading spaces from @p str. */
std::string trimLeft(const std::string &str);
/** @brief Convert to Double. Returns 0 if substring is all white spaces. */
Double toDouble(const std::string &str);
/** @brief Convert to Int. Returns 0 if substring is all white spaces. */
Int toInt(const std::string &str);
/** @brief test whether the @a str contains @p test. */
Bool contains(const std::string &str, const std::string &test);
/** @brief test whether the @a str starts with @p test. */
Bool startsWith(const std::string &str, const std::string &test);
/** @brief test whether the @a str ends with @p test. */
Bool endsWith(const std::string &str, const std::string &test);
/** @brief Replace all occurrences of @p search in @p str with the @p substitute string. */
std::string replaceAll(const std::string &str, const std::string &search, const std::string &substitute);
/** @brief Replace all occurrences of @p substitutes.first with the @p substitutes.second string. */
std::string replaceAll(const std::string &str, const std::vector<std::pair<std::string, std::string>> &substitutes);
/** @brief Returns a splitted string separated by @p seperator. */
std::vector<std::string> split(const std::string &str, Char seperator);
/** @brief Returns a splitted string separated by any character of @p seperators. */
std::vector<std::string> split(const std::string &str, const std::string &seperators);
/** @brief Convert a simple wildcard pattern into an equivalent regex expression.
* Wildcards *, ? can be escaped \*, \?. */
std::regex wildcard2regex(const std::string &pattern);
}
/***********************************************/
#endif /* __GROOPS___ */
|