From 0091365325a1b1608d4e8dac4b3d0756bd14d6f8 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 25 May 2014 13:06:38 +0300 Subject: Check align in constructors initialisation list. --- src/rules/constructor.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/src/rules/constructor.cpp b/src/rules/constructor.cpp index e9acb1b..8777ce1 100644 --- a/src/rules/constructor.cpp +++ b/src/rules/constructor.cpp @@ -22,8 +22,13 @@ registerRuleExt(constructor, "006", "(.+)[.](cpp|h)") +bool foundConstructor(false); +int align = 0; + startRule(constructor) { + foundConstructor = false; + align = 0; } endRule(constructor) @@ -32,6 +37,53 @@ endRule(constructor) parseLineRule(constructor) { - if (strEndWith(data, "):")) - print("Add space between constructor and \":\"."); + if (foundConstructor) + { + if (data.size() > 0 && data[0] == '#') + return; + + int align2 = 0; + const size_t sz = data.size(); + for (size_t f = 0; f < sz; f ++) + { + if (data[f] != ' ') + break; + align2 ++; + } + if (align2 != align + 4) + print("Wrong align in initialisation list."); + + foundConstructor = false; + } + else + { + if (data.find("(") != std::string::npos) + { + align = 0 ; + const size_t sz = data.size(); + for (size_t f = 0; f < sz; f ++) + { + if (data[f] != ' ') + break; + align ++; + } + } + if (strEndWith(data, "):")) + { + print("Add space between constructor and \":\"."); + if (data.find("<") == std::string::npos + && data.find("?") == std::string::npos) + { + foundConstructor = true; + } + } + else if (strEndWith(data, ") :")) + { + if (data.find("<") == std::string::npos + && data.find("?") == std::string::npos) + { + foundConstructor = true; + } + } + } } -- cgit v1.2.3-60-g2f50