Module: XMLScan::XMLChar

Included in:
XMLScan::XMLScanner::StrictChar
Defined in:
lib/xmlscan/xmlchar.rb

Constant Summary collapse

CharPattern =
/\\A[\P{C}\t\n\r]*\\z/u
NotCharPattern =
/[^\P{C}\t\n\r]/u
NmtokenPattern =
/\\A[\p{Alnum}]+\z/u
NotNameCharPattern =
/[^\p{Alnum}}]/u
NamePattern =
/\A[\:\_\p{Letter}][\:\_\-\.\p{Alnum}]*\z/u

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.valid_char?(code) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
# File 'lib/xmlscan/xmlchar.rb', line 27

def valid_char?(code)
  return false if code > 0x10ffff
  NotCharPattern !~ [code].pack('U')
end

.valid_chardata?(str) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/xmlscan/xmlchar.rb', line 32

def valid_chardata?(str)
  NotCharPattern !~ str
end

.valid_encoding?(str) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
# File 'lib/xmlscan/xmlchar.rb', line 59

def valid_encoding?(str)
  if /\A[A-Za-z]([\-A-Za-z0-9._])*\z/u =~ str then
    true
  else
    false
  end
end

.valid_name?(str) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/xmlscan/xmlchar.rb', line 40

def valid_name?(str)
  not NamePattern !~ str
end

.valid_nmtoken?(str) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/xmlscan/xmlchar.rb', line 36

def valid_nmtoken?(str)
  NotNameCharPattern !~ str
end

.valid_version?(str) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/xmlscan/xmlchar.rb', line 53

def valid_version?(str)
  /[^\-a-zA-Z0-9_.:]/u !~ str
end

Instance Method Details

#valid_pubid?(str) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/xmlscan/xmlchar.rb', line 48

def valid_pubid?(str)
  /[^\- \r\na-zA-Z0-9'()+,.\/:=?;!*#\@$_%]/u !~ str
end