From 54efbe5b24533559978a8ac0211700bce555d405 Mon Sep 17 00:00:00 2001 From: Matthias Bilger Date: Thu, 17 Dec 2015 21:35:53 +0100 Subject: [PATCH] Detect usage of std:: and avoid using namespace --- plugin/cpp_auto_include.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin/cpp_auto_include.vim b/plugin/cpp_auto_include.vim index 8252e58..6ba8ad5 100644 --- a/plugin/cpp_auto_include.vim +++ b/plugin/cpp_auto_include.vim @@ -111,6 +111,7 @@ module CppAutoInclude ] USING_STD = 'using namespace std;' + USING_STD_REGEX = /using namespace std;|std::/ # do nothing if lines.count > LINES_THRESHOLD LINES_THRESHOLD = 1000 @@ -138,7 +139,7 @@ module CppAutoInclude # process each header HEADER_STD_COMPLETE_REGEX.each do |header, std, complete, regex| has_header = includes.detect { |l| l.first.include? "<#{header}>" } - has_keyword = (has_header && !complete) || (content =~ regex) + has_keyword = (has_header && !complete) || (content =~ rex) use_std ||= std && has_keyword if has_keyword && !has_header @@ -159,7 +160,7 @@ module CppAutoInclude end # add / remove 'using namespace std' - has_std = content[USING_STD] + has_std = content[USING_STD_REGEX] if use_std && !has_std && !includes.empty? VIM::append(includes.last.last+1, USING_STD)