PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/src/regex.cpp

https://github.com/Naddiseo/regex
C++ | 49 lines | 31 code | 8 blank | 10 comment | 3 complexity | 44884c7ba4b9dab2c21317023b2135cf MD5 | raw file
  1. /*
  2. * regex.cpp
  3. *
  4. * Copyright (C) 2011 richard
  5. *
  6. * This software is licensed as described in the file COPYING, which
  7. * you should have received as part of this distribution.
  8. * Created on: 2011-02-16
  9. * Author: richard
  10. */
  11. #include <regex.h>
  12. #include <token.h>
  13. #include <scanner.h>
  14. namespace _local {
  15. regex::regex(const char* rx, REGEX_FLAGS _flags) {
  16. rx_pattern = std::string(rx);
  17. flags = _flags;
  18. compile();
  19. }
  20. regex::regex(std::string rx, REGEX_FLAGS _flags){
  21. rx_pattern = rx;
  22. flags = _flags;
  23. compile();
  24. }
  25. bool regex::compile() {
  26. scanner _s(rx_pattern, flags);
  27. for(;;) {
  28. token t = token(new Token());
  29. if (!_s.advance(t)) {
  30. break;
  31. }
  32. tokens.push_back(t);
  33. }
  34. return true;
  35. }
  36. void regex::print() {
  37. for (auto token : tokens) {
  38. token->print();
  39. }
  40. }
  41. }