in src/generic/htmlify.c [270:349]
int webDeHtmlify(ConvData * convData, Tcl_Obj * in, Tcl_Obj * out)
{
int length; /* length of input */
int pos = 0; /* actual position in string */
Tcl_UniChar *unic;
int plainfirst = 0;
int plainend = 0;
int err = 0; /* temporary use, may be removed */
if (in == NULL || out == NULL) {
return TCL_ERROR;
}
unic = Tcl_GetUnicode(in);
length = Tcl_GetCharLength(in);
if (length == 1) {
if ((unic[0] == '>') || (unic[pos] == '>')) {
/* nada */
return TCL_OK;
}
else {
Tcl_AppendUnicodeToObj(out, &unic[0], 1);
return TCL_OK;
}
}
while (pos < length) {
plainend = pos;
if (unic[pos] == '<') {
/* dump */
Tcl_AppendUnicodeToObj(out, &unic[plainfirst],
plainend - plainfirst);
/* ---------------------------------------------------------------------
* we're in a tag, thus we skip everything
* --------------------------------------------------------------------*/
HANDLE_TAG(unic, length, out, pos, err);
plainfirst = pos + 1;
}
else if (unic[pos] == '>') {
/* dump */
Tcl_AppendUnicodeToObj(out, &unic[plainfirst],
plainend - plainfirst);
/* syntax error, too many closing '>' */
Tcl_AppendUnicodeToObj(out, &(unic[pos]), 1);
/*Tcl_SetStringObj(out,"Error: web::dehtmlify, unbalanced '>'",-1); */
plainfirst = pos + 1;
}
else if (unic[pos] == '&') {
/* dump */
Tcl_AppendUnicodeToObj(out, &unic[plainfirst],
plainend - plainfirst);
/*
* it's an entity
*/
HANDLE_ENTITY(convData, unic, length, out, pos, err);
plainfirst = pos + 1;
}
/* ------------------------------------------------------------------------
* search on
* ----------------------------------------------------------------------*/
pos++;
}
/* final dump */
if (plainend >= plainfirst && plainend > 0) {
Tcl_AppendUnicodeToObj(out, &unic[plainfirst],
plainend - plainfirst + 1);
}
return TCL_OK;
}