1 #include "Utils.h"
2 
3 namespace clang
4 {
5 namespace tidy
6 {
7 namespace cata
8 {
9 
NameConvention(StringRef xName)10 NameConvention::NameConvention( StringRef xName )
11 {
12     if( xName.endswith( "x" ) ) {
13         root = xName.drop_back();
14         capital = false;
15         atEnd = true;
16     } else if( xName.endswith( "X" ) ) {
17         root = xName.drop_back();
18         capital = true;
19         atEnd = true;
20     } else if( xName.startswith( "x" ) ) {
21         root = xName.drop_front();
22         capital = false;
23         atEnd = false;
24     } else if( xName.startswith( "X" ) ) {
25         root = xName.drop_front();
26         capital = true;
27         atEnd = false;
28     } else {
29         valid = false;
30     }
31 }
32 
Match(StringRef name) const33 NameConvention::MatchResult NameConvention::Match( StringRef name ) const
34 {
35     if( name.empty() ) {
36         return None;
37     }
38 
39     StringRef Root = atEnd ? name.drop_back() : name.drop_front();
40     if( Root != root ) {
41         return None;
42     }
43 
44     char Dim = atEnd ? name.back() : name.front();
45     switch( Dim ) {
46         case 'x':
47         case 'X':
48             return XName;
49         case 'y':
50         case 'Y':
51             return YName;
52         case 'z':
53         case 'Z':
54             return ZName;
55         default:
56             return None;
57     }
58 }
59 
60 } // namespace cata
61 } // namespace tidy
62 } // namespace clang
63