crex

Explore, test, and check regular expressions in the terminal.


crex

/

src

/

crex.hh

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
#ifndef OB_CREX_HH
#define OB_CREX_HH

#include <string>
#include <vector>
#include <regex>
#include <utility>

namespace OB
{

class Crex
{
public:
  using Match = std::vector<std::pair<std::string, std::pair<size_t, size_t>>>;
  using Matches = std::vector<Match>;

  Crex();
  ~Crex();

  Crex& regex(std::string regex_);
  std::string regex() const;

  Crex& text(std::string text_);
  std::string text() const;

  Crex& options(std::regex_constants::syntax_option_type opts_);
  std::regex_constants::syntax_option_type options() const;

  Crex& flags(std::regex_constants::match_flag_type flgs_);
  std::regex_constants::match_flag_type flags() const;

  bool run();
  Matches const& matches() const;

private:
  std::string _regex;
  std::string _text;

  std::regex_constants::syntax_option_type _opts {};
  std::regex_constants::match_flag_type _flgs {};

  Matches _matches;

  std::pair<std::string, std::string> split(std::string str, std::string delim) const;

}; // class Crex

} // namespace OB

#endif // OB_CREX_HH
Back to Top