diff --git a/Examples/test-suite/doxygen_misc_constructs.h b/Examples/test-suite/doxygen_misc_constructs.h index d677dc3d3..7782b532f 100644 --- a/Examples/test-suite/doxygen_misc_constructs.h +++ b/Examples/test-suite/doxygen_misc_constructs.h @@ -91,4 +91,6 @@ void backslashC() void cycle(int id, char *fileName) {} +/// This doc comment ends with a quote: "and that's ok" +void doc_ends_with_quote() {} diff --git a/Examples/test-suite/java/doxygen_misc_constructs_runme.java b/Examples/test-suite/java/doxygen_misc_constructs_runme.java index b1f4e2ef5..ca4b06b55 100644 --- a/Examples/test-suite/java/doxygen_misc_constructs_runme.java +++ b/Examples/test-suite/java/doxygen_misc_constructs_runme.java @@ -185,6 +185,8 @@ public class doxygen_misc_constructs_runme { "\n" + " @param fileName name of the log file\n"); + wantedComments.put("doxygen_misc_constructs.doxygen_misc_constructs.doc_ends_with_quote()", + "This doc comment ends with a quote: \"and that's ok\""); // and ask the parser to check comments for us System.exit(CommentParser.check(wantedComments)); diff --git a/Examples/test-suite/python/doxygen_misc_constructs_runme.py b/Examples/test-suite/python/doxygen_misc_constructs_runme.py index c0b5c1620..5655b2cef 100644 --- a/Examples/test-suite/python/doxygen_misc_constructs_runme.py +++ b/Examples/test-suite/python/doxygen_misc_constructs_runme.py @@ -131,3 +131,7 @@ Spaces at the start of line should be taken into account: :type fileName: string :param fileName: name of the log file""" ); + +comment_verifier.check(inspect.getdoc(doxygen_misc_constructs.doc_ends_with_quote), + r'''This doc comment ends with a quote: "and that's ok"''' +); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index f6b47be24..a4ac11811 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -1571,7 +1571,8 @@ public: String *docstring(Node *n, autodoc_t ad_type, const String *indent, bool low_level = false) { String *docstr = build_combined_docstring(n, ad_type, indent, low_level); - if (!Len(docstr)) + const int len = Len(docstr); + if (!len) return docstr; // Notice that all comments are created as raw strings (prefix "r"), @@ -1584,9 +1585,22 @@ public: // escape '\x'. '\' may additionally appear in verbatim or htmlonly sections // of doxygen doc, Latex expressions, ... String *doc = NewString(""); - Append(doc, "r\"\"\""); + + // Determine which kind of quotes to use as delimiters: for single line + // strings we can avoid problems with having a quote as the last character + // of the docstring by using different kind of quotes as delimiters. For + // multi-line strings this problem doesn't arise, as we always have a new + // line or spaces at the end of it, but it still does no harm to do it for + // them too. + // + // Note: we use double quotes by default, i.e. if there is no reason to + // prefer using single ones, for consistency with the older SWIG versions. + const bool useSingleQuotes = (Char(docstr))[len - 1] == '"'; + + Append(doc, useSingleQuotes ? "r'''" : "r\"\"\""); + Append(doc, docstr); - Append(doc, "\"\"\""); + Append(doc, useSingleQuotes ? "'''" : "\"\"\""); Delete(docstr); return doc;