Remove extra newline from end of doxygen python \code command

Remove the extra newline at the end of translation of doxygen \code
\endcode command for Python.  Update test output accordingly.
This commit is contained in:
John McFarland 2019-05-25 13:40:59 -05:00
commit 321cb096a8
3 changed files with 7 additions and 5 deletions

View file

@ -50,7 +50,6 @@ Warning: This may not work as expected
.. code-block:: c++
int main() { while(true); }
}"""
)
comment_verifier.check(inspect.getdoc(doxygen_basic_translate.function5),

View file

@ -25,7 +25,6 @@ Author: Zubr
some test code
Conditional comment: SOMECONDITION
Some conditional comment
End of conditional comment.

View file

@ -495,7 +495,7 @@ void PyDocConverter::handleCode(DoxygenEntity &tag, std::string &translatedComme
// Try and remove leading newline, which is present for block \code
// command:
if (code[0] == '\n')
if ((! code.empty()) && code[0] == '\n')
code.erase(code.begin());
translatedComment += codeIndent;
@ -515,8 +515,12 @@ void PyDocConverter::handleCode(DoxygenEntity &tag, std::string &translatedComme
}
trimWhitespace(translatedComment);
if (*translatedComment.rbegin() != '\n')
translatedComment += '\n';
// For block commands, the translator adds the newline after
// \endcode, so try and compensate by removing the last newline from
// the code text:
if ((! translatedComment.empty()) && translatedComment[translatedComment.size()-1] == '\n')
translatedComment = translatedComment.substr(0, translatedComment.size()-1); // use translatedComment.pop_back() in C++ 11
}
void PyDocConverter::handlePlainString(DoxygenEntity &tag, std::string &translatedComment, const std::string &) {