JamesReynolds created this revision.
JamesReynolds added a reviewer: alexfh.
JamesReynolds added a subscriber: cfe-commits.

Added Stroustrup_Case and stroustrup_Back 
(http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#S-naming)

```
class Stroustrup_Case_Class_Name
{
  void private_Stroustrup_Back_Method_Name();
}
```

http://reviews.llvm.org/D21472

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tidy/readability/IdentifierNamingCheck.h
  test/clang-tidy/readability-identifier-naming.cpp

Index: test/clang-tidy/readability-identifier-naming.cpp
===================================================================
--- test/clang-tidy/readability-identifier-naming.cpp
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -59,10 +59,10 @@
 // RUN:     {key: readability-identifier-naming.UsingCase, value: lower_case}, \
 // RUN:     {key: readability-identifier-naming.ValueTemplateParameterCase, value: camelBack}, \
 // RUN:     {key: readability-identifier-naming.VariableCase, value: lower_case}, \
-// RUN:     {key: readability-identifier-naming.VirtualMethodCase, value: UPPER_CASE}, \
+// RUN:     {key: readability-identifier-naming.VirtualMethodCase, value: Stroustrup_Case}, \
 // RUN:     {key: readability-identifier-naming.VirtualMethodPrefix, value: 'v_'}, \
 // RUN:     {key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE}, \
-// RUN:     {key: readability-identifier-naming.TypeAliasCase, value: lower_case}, \
+// RUN:     {key: readability-identifier-naming.TypeAliasCase, value: stroustrup_Back}, \
 // RUN:     {key: readability-identifier-naming.TypeAliasSuffix, value: '_t'}, \
 // RUN:     {key: readability-identifier-naming.IgnoreFailedSplit, value: 0} \
 // RUN:   ]}' -- -std=c++11 -fno-delayed-template-parsing \
@@ -261,7 +261,7 @@
 // CHECK-FIXES: {{^}}    virtual ~AAbstractClass() = 0;{{$}}
     virtual void VIRTUAL_METHOD();
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for virtual method 'VIRTUAL_METHOD'
-// CHECK-FIXES: {{^}}    virtual void v_VIRTUAL_METHOD();{{$}}
+// CHECK-FIXES: {{^}}    virtual void v_Virtual_Method();{{$}}
     void non_Virtual_METHOD() {}
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: invalid case style for private method 'non_Virtual_METHOD'
 // CHECK-FIXES: {{^}}    void __non_Virtual_METHOD() {}{{$}}
@@ -316,12 +316,12 @@
 
 using my_struct_type = THIS___Structure;
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'my_struct_type'
-// CHECK-FIXES: {{^}}using my_struct_type_t = this_structure;{{$}}
+// CHECK-FIXES: {{^}}using my_Struct_Type_t = this_structure;{{$}}
 
 template<typename t_t>
 using SomeOtherTemplate = my_other_templated_class  <:: FOO_NS  ::my_class>;
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for type alias 'SomeOtherTemplate'
-// CHECK-FIXES: {{^}}using some_other_template_t = CMyOtherTemplatedClass  <:: foo_ns  ::CMyClass>;{{$}}
+// CHECK-FIXES: {{^}}using some_Other_Template_t = CMyOtherTemplatedClass  <:: foo_ns  ::CMyClass>;{{$}}
 
 static void static_Function() {
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for function 'static_Function'
Index: clang-tidy/readability/IdentifierNamingCheck.h
===================================================================
--- clang-tidy/readability/IdentifierNamingCheck.h
+++ clang-tidy/readability/IdentifierNamingCheck.h
@@ -48,6 +48,8 @@
     CT_CamelBack,
     CT_UpperCase,
     CT_CamelCase,
+    CT_StroustrupCase,
+    CT_StroustrupBack
   };
 
   struct NamingStyle {
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===================================================================
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -163,6 +163,8 @@
         .Case("UPPER_CASE", CT_UpperCase)
         .Case("camelBack", CT_CamelBack)
         .Case("CamelCase", CT_CamelCase)
+        .Case("Stroustrup_Case", CT_StroustrupCase)
+        .Case("stroustrup_Back", CT_StroustrupBack)
         .Default(CT_AnyCase);
   };
 
@@ -189,6 +191,10 @@
       return "UPPER_CASE";
     case CT_CamelCase:
       return "CamelCase";
+    case CT_StroustrupCase:
+      return "Stroustrup_Case";
+    case CT_StroustrupBack:
+      return "stroustrup_Back";
     }
 
     llvm_unreachable("Unknown Case Type");
@@ -230,6 +236,8 @@
       llvm::Regex("^[a-z][a-zA-Z0-9]*$"),
       llvm::Regex("^[A-Z][A-Z0-9_]*$"),
       llvm::Regex("^[A-Z][a-zA-Z0-9]*$"),
+      llvm::Regex("^[A-Z]([a-z0-9]*(_[A-Z])?)*"),
+      llvm::Regex("^[a-z]([a-z0-9]*(_[A-Z])?)*"),
   };
 
   bool Matches = true;
@@ -319,6 +327,27 @@
       }
     }
     break;
+
+  case IdentifierNamingCheck::CT_StroustrupCase:
+    for (auto const &Word : Words) {
+      if (&Word != &Words.front())
+        Fixup += "_";
+      Fixup += Word.substr(0, 1).upper();
+      Fixup += Word.substr(1).lower();
+    }
+    break;
+
+  case IdentifierNamingCheck::CT_StroustrupBack:
+    for (auto const &Word : Words) {
+      if (&Word != &Words.front()) {
+        Fixup += "_";
+        Fixup += Word.substr(0, 1).upper();
+      } else {
+        Fixup += Word.substr(0, 1).lower();
+      }
+      Fixup += Word.substr(1).lower();
+    }
+    break;
   }
 
   return Fixup;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to