Index: htmldocvisitor.cpp
===================================================================
--- htmldocvisitor.cpp	(revision 833)
+++ htmldocvisitor.cpp	(working copy)
@@ -34,30 +34,36 @@
 static const int NUM_HTML_LIST_TYPES = 4;
 static const char types[][NUM_HTML_LIST_TYPES] = {"1", "a", "i", "A"};
 
+
+static inline char toHexHelper(char c)
+{
+    static const char hexnumbers[] = "0123456789ABCDEF";
+    return hexnumbers[c & 0xf];
+}
+
 static QCString convertIndexWordToAnchor(const QString &word)
 {
-  static char hex[] = "0123456789abcdef";
-  uint i;
   QCString result;
-  for (i=0;i<word.length();i++)
-  {
-    int c = word.at(i);
-    if (isId(c))
-    {
-      result+=c;
+  const char *str = word.data();
+  unsigned char c;
+  while (c = *str++) {
+    if ((c >= 0x61 && c <= 0x7A) // ALPHA
+         || (c >= 0x41 && c <= 0x5A) // ALPHA
+         || (c >= 0x30 && c <= 0x39) // DIGIT
+         || c == 0x2D // -
+         || c == 0x2E // .
+         || c == 0x5F // _
+         || c == 0x7E // ~
+       )
+      result += c;
+    else {
+      char enc[4];
+      enc[0] = '%';
+      enc[1] = toHexHelper((c & 0xf0) >> 4);
+      enc[2] = toHexHelper(c & 0xf);
+      enc[3] = 0;
+      result += enc;
     }
-    else if (isspace(c))
-    {
-      result+="_";
-    }
-    else
-    {
-      char cs[3];
-      cs[0]=hex[c>>4];
-      cs[1]=hex[c&0xf];
-      cs[2]=0;
-      result+=cs;
-    }
   }
   return result;
 }
