File: cdata.rb

package info (click to toggle)
librexml-ruby 1.2.5-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 792 kB
  • ctags: 655
  • sloc: ruby: 3,778; xml: 1,609; java: 109; makefile: 43
file content (38 lines) | stat: -rw-r--r-- 825 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require "rexml/text"

module REXML
	class CData < Text
		START = '<![CDATA['
		START_RE = /\A<!\[CDATA\[/u
		STOP = ']]>'
		PATTERN = /#{Regexp.escape(START)}(.*?)#{Regexp.escape(STOP)}/um

		##
		#	Constructor.  CData is data between <![CDATA[ ... ]]>
		#	@param first If a Source, then CData is parsed directly from the
		#	source.  Otherwise, all arguments are passed to the superclass
		#	constructor, Text.
		def initialize( first, whitespace=nil, parent=nil )
			super( first, whitespace, parent, PATTERN, true )
		end

		def clone
			CData.new self
		end

		def to_s
			@string
		end

		def write( output, indent )
			indent( output, indent )
			output << START
			output << @string
			output << STOP
		end

		def CData.parse_stream(source, listener)
			listener.cdata(source.match( PATTERN, true )[1])
		end
	end
end