1#--
2# htmlutils.rb -- HTMLUtils Module
3#
4# Author: IPR -- Internet Programming with Ruby -- writers
5# Copyright (c) 2000, 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
6# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
7# reserved.
8#
9# $IPR: htmlutils.rb,v 1.7 2002/09/21 12:23:35 gotoyuzo Exp $
10
11module WEBrick
12  module HTMLUtils
13
14    ##
15    # Escapes &, ", > and < in +string+
16
17    def escape(string)
18      return "" unless string
19      str = string.b
20      str.gsub!(/&/n, '&amp;')
21      str.gsub!(/\"/n, '&quot;')
22      str.gsub!(/>/n, '&gt;')
23      str.gsub!(/</n, '&lt;')
24      str.force_encoding(string.encoding)
25    end
26    module_function :escape
27
28  end
29end
30