MCPcopy Create free account
hub / github.com/bumptop/BumpTop / WarnUnwrappedStringLitteral

Function WarnUnwrappedStringLitteral

trunk/win/Source/LUpdateString/cpp.cpp:743–808  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

741unsigned int stringCount = 0;
742
743static void WarnUnwrappedStringLitteral()
744{
745 static const QChar chNewline(QLatin1Char('\n'));
746 static const QString strEquals(QLatin1String("==")), strNotEquals(QLatin1String("!="));
747 static const QString strInsert(QLatin1String("insert(\""));
748 static const QString immediateLeftToExclude [] =
749 {
750 QLatin1String("insert(\""), QLatin1String("[\""), QLatin1String("/ \"") /*path join*/, QLatin1String("QT_NT(L\"")/*matchString doesn't match wide string*/,
751 QLatin1String("Message(\""), QLatin1String("printTimedUnique(\""), QLatin1String("printUniqueError(\""), QLatin1String("printUnique(\""),
752
753 };
754
755 static const QString containsToExclude [] =
756 {
757 QLatin1String("QT_TR_NOO"), QLatin1String("QT_TRANSLATE_NOOP"), //it's assumed that if the line contains these then other strings shouldn't be translated
758 QLatin1String("puts"), QLatin1String("printf"), QLatin1String("wprintf"), QLatin1String("consoleWrite"),
759 QLatin1String("LOG("), QLatin1String("LOG_START("), QLatin1String("LOG_FINISH("),
760 QLatin1String("throw ")/*some sentences might have throw*/,
761 QLatin1String("TEST_LOG("), QLatin1String(" << "),
762 QLatin1String("dismiss(\""), QLatin1String("make_file"),
763 QLatin1String("contains(\""), QLatin1String("value(\""), QLatin1String("getValue"), QLatin1String("getString"), QLatin1String("isMember(\""),
764 QLatin1String("setTextureID"), QLatin1String("texMgr->"), QLatin1String("profiler->"),
765 };
766
767 /*QString lineText = yyInStr;
768 for (int i = 1; i < yyLineNo; i++)
769 lineText = lineText.mid(lineText.indexOf(QLatin1String("\n")) + 1);
770 lineText = lineText.mid(0, lineText.indexOf(QLatin1String("\n")));*/
771 //QString lineText = QLatin1String("");
772 for (int i = lastLineNumber; i < yyLineNo; i++)
773 remainingFileString = remainingFileString.mid(remainingFileString.indexOf(chNewline) + 1);
774 QString lineText = remainingFileString.mid(0, remainingFileString.indexOf(chNewline));;
775 lastLineNumber = yyLineNo;
776
777 for (unsigned int i = 0; i < _countof(containsToExclude); i++)
778 {
779 if (lineText.contains(containsToExclude[i]))
780 return;
781 }
782
783 if (yyString.size() <= 2)
784 return;
785
786 int stringIndex = lineText.indexOf(yyString);
787 int strEqualsIndex = lineText.indexOf(strEquals);
788 int strNotEqualsIndex = lineText.indexOf(strNotEquals);
789
790 if (strEqualsIndex > -1 || strNotEqualsIndex > -1)
791 return; //TODO: check if string is actually the comparison operand
792
793 //some immdiate left occurs more than once per line, so second fails
794 for (unsigned int i = 0; i < _countof(immediateLeftToExclude); i++)
795 {
796 int index = lineText.indexOf(immediateLeftToExclude[i]);
797 if (index > -1)
798 if (index + immediateLeftToExclude[i].size() == stringIndex)
799 return;
800 }

Callers 1

parseFunction · 0.85

Calls 6

QLatin1CharClass · 0.85
QLatin1StringClass · 0.85
midMethod · 0.45
indexOfMethod · 0.45
containsMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected