in src/generic/htmlify.c [386:467]
int removeHtmlComments(Tcl_Interp * interp, Tcl_Obj * in, Tcl_Obj * res)
{
int len = 0;
TCLCONST char *utf = NULL;
TCLCONST char *cmtopen = NULL;
TCLCONST char *cmtclose = NULL;
TCLCONST char *next1 = NULL;
TCLCONST char *next2 = NULL;
TCLCONST char *next3 = NULL;
if ((in == NULL) || (res == NULL))
return TCL_ERROR;
utf = Tcl_GetStringFromObj(in, &len);
if (len == 0)
return TCL_OK;
/* --------------------------------------------------------------------------
* fast forward to first "<"
* ----------------------------------------------------------------------- */
while ((cmtopen = Tcl_UtfFindFirst(utf, '<')) != NULL) {
next1 = NULL;
next2 = NULL;
next3 = NULL;
next1 = Tcl_UtfNext(cmtopen);
if (next1 != NULL)
next2 = Tcl_UtfNext(next1);
if (next2 != NULL)
next3 = Tcl_UtfNext(next2);
if (next1[0] == '!') {
/* ----------------------------------------------------------------------
* starts like a comment.
* ------------------------------------------------------------------- */
if ((next2[0] == '-') && (next3[0] == '-')) {
Tcl_AppendToObj(res, utf, cmtopen - utf);
cmtclose = findHtmlCmtClose(Tcl_UtfNext(next3));
if (cmtclose == NULL) {
Tcl_AppendToObj(res, cmtopen, -1);
LOG_MSG(interp, WRITE_LOG, __FILE__, __LINE__,
"removeHtmlComments", WEBLOG_INFO,
"end of string encountered while searching for comment-end",
NULL);
return TCL_OK;
}
else {
utf = Tcl_UtfNext(cmtclose);
}
}
else {
if (next2[0] == '>') {
Tcl_AppendToObj(res, utf, cmtopen - utf);
utf = next3;
}
else {
Tcl_AppendToObj(res, utf, cmtopen - utf + 1);
utf = next1;
}
}
}
else {
/* ----------------------------------------------------------------------
* not a comment. proceed.
* ------------------------------------------------------------------- */
Tcl_AppendToObj(res, utf, cmtopen - utf + 1);
utf = next1;
}
}
/* ------------------------------------------------------------------------
* append rest
* --------------------------------------------------------------------- */
if (utf != NULL)
Tcl_AppendToObj(res, utf, -1);
return TCL_OK;
}