From e9739f4be82ea11e6f411ef4776479b2f6fa6f09 Mon Sep 17 00:00:00 2001 From: Teemu Murtola Date: Thu, 10 Jul 2014 13:57:32 +0300 Subject: [PATCH] Fix HTML links that contain file extensions - Consider '-' and '_' as part of a word when replacing links, so that convert-tpr and make_ndx are considered single words, and the extensions there are not converted into links. - Do links.dat replacement before program links, so that the URL in the above program name links is not processed. Change-Id: I0ce204d3adedc56e57c1e1cd150a63d21c442eab --- src/gromacs/commandline/cmdlinehelpmodule.cpp | 2 +- src/gromacs/utility/stringutil.cpp | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/gromacs/commandline/cmdlinehelpmodule.cpp b/src/gromacs/commandline/cmdlinehelpmodule.cpp index 30bf3ce351..745e0c7410 100644 --- a/src/gromacs/commandline/cmdlinehelpmodule.cpp +++ b/src/gromacs/commandline/cmdlinehelpmodule.cpp @@ -549,7 +549,6 @@ class HelpExportHtml : public HelpExportInterface HelpExportHtml::HelpExportHtml(const CommandLineHelpModuleImpl &helpModule) : links_(eHelpOutputFormat_Html) { - initProgramLinks(&links_, helpModule); File linksFile("links.dat", "r"); std::string line; while (linksFile.readLine(&line)) @@ -557,6 +556,7 @@ HelpExportHtml::HelpExportHtml(const CommandLineHelpModuleImpl &helpModule) links_.addLink(line, "../online/" + line, line); } linksFile.close(); + initProgramLinks(&links_, helpModule); setupHeaderAndFooter(); } diff --git a/src/gromacs/utility/stringutil.cpp b/src/gromacs/utility/stringutil.cpp index 82bf0a39de..6104225d3f 100644 --- a/src/gromacs/utility/stringutil.cpp +++ b/src/gromacs/utility/stringutil.cpp @@ -174,6 +174,18 @@ std::string concatenateStrings(const char *const *sarray, size_t count) namespace { +/*! \brief + * Helper function to identify word boundaries for replaceAllWords(). + * + * \returns `true` if the character is considered part of a word. + * + * \ingroup module_utility + */ +bool isWordChar(char c) +{ + return std::isalnum(c) || c == '-' || c == '_'; +} + /*! \brief * Common implementation for string replacement functions. * @@ -201,8 +213,8 @@ replaceInternal(const std::string &input, const char *from, const char *to, size_t matchEnd = matchPos + matchLength; if (bWholeWords) { - if (!((matchPos == 0 || !std::isalnum(input[matchPos-1])) - && (matchEnd == input.length() || !std::isalnum(input[matchEnd])))) + if (!((matchPos == 0 || !isWordChar(input[matchPos-1])) + && (matchEnd == input.length() || !isWordChar(input[matchEnd])))) { matchPos = input.find(from, matchPos + 1); continue; -- 2.22.0