Fix HTML links that contain file extensions
authorTeemu Murtola <teemu.murtola@gmail.com>
Thu, 10 Jul 2014 10:57:32 +0000 (13:57 +0300)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Fri, 11 Jul 2014 05:18:17 +0000 (07:18 +0200)
- 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
src/gromacs/utility/stringutil.cpp

index 30bf3ce3515c5efa9be8db74ffb0a7e44b98e583..745e0c74108edce1534e5cf8618825094548685d 100644 (file)
@@ -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();
 }
 
index 82bf0a39de7f6e0beefcab95af2349e280a0eab2..6104225d3f174876a601a25c5e3c0e4c2719ddc5 100644 (file)
@@ -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;