summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-05-25 13:06:38 +0300
committerAndrei Karas <akaras@inbox.ru>2014-05-25 13:06:38 +0300
commit0091365325a1b1608d4e8dac4b3d0756bd14d6f8 (patch)
treea9fa6c80e4912000a23060725c72b8b97c2394bd
parent934ec27a783a7ad02a078160c1010a6d443b3437 (diff)
downloadmplint-0091365325a1b1608d4e8dac4b3d0756bd14d6f8.tar.gz
mplint-0091365325a1b1608d4e8dac4b3d0756bd14d6f8.tar.bz2
mplint-0091365325a1b1608d4e8dac4b3d0756bd14d6f8.tar.xz
mplint-0091365325a1b1608d4e8dac4b3d0756bd14d6f8.zip
Check align in constructors initialisation list.
-rw-r--r--src/rules/constructor.cpp56
1 files 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;
+ }
+ }
+ }
}