method
check
v2_4_6 -
Show latest stable
- Class:
REXML::Text
check(string, pattern, doctype)public
check for illegal characters
# File lib/rexml/text.rb, line 130
def Text.check string, pattern, doctype
# illegal anywhere
if string !~ VALID_XML_CHARS
if String.method_defined? :encode
string.chars.each do |c|
case c.ord
when *VALID_CHAR
else
raise "Illegal character #{c.inspect} in raw string \"#{string}\""
end
end
else
string.scan(/[\x00-\x7F]|[\x80-\xBF][\xC0-\xF0]*|[\xC0-\xF0]/) do |c|
case c.unpack('U')
when *VALID_CHAR
else
raise "Illegal character #{c.inspect} in raw string \"#{string}\""
end
end
end
end
# context sensitive
string.scan(pattern) do
if $1[-1] != ;;
raise "Illegal character '#{$1}' in raw string \"#{string}\""
elsif $1[0] == &&
if $5 and $5[0] == ##
case ($5[1] == xx ? $5[2..-1].to_i(16) : $5[1..-1].to_i)
when *VALID_CHAR
else
raise "Illegal character '#{$1}' in raw string \"#{string}\""
end
# FIXME: below can't work but this needs API change.
# elsif @parent and $3 and !SUBSTITUTES.include?($1)
# if !doctype or !doctype.entities.has_key?($3)
# raise "Undeclared entity '#{$1}' in raw string \"#{string}\""
# end
end
end
end
end Related methods
- Instance methods
- <<
- <=>
- clone
- doctype
- empty?
- indent_text
- inspect
- node_type
- parent=
- to_s
- value
- value=
- wrap
- write
- write_with_substitution
- xpath
- Class methods
- check
- new
- Private methods
-
expand -
normalize -
read_with_substitution -
unnormalize -
clear_cache