MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / MakeNameStyle

Function MakeNameStyle

CodeFormatCore/src/Config/LuaDiagnosticStyle.cpp:9–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7 }
8
9NameStyleRule MakeNameStyle(InfoNode n) {
10 if (n.IsString()) {
11 auto type = n.AsString();
12 if (type == "snake_case") {
13 return NameStyleRule(NameStyleType::SnakeCase);
14 } else if (type == "upper_snake_case") {
15 return NameStyleRule(NameStyleType::UpperSnakeCase);
16 } else if (type == "pascal_case") {
17 return NameStyleRule(NameStyleType::PascalCase);
18 } else if (type == "camel_case") {
19 return NameStyleRule(NameStyleType::CamelCase);
20 }
21
22 } else if (n.IsObject()) {
23 auto typeNode = n.GetValue("type");
24 if (typeNode.IsString()) {
25 auto type = typeNode.AsString();
26 if (type == "snake_case") {
27 return NameStyleRule(NameStyleType::SnakeCase);
28 } else if (type == "upper_snake_case") {
29 return NameStyleRule(NameStyleType::UpperSnakeCase);
30 } else if (type == "pascal_case") {
31 return NameStyleRule(NameStyleType::PascalCase);
32 } else if (type == "camel_case") {
33 return NameStyleRule(NameStyleType::CamelCase);
34 } else if (type == "ignore") {
35 auto paramNode = n.GetValue("param");
36 std::set<std::string> ignores;
37 if (paramNode.IsString()) {
38 ignores.insert(paramNode.AsString());
39 } else if (paramNode.IsArray()) {
40 auto arr = paramNode.AsArray();
41 for (auto item: arr) {
42 if (item.IsString()) {
43 ignores.insert(item.AsString());
44 }
45 }
46 }
47
48 return NameStyleRule(NameStyleType::Ignore, std::make_shared<IgnoreNameStyleData>(ignores));
49 } else if (type == "pattern") {
50 auto paramNode = n.GetValue("param");
51 if (paramNode.IsString()) {
52
53 auto patternData = std::make_shared<PatternNameStyleData>();
54 auto patternString = paramNode.AsString();
55 try {
56 patternData->Re = std::regex(patternString, std::regex_constants::ECMAScript);
57 patternData->PatternString = patternString;
58 for (auto pair: n.AsMap()) {
59 if (string_util::StartWith(pair.first, "$")) {
60 auto istr = pair.first.substr(1);
61 std::size_t groupId = std::stoull(istr);
62 auto rule = pair.second.AsString();
63
64 if (rule == "snake_case") {
65 patternData->GroupRules.emplace_back(groupId, NameStyleType::SnakeCase);
66 } else if (rule == "upper_snake_case") {

Callers 1

ParseTreeMethod · 0.85

Calls 9

NameStyleRuleClass · 0.85
IsStringMethod · 0.80
AsStringMethod · 0.80
IsObjectMethod · 0.80
GetValueMethod · 0.80
IsArrayMethod · 0.80
AsArrayMethod · 0.80
AsMapMethod · 0.80
insertMethod · 0.45

Tested by

no test coverage detected