else
Matches = false;
+ // Ensure the name doesn't have any extra underscores beyond those specified
+ // in the prefix and suffix.
+ if (Name.startswith("_") || Name.endswith("_"))
+ Matches = false;
+
if (Style.Case && !Matchers[static_cast<size_t>(*Style.Case)].match(Name))
Matches = false;
static std::string
fixupWithStyle(StringRef Name,
const IdentifierNamingCheck::NamingStyle &Style) {
- return Style.Prefix +
- fixupWithCase(Name, Style.Case.getValueOr(
- IdentifierNamingCheck::CaseType::CT_AnyCase)) +
- Style.Suffix;
+ const std::string Fixed = fixupWithCase(
+ Name, Style.Case.getValueOr(IdentifierNamingCheck::CaseType::CT_AnyCase));
+ StringRef Mid = StringRef(Fixed).trim("_");
+ if (Mid.empty())
+ Mid = "_";
+ return (Style.Prefix + Mid + Style.Suffix).str();
}
static StyleKind findStyleKind(
int member2 = 2;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'member2'
// CHECK-FIXES: {{^}} int __member2 = 2;{{$}}
+ int _memberWithExtraUnderscores_ = 42;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member '_memberWithExtraUnderscores_'
+// CHECK-FIXES: {{^}} int __memberWithExtraUnderscores = 42;{{$}}
private:
int private_member = 3;