Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect usage of std:: and avoid using namespace #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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