From 758ca4c4d5e655dd1fa0da32092b498b97f2f095 Mon Sep 17 00:00:00 2001 From: Topi Reinio Date: Thu, 16 Mar 2023 19:42:17 +0000 Subject: qdoc: C++ marker: Allow single quote as a separator in integer literals Since C++14, single quotes can appear in integer literals as separators to improve readability. When quoting a file that contains such a literal, QDoc interpreted the single quote as a delimiter for a char, and kept reading ahead for the closing quote. This interfered with correct marking up of C++ code and ultimately caused a warning: (qdoc) warning: Something is wrong with qdoc's handling of marked code as the plain code and marked-up code end up having different number of lines. Fixes: QTBUG-111973 Change-Id: Icd2d95973f9cee72eb1c9e3f2d79df0af643dbaa Reviewed-by: Paul Wicking (cherry picked from commit f47a4b17f778e790f9713c9e34ff5919861f49d5) Reviewed-by: Qt Cherry-pick Bot --- src/qdoc/cppcodemarker.cpp | 2 +- .../expected_output/examples-manifest.xml | 1 + .../expected_output/test-demos-demo-example.html | 23 ++++++++++++++++++++++ .../qdoc/generatedoutput/expected_output/test.qhp | 2 ++ .../testdata/examples/demos/demo/demo.cpp | 11 +++++++++++ .../testdata/examples/demos/demo/doc/src/demo.qdoc | 2 ++ .../qdoc/generatedoutput/tst_generatedoutput.cpp | 1 + 7 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/auto/qdoc/generatedoutput/expected_output/test-demos-demo-example.html create mode 100644 tests/auto/qdoc/generatedoutput/testdata/examples/demos/demo/demo.cpp diff --git a/src/qdoc/cppcodemarker.cpp b/src/qdoc/cppcodemarker.cpp index 7d4e8c4ed..32b14d24b 100644 --- a/src/qdoc/cppcodemarker.cpp +++ b/src/qdoc/cppcodemarker.cpp @@ -430,7 +430,7 @@ QString CppCodeMarker::addMarkUp(const QString &in, const Node * /* relative */, do { finish = i; readChar(); - } while (!atEOF && (ch.isLetterOrNumber() || ch == '.')); + } while (!atEOF && (ch.isLetterOrNumber() || ch == '.' || ch == '\'')); tag = QStringLiteral("number"); } else { switch (ch.unicode()) { diff --git a/tests/auto/qdoc/generatedoutput/expected_output/examples-manifest.xml b/tests/auto/qdoc/generatedoutput/expected_output/examples-manifest.xml index 0a32be836..563e3c5a3 100644 --- a/tests/auto/qdoc/generatedoutput/expected_output/examples-manifest.xml +++ b/tests/auto/qdoc/generatedoutput/expected_output/examples-manifest.xml @@ -9,6 +9,7 @@ test + test/demos/demo/demo.cpp diff --git a/tests/auto/qdoc/generatedoutput/expected_output/test-demos-demo-example.html b/tests/auto/qdoc/generatedoutput/expected_output/test-demos-demo-example.html new file mode 100644 index 000000000..c29408d19 --- /dev/null +++ b/tests/auto/qdoc/generatedoutput/expected_output/test-demos-demo-example.html @@ -0,0 +1,23 @@ + + + + + + Demo | Test 0.0.1 + + + +

Demo

+ +
+

    if (n > 1'000)
+        return true;
+

Files:

+ +
+ + + diff --git a/tests/auto/qdoc/generatedoutput/expected_output/test.qhp b/tests/auto/qdoc/generatedoutput/expected_output/test.qhp index 417f5a7fb..7ef863788 100644 --- a/tests/auto/qdoc/generatedoutput/expected_output/test.qhp +++ b/tests/auto/qdoc/generatedoutput/expected_output/test.qhp @@ -195,6 +195,8 @@ test-componentset-progressbar-qml.html test-componentset-switch-qml.html test-componentset-tabwidget-qml.html + test-demos-demo-demo-cpp.html + test-demos-demo-demo-pro.html test-demos-demo-example.html test-demos-hidden-example.html test-empty-qmlmodule.html diff --git a/tests/auto/qdoc/generatedoutput/testdata/examples/demos/demo/demo.cpp b/tests/auto/qdoc/generatedoutput/testdata/examples/demos/demo/demo.cpp new file mode 100644 index 000000000..906c6292f --- /dev/null +++ b/tests/auto/qdoc/generatedoutput/testdata/examples/demos/demo/demo.cpp @@ -0,0 +1,11 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +bool isOverThousand(int n) +{ +//! [integer literal with separator] + if (n > 1'000) + return true; +//! [integer literal with separator] + return false; +} diff --git a/tests/auto/qdoc/generatedoutput/testdata/examples/demos/demo/doc/src/demo.qdoc b/tests/auto/qdoc/generatedoutput/testdata/examples/demos/demo/doc/src/demo.qdoc index 82f3352c2..21ebc5588 100644 --- a/tests/auto/qdoc/generatedoutput/testdata/examples/demos/demo/doc/src/demo.qdoc +++ b/tests/auto/qdoc/generatedoutput/testdata/examples/demos/demo/doc/src/demo.qdoc @@ -6,4 +6,6 @@ \title Demo \image leonardo-da-vinci.png //! Icon made by Smashicons from www.flaticon.com + + \snippet demos/demo/demo.cpp integer literal with separator */ diff --git a/tests/auto/qdoc/generatedoutput/tst_generatedoutput.cpp b/tests/auto/qdoc/generatedoutput/tst_generatedoutput.cpp index 5c013639a..e8aadeffd 100644 --- a/tests/auto/qdoc/generatedoutput/tst_generatedoutput.cpp +++ b/tests/auto/qdoc/generatedoutput/tst_generatedoutput.cpp @@ -352,6 +352,7 @@ void tst_generatedOutput::examplesManifestXmlAndQhp() { testAndCompare("testdata/configs/examples-qhp.qdocconf", "examples-manifest.xml " + "test-demos-demo-example.html " "test.qhp"); } -- cgit v1.2.1