class String

Public Instance Methods

escape_glob() click to toggle source

escape [] and {} character for Dir.glob to use

# File lib/kamishibai/functions.rb, line 39
def escape_glob
        s = self.dup
        s.gsub(/([\[\]\{\}\*\?\\])/, '\\\\\1')
end
escape_glob!() click to toggle source

escape glob and overwite it

# File lib/kamishibai/functions.rb, line 45
def escape_glob!
        self.replace( self.escape_glob )
end
escape_html() click to toggle source

escape characters and make it html safe

# File lib/kamishibai/functions.rb, line 50
def escape_html
        s = self.dup

        for i in 32..255
                next if i == 35 # #
                next if i == 38 # &
                next if i == 59 # ;
                next if i >=  48 && i <=  57 # 0-9
                next if i >=  65 && i <=  90 # A-Z
                next if i >=  97 && i <= 122 # a-z
                next if i >= 127 && i <= 159 # not defined in html standards

                c = [i].pack('U')
                r = "\&\##{i.to_s}\;"
                s.gsub!(c, r) # replace char to html number
        end

        s
end
escape_html!() click to toggle source

escape characters and make it html safe and overwrite

# File lib/kamishibai/functions.rb, line 71
def escape_html!
        self.replace( self.escape_html )
end