Fix generated Python code for Doxygen comments ending with quote
Single-line Doxygen comments ending with a double quote resulted in syntactically-invalid Python docstrings in the output, so use triple single quotes as delimiters in this case to avoid it.
This commit is contained in:
parent
3a329566f8
commit
b81cd1bdab
4 changed files with 25 additions and 3 deletions
|
|
@ -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() {}
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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"'''
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue