Skip to content

Commit 54efbe5

Browse files
committed
Detect usage of std:: and avoid using namespace
1 parent 6946d4a commit 54efbe5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

plugin/cpp_auto_include.vim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ module CppAutoInclude
111111
]
112112

113113
USING_STD = 'using namespace std;'
114+
USING_STD_REGEX = /using namespace std;|std::/
114115

115116
# do nothing if lines.count > LINES_THRESHOLD
116117
LINES_THRESHOLD = 1000
@@ -138,7 +139,7 @@ module CppAutoInclude
138139
# process each header
139140
HEADER_STD_COMPLETE_REGEX.each do |header, std, complete, regex|
140141
has_header = includes.detect { |l| l.first.include? "<#{header}>" }
141-
has_keyword = (has_header && !complete) || (content =~ regex)
142+
has_keyword = (has_header && !complete) || (content =~ rex)
142143
use_std ||= std && has_keyword
143144

144145
if has_keyword && !has_header
@@ -159,7 +160,7 @@ module CppAutoInclude
159160
end
160161

161162
# add / remove 'using namespace std'
162-
has_std = content[USING_STD]
163+
has_std = content[USING_STD_REGEX]
163164

164165
if use_std && !has_std && !includes.empty?
165166
VIM::append(includes.last.last+1, USING_STD)

0 commit comments

Comments
 (0)