From 976b43426305bae21d0b29adf6f144772f29666a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 3 Jan 2016 18:34:27 +0300 Subject: Add check for same number of spaces at start of line (po files). --- src/rules/po.cpp | 27 +++++++++++++++++++++++++-- tests/testreport.txt | 3 ++- tests/testsrc/bad/uk.po | 5 ++--- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/rules/po.cpp b/src/rules/po.cpp index d600d19..edfb787 100644 --- a/src/rules/po.cpp +++ b/src/rules/po.cpp @@ -28,6 +28,17 @@ bool skipOneCheck(false); std::string msgId; std::string msgStr; +static int countStartSpaces(const std::string &str) +{ + const int sz = str.size(); + for (int f = 0; f < sz; f ++) + { + if (str[f] != ' ') + return f; + } + return -1; +} + static void processMessage(RuleBase *const rule) { // rule->print(std::string("pair: ").append(msgId).append( @@ -73,6 +84,7 @@ static void processMessage(RuleBase *const rule) if (name.find("po/unused/") != std::string::npos) return; + bool isError(false); if (eId == '.' || eId == ',' || eId == '!' || @@ -86,7 +98,10 @@ static void processMessage(RuleBase *const rule) eId == ' ') { if (eId != eStr) + { rule->print("Wrong character at end of translation line."); + isError = true; + } } if (sId == '.' || sId == ',' || @@ -101,13 +116,21 @@ static void processMessage(RuleBase *const rule) sId == ' ') { if (sId != sStr) + { rule->print("Wrong character at start of translation line."); + isError = true; + } } - if (msgId.find("###") != std::string::npos - && msgStr.find("###") == std::string::npos) + if (msgId.find("###") != std::string::npos && + msgStr.find("###") == std::string::npos) { rule->print("Missing ### in translation."); } + if (isError == false) + { + if (countStartSpaces(msgId) != countStartSpaces(msgStr)) + rule->print("Wrong number of spaces at start of translation line."); + } /* if (msgId.find("\\n") != std::string::npos) { diff --git a/tests/testreport.txt b/tests/testreport.txt index 2a620a7..94223aa 100644 --- a/tests/testreport.txt +++ b/tests/testreport.txt @@ -44,7 +44,8 @@ [testsrc/bad/packet.cpp:25]: V012: Wrong output packet creation. Must be 'createOutPacket(CMSG...' [testsrc/bad/uk.po:2257]: V010: Wrong character at end of translation line. [testsrc/bad/uk.po:2269]: V010: Wrong character at start of translation line. -[testsrc/bad/uk.po:3712]: V010: Wrong character at end of translation line. +[testsrc/bad/uk.po:2535]: V010: Wrong number of spaces at start of translation line. +[testsrc/bad/uk.po:3711]: V010: Wrong character at end of translation line. [testsrc/bad/virtual1.cpp:33]: V013: Keywords virtual is useless if used with override or final [testsrc/bad/virtual1.cpp:36]: V013: Keywords virtual is useless if used with override or final [testsrc/bad/virtual1.h:31]: V013: Keywords virtual is useless if used with override or final diff --git a/tests/testsrc/bad/uk.po b/tests/testsrc/bad/uk.po index 1aef374..9f6c414 100644 --- a/tests/testsrc/bad/uk.po +++ b/tests/testsrc/bad/uk.po @@ -2530,9 +2530,8 @@ msgid "Options:" msgstr "Параметри:" #: src/main.cpp:45 -#, fuzzy -msgid " -v --version : Display the version" -msgstr " -h --help : показати ще раз цю довідку" +msgid " -v --version : Display the version" +msgstr " -v --version : показати ще раз цю довідку" #: src/main.cpp:46 #, fuzzy -- cgit v1.2.3-70-g09d2