Sub HtmlDecoder(encoded As String) As String
Dim sb As StringBuilder
sb.Initialize
Dim xmlEntities As Map = CreateMap("quot": QUOTE, "lt": "<", "gt": ">", "amp": "&")
Dim m As Matcher = Regex.Matcher("&(#\d+|quot|lt|gt|amp);", encoded)
Dim index As Int
Do While m.Find
sb.Append(encoded.SubString2(index, m.GetStart(0)))
index = m.GetEnd(0)
If xmlEntities.ContainsKey(m.Group(1)) Then
sb.Append(xmlEntities.Get(m.Group(1)))
Else
Dim rawCodepoint As String = m.Group(1).SubString(1)
If IsNumber(rawCodepoint) Then
sb.Append(Chr(rawCodepoint))
Else
sb.Append(m.Match)
End If
End If
Loop
If index < encoded.Length Then sb.Append(encoded.SubString(index))
Return sb.ToString
End Sub