From 45e6bd321e749219290618bf735fabc68a1579fc Mon Sep 17 00:00:00 2001 From: eidheim Date: Thu, 3 Aug 2017 12:04:10 +0200 Subject: [PATCH] Added remove_include_guard to Utility --- src/Utility.cc | 90 +++++++++++++++++++++++++++++++++++++++++++++++++- src/Utility.h | 4 ++- 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/src/Utility.cc b/src/Utility.cc index cede9a2..854e02e 100644 --- a/src/Utility.cc +++ b/src/Utility.cc @@ -1,4 +1,5 @@ #include "Utility.h" +#include std::string clangmm::to_string(CXString cx_string) { std::string string; @@ -7,4 +8,91 @@ std::string clangmm::to_string(CXString cx_string) { clang_disposeString(cx_string); } return string; -} \ No newline at end of file +} + +void clangmm::remove_include_guard(std::string &buffer) { + static std::regex ifndef_regex1("^[ \t]*#[ \t]*ifndef[ \t]+([A-Za-z0-9_]+).*$"); + static std::regex ifndef_regex2("^[ \t]*#[ \t]*if[ \t]+![ \t]*defined[ \t]*\\([ \t]*([A-Za-z0-9_]+).*$"); + static std::regex define_regex("^[ \t]*#[ \t]*define[ \t]+([A-Za-z0-9_]+).*$"); + static std::regex endif_regex("^[ \t]*#[ \t]*endif.*$"); + std::vector> ranges; + bool found_ifndef=false, found_define=false; + bool line_comment=false, multiline_comment=false; + size_t start_of_line=0; + std::string line; + std::string preprocessor_identifier; + for(size_t c=0;c