EventAnalysis  1.3.0
StringUtils.h
Go to the documentation of this file.
1 /*
2  * StringUtils.h
3  *
4  * Created on: 17 Aug 2017
5  * Author: Nicola Mori
6  */
7 
10 #ifndef STRINGUTILS_H_
11 #define STRINGUTILS_H_
12 
13 #include "core/Traits.h" // TODO: Move Traits.h in utils ?
14 
15 #include <iostream>
16 #include <regex>
17 #include <string>
18 #include <vector>
19 namespace EA {
20 
22 namespace StringUtils {
23 
24 using Tokens = std::vector<std::string>;
25 
38 Tokens Tokenize(const std::string &str, char delimiter = ' ');
39 
47 std::string Trim(const std::string &str);
48 
56 bool IsInteger(const std::string &str);
57 
67 bool IsReal(const std::string &str);
68 
78 bool ToBoolean(const std::string &str);
79 
88 bool IsGlobExpression(const std::string &str);
89 
97 std::string RegexFromGlob(const std::string &str);
98 
108 template <typename Container>
109 std::enable_if_t<!(is_pointer<typename Container::value_type>::value), std::string> FindSimilar(const std::string &str,
110  const Container &cont);
111 
122 template <typename Container>
123 std::enable_if_t<is_pointer<typename Container::value_type>::value, std::string> FindSimilar(const std::string &str,
124  const Container &cont);
125 
126 } // namespace StringUtils
127 
128 } // namespace EA
129 
130 #include "utils/StringUtils.hpp"
131 
132 #endif /* STRINGUTILS_H_ */
bool ToBoolean(const std::string &str)
Converts a string into a boolean value.
Definition: StringUtils.cpp:124
bool IsGlobExpression(const std::string &str)
Check if the given string is a glob expression.
Definition: StringUtils.cpp:144
Tokens Tokenize(const std::string &str, char delimiter=' ')
Extracts words from a string.
Definition: StringUtils.cpp:17
IncludeFileExc.h IncludeFileExc class declaration.
Definition: Algorithm.h:21
std::string Trim(const std::string &str)
Trims a string.
Definition: StringUtils.cpp:69
std::vector< std::string > Tokens
Definition: StringUtils.h:24
std::string RegexFromGlob(const std::string &str)
Build a regex starting from a glob expression.
Definition: StringUtils.cpp:152
bool IsReal(const std::string &str)
Checks if a string is a real number.
Definition: StringUtils.cpp:92
bool IsInteger(const std::string &str)
Checks if a string is an a integer.
Definition: StringUtils.cpp:80
std::enable_if_t<!(is_pointer< typename Container::value_type >::value), std::string > FindSimilar(const std::string &str, const Container &cont)
Find a similar string inside a container.
Definition: StringUtils.hpp:22