Module: BlueFeather::Util
- Defined in:
- lib/bluefeather.rb
Constant Summary collapse
- HTML_ESC =
{ '&' => '&', '"' => '"', '<' => '<', '>' => '>' }
Class Method Summary collapse
- .change_kcode(kcode = nil) ⇒ Object
-
.escape_html(str) ⇒ Object
(Author: Minero Aoki).
- .generate_blank_string_io(encoding_base) ⇒ Object
Class Method Details
.change_kcode(kcode = nil) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/bluefeather.rb', line 170 def change_kcode(kcode = nil) if defined?(Encoding) then # ruby 1.9 later yield else # ruby 1.8 earlier original_kcode = $KCODE begin $KCODE = kcode if kcode yield ensure # recover $KCODE = original_kcode end end # if defined? end |
.escape_html(str) ⇒ Object
(Author: Minero Aoki)
155 156 157 158 |
# File 'lib/bluefeather.rb', line 155 def escape_html(str) table = HTML_ESC # optimize str.gsub(/[&"<>]/) {|s| table[s] } end |
.generate_blank_string_io(encoding_base) ⇒ Object
160 161 162 163 164 165 166 167 168 |
# File 'lib/bluefeather.rb', line 160 def generate_blank_string_io(encoding_base) io = StringIO.new if io.respond_to?(:set_encoding) then io.set_encoding(encoding_base.encoding) end return io end |