96fd7fffb86e919a6a394250208c04bca67842da
tdreszer
  Tue Feb 8 12:38:25 2011 -0800
Added routine to strip html tags from text.  This shouuld be used on strings that become tooltip titles.
diff --git src/lib/htmshell.c src/lib/htmshell.c
index 409c397..735e556 100644
--- src/lib/htmshell.c
+++ src/lib/htmshell.c
@@ -112,30 +112,55 @@
 	    fputs(""", f);
 	    break;
 	default:
 	    fputc(c, f);
 	    break;
 	}
     }
 }
 
 void htmlTextOut(char *s)
 /* Print out string, if necessary replacing > with > and the like */
 {
 htmTextOut(stdout, s);
 }
 
+char *htmlTextStripTags(char *s)
+/* Returns a cloned string with all html tags stripped out */
+{
+if (s == NULL)
+    return NULL;
+char *scrubbed = needMem(strlen(s));
+char *from=s;
+char *to=scrubbed;
+while(*from!='\0')
+    {
+    if (*from == '<')
+        {
+        from++;
+        while (*from!='\0' && *from != '>')
+            from++;
+        if (*from == '\0')  // The last open tag was never closed!
+            break;
+        from++;
+        }
+    else
+        *to++ = *from++;
+    }
+return scrubbed;
+}
+
 char *htmlEncodeText(char *s,boolean tagsOkay)
 /* Returns a cloned string with quotes replaced by html codes.
    Changes ',",\n and if not tagsOkay >,<,& to code equivalents.
    This differs from cgiEncode as it handles text that will
    be displayed in an html page or tooltip style title.  */
 {
 int size = strlen(s) + 3; // Add some slop
 if(tagsOkay)
     size += countChars(s,'\n') * 4;
 else
     {
     size += countChars(s,'>' ) * 4;
     size += countChars(s,'<' ) * 4;
     size += countChars(s,'&' ) * 5;
     size += countChars(s,'\n') * 6;
@@ -152,31 +177,30 @@
     {
     strSwapStrs(cleanQuote, size,"&" ,"&amp;" ); //  '&' is not the start of a control char
     strSwapStrs(cleanQuote, size,">" ,"&gt;"  ); // '>' is not the close of a tag
     strSwapStrs(cleanQuote, size,"<" ,"&lt;"  ); // '<' is not the open of a tag
     if(cgiClientBrowser(NULL,NULL,NULL) == btFF)
         strSwapStrs(cleanQuote, size,"\n","&#124;"); // FF does not support!  Use "&#124;" for '|' instead
     else
         strSwapStrs(cleanQuote, size,"\n","&#x0A;"); // '\n' is supported on some browsers
     }
 strSwapStrs(cleanQuote, size,"\"","&quot;"); // Shield double quotes
 strSwapStrs(cleanQuote, size,"'" ,"&#39;" ); // Shield single quotes
 
 return cleanQuote;
 }
 
-
 char *htmlWarnStartPattern()
 /* Return starting pattern for warning message. */
 {
 return "<!-- HGERROR-START -->\n";
 }
 
 char *htmlWarnEndPattern()
 /* Return ending pattern for warning message. */
 {
 return "<!-- HGERROR-END -->\n";
 }
 
 void htmlWarnBoxSetup(FILE *f)
 /* Creates an invisible, empty warning box than can be filled with errors
  * and then made visible. */