/src/regex.cpp
C++ | 49 lines | 31 code | 8 blank | 10 comment | 3 complexity | 44884c7ba4b9dab2c21317023b2135cf MD5 | raw file
- /*
- * regex.cpp
- *
- * Copyright (C) 2011 richard
- *
- * This software is licensed as described in the file COPYING, which
- * you should have received as part of this distribution.
- * Created on: 2011-02-16
- * Author: richard
- */
- #include <regex.h>
- #include <token.h>
- #include <scanner.h>
- namespace _local {
- regex::regex(const char* rx, REGEX_FLAGS _flags) {
- rx_pattern = std::string(rx);
- flags = _flags;
- compile();
- }
- regex::regex(std::string rx, REGEX_FLAGS _flags){
- rx_pattern = rx;
- flags = _flags;
- compile();
- }
-
- bool regex::compile() {
- scanner _s(rx_pattern, flags);
- for(;;) {
- token t = token(new Token());
- if (!_s.advance(t)) {
- break;
- }
- tokens.push_back(t);
- }
- return true;
- }
-
- void regex::print() {
- for (auto token : tokens) {
- token->print();
- }
- }
- }