Hey, I've been doing a bit of a code tidy-up/speed-up recently, and I spent a minute with this (excellent) function. I figured I'd post the final result here since the modifications - mostly cutting back on the number of times values are stored to temporary variables - made UnHTM() a full 2x faster. (It's still functionally identical).
Also it's now in my coding style, but, well, that was kind of the whole point. sorry!
Code:
UnHTM(HTM) ;www.autohotkey.com/forum/topic51342.html
{
Static HT
If (HT = "")
HT := "ááââ´´ææàà&ååããää&bdquo„¦¦&bull•ç縸¢¢&circˆ©©¤¤&dagger†&dagger‡°°÷÷ééêêèèððëë&euro€&fnofƒ½½¼¼¾¾>>&hellip…ííîî¡¡ìì¿¿ïï««&ldquo“&lsaquo‹&lsquo‘<<¯¯&mdash—µµ··  &ndash–¬¬ññóóôô&oeligœòòªªººøøõõöö¶¶&permil‰±±££"""»»&rdquo”®®&rsaquo›&rsquo’&sbquo‚&scaronš§§­ ¹¹²²³³ßßþþ&tilde˜××&trade™úúûûùù¨¨üüýý¥¥ÿÿ"
HTM := RegExReplace(HTM, "<[^>]+>")
Loop, Parse, HTM, &`;
If !((A_Index & 1) or InStr(R, "&" A_LoopField ";", True))
R .= "&" A_LoopField ";"
StringTrimRight, R, R, 1
Loop, Parse, R, `;
If InStr(HT, A_LoopField)
StringReplace, HTM, HTM, %A_LoopField%;, % SubStr(HT, InStr(HT, A_LoopField) + StrLen(A_LoopField), 1), All
Else If (SubStr(A_LoopField, 2, 1) = "#")
StringReplace, HTM, HTM, %A_LoopField%;, % Chr(((SubStr(A_LoopField, 3, 1) = "x") ? 0 : "") SubStr(A_LoopField, 3)), All
Return RegExMatch(HTM, "\S") ? RegExReplace(HTM, "^\s*([\s\S]*\S)\s*$", "$1") : ""
}
_________________
★★★ Email me at berban at aim full stop com
★★★