module Potato
# Mixin module for helper methods we want to add to classes.
module Helpers
# Helpers for String.
module String
# Convert numeric and hexadecimal HTML entities to Unicode codepoints.
# @return [String]
def decode_entities
gsub(/(\d+);/){[$1.to_i].pack("U*")}.gsub(/([0-9a-fA-F]+);/){[$1.to_i(16)].pack("U*")}
end
# Convert Unicode codepoints to numeric HTML entities.
# @return [String]
def encode_entities
gsub(/([^ a-zA-Z0-9_.\-'",;!@#\$%^&\*\(\)\{\}\?\/\\<>=\+:])/u){"#{$1.unpack("U*")[0]};"}
end
# Convert IRC formatting to tags.
# @see Potato::DAmn::Client
# @return [String]
def to_tags
gsub(/\x02(.*?)\x0F/u, '\1').gsub(/\x16(.*?)\x0F/u, '\1').gsub(/\x1F(.*?)\x0F/u, '\1')
end
end
end
end
class String; include Potato::Helpers::String; end