mirror of
https://github.com/ksherlock/mpw-shell.git
synced 2024-06-02 15:41:37 +00:00
ce1a36eba5
eg: evaluate abc =~ /(abc)®4/ # sets the '@4' environment variable. evaluate abc !~ /[aA]bc/ MPW regular expressions are converted to c++11 std::regex regular expressions and evaluated. Sadly, the // regular expression syntax interferes with unix-paths (if the / count is odd). quoting or ∂-escaping the /s is therefore necessary. file globbing is not yet implemented.
49 lines
1.1 KiB
C++
49 lines
1.1 KiB
C++
#ifndef __mpw_regex_h__
|
|
#define __mpw_regex_h__
|
|
|
|
#include "environment.h"
|
|
|
|
#include <string>
|
|
#include <regex>
|
|
|
|
class mpw_regex {
|
|
|
|
public:
|
|
|
|
mpw_regex(const std::string &s, bool slash);
|
|
|
|
mpw_regex(const mpw_regex &) = default;
|
|
// mpw_regex(mpw_regex &&) = default;
|
|
|
|
~mpw_regex() = default;
|
|
|
|
|
|
mpw_regex &operator=(const mpw_regex &) = default;
|
|
// mpw_regex &operator=(mpw_regex &&) = default;
|
|
|
|
bool match(const std::string &, class Environment &);
|
|
bool match(const std::string &);
|
|
|
|
static bool is_glob(const std::string &s);
|
|
|
|
private:
|
|
typedef std::string::const_iterator iterator;
|
|
|
|
|
|
void convert_re(const std::string &, bool slash);
|
|
|
|
iterator convert_re(iterator iter, iterator end, std::string &accumulator, unsigned char term);
|
|
iterator convert_re_repeat(iterator iter, iterator end, std::string &accumulator);
|
|
iterator convert_re_set(iterator iter, iterator end, std::string &accumulator);
|
|
iterator convert_re_capture(iterator iter, iterator end, std::string &accumulator);
|
|
|
|
|
|
std::regex re;
|
|
std::string key;
|
|
int capture_map[10] = {}; // map mpw capture number to ecma group
|
|
int num_captures = 0;
|
|
|
|
};
|
|
|
|
#endif
|