Last change
on this file since 2280 was
1585,
checked in by ymipsl, 6 years ago
|
Create string splitting function based on regular expresion pattern (c++11)
YM
|
File size:
596 bytes
|
Rev | Line | |
---|
[1585] | 1 | #ifndef __STRING_TOOLS_HPP__ |
---|
| 2 | #define __STRING_TOOLS_HPP__ |
---|
| 3 | |
---|
| 4 | #include <string> |
---|
| 5 | #include <regex> |
---|
| 6 | #include <vector> |
---|
| 7 | |
---|
| 8 | namespace xios |
---|
| 9 | { |
---|
| 10 | std::vector<std::string> splitRegex(const std::string& input, const std::string& regex) ; |
---|
| 11 | |
---|
| 12 | inline std::vector<std::string> splitRegex(const std::string& input, const std::string& regex) |
---|
| 13 | { |
---|
| 14 | // passing -1 as the submatch index parameter performs splitting |
---|
| 15 | std::regex re(regex); |
---|
| 16 | std::regex_token_iterator<std::string::const_iterator> |
---|
| 17 | first{input.begin(), input.end(), re, -1}, |
---|
| 18 | last; |
---|
| 19 | return {first, last}; |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | } |
---|
| 23 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.