source: XIOS3/trunk/src/string_tools.hpp @ 2628

Last change on this file since 2628 was 2614, checked in by ymipsl, 3 months ago
  • Permit now usage of contex_group into xml file for more modularity
  • Src path is now relative to parent file, except if path is an absolute path

YM

File size: 776 bytes
Line 
1#ifndef __STRING_TOOLS_HPP__
2#define __STRING_TOOLS_HPP__
3
4#include <string>
5#include <regex>
6#include <vector>
7
8namespace xios
9{
10  std::vector<std::string> splitRegex(const std::string& input, const std::string& regex) ;
11  std::string strTrim(const std::string& input) ;
12
13  inline std::vector<std::string> splitRegex(const std::string& input, const std::string& regex)
14  {
15      // passing -1 as the submatch index parameter performs splitting
16      std::regex re(regex);
17      std::regex_token_iterator<std::string::const_iterator>
18          first{input.begin(), input.end(), re, -1},
19          last;
20      return {first, last}; 
21  }
22
23  inline std::string strTrim(const std::string& input)
24  {
25    return std::regex_replace(input, std::regex("^ +| +$"), "$1");
26  }
27}
28#endif
Note: See TracBrowser for help on using the repository browser.