Skip to content

Commit

Permalink
Detect usage of std:: and avoid using namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
m42e committed Dec 18, 2015
1 parent 6946d4a commit 54efbe5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions plugin/cpp_auto_include.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 54efbe5

Please sign in to comment.