Method: Irc::Utils.decode_html_entities

Defined in:
lib/rbot/core/utils/utils.rb

.decode_html_entities(str) ⇒ Object

Decode HTML entities in the String str, using HTMLEntities if the package was found, or UNESCAPE_TABLE otherwise.



335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/rbot/core/utils/utils.rb', line 335

def Utils.decode_html_entities(str)
  if defined? ::HTMLEntities
    return HTMLEntities.decode_entities(str)
  else
    str.gsub(/(&(.+?);)/) {
      symbol = $2
      # remove the 0-paddng from unicode integers
      if symbol =~ /^#(\d+)$/
        symbol = $1.to_i.to_s
      end

      # output the symbol's irc-translated character, or a * if it's unknown
      UNESCAPE_TABLE[symbol] || (symbol.match(/^\d+$/) ? [symbol.to_i].pack("U") : '*')
    }
  end
end