It's in the title.
I have an idea on how to do it, but it's a really long one that I don't want to write considering the fact that I have approx 1000 more lines of code to do before a release is made.
I was going to findtext each < and > and check if it is in the approved tags list.
mob/proc/removeTags(var/tx, var/list/tags) I did that last night. My way versus your way, which one would be more beneficial from your perspective for a text that has a limit of 5000 characters? I'm trying to condense codes and processing time as much as possible. |
Dang you Xirre. You never message me when it comes to these types of questions. The simple ones :p..
The best method I know of is to use findtext(). By doing so, you will only examine the <'s in the string, and will stop once done. Therefore, by doing so you could replace the <'s in a 500 length text, and only have a loop ran twice. Example of mentioned method: var/allowedTags=list("<a","<b","<i","</i","</b","</a")<br/"> As for whether or not it would be best to manipulate a string alone or to use html_encode(), I am not entirely sure. Either way has it's potential usefulness. However, as Nadrew said, by allow blocked tags through html_encode(), you would essentially cut back on CPU usage, because you are likely to disallow more than you allow. |
I usually do it backwards, I'll html_encode() the string, then go through allowed tags and replace the encoded version of the html with the non-encoded version. It's a whole lot easier to include tags you want than to exclude the ones you don't want -- I imagine the ones you don't want outweigh the ones you do by a bit.