2003-06-09 21:31:01 -04:00
|
|
|
require 'rexml/encoding'
|
|
|
|
|
|
|
|
module REXML
|
|
|
|
# Generates Source-s. USE THIS CLASS.
|
|
|
|
class SourceFactory
|
|
|
|
# Generates a Source object
|
|
|
|
# @param arg Either a String, or an IO
|
|
|
|
# @return a Source, or nil if a bad argument was given
|
Merged from REXML main repository:
Fixes ticket:68.
NOTE that this involves an API change! Entity declarations in the doctype
now generate events that carry two, not one, arguments.
Implements ticket:15, using gwrite's suggestion. This allows Element to be
subclassed.
Two unrelated changes, because subversion is retarded and doesn't do
block-level commits:
1) Fixed a typo bug in previous change for ticket:15
2) Fixed namespaces handling in XPath and element.
***** Note that this is an API change!!! *****
Element.namespaces() now returns a hash of namespace mappings which are
relevant for that node.
Fixes a bug in multiple decodings
The changeset 1230:1231 was bad. The default behavior is *not* to use the
native REXML encodings by default, but rather to use ICONV by default. I know
that this will piss some people off, but defaulting to the pure Ruby version
isn't the correct solution, and it breaks other encodings, so I've reverted it.
* Fixes ticket:61 (xpath_parser)
* Fixes ticket:63 (UTF-16; UNILE decoding was bad)
* Cleans up some tests, removing opportunities for test corruption
* Improves parsing error messages a little
* Adds the ability to override the encoding detection in Source construction
* Fixes an edge case in Functions::string, where document nodes weren't
correctly converted
* Fixes Functions::string() for Element and Document nodes
* Fixes some problems in entity handling
Addresses ticket:66
Fixes ticket:71
Addresses ticket:78
NOTE: that this also fixes what is technically another bug in REXML. REXML's
XPath parser used to allow exponential notation in numbers. The XPath spec
is specific about what a number is, and scientific notation is not included.
Therefore, this has been fixed.
Cross-ported a fix for ticket:88 from CVS.
Fixes ticket:80
Documentation cleanup. Ticket:84
Applied Kou's fix for an un-trac'ed bug.
------------------------------------------------------------------------
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-01-19 22:56:02 -05:00
|
|
|
def SourceFactory::create_from(arg)
|
Short summary:
This is a version bump to REXML 3.1.4 for Ruby HEAD. This change log is
identical to the log for the 1.8 branch.
It includes numerous bug fixes and is a pretty big patch, but is nonetheless
a minor revision bump, since the API hasn't changed.
For more information, see:
http:/www.germane-software.com/projects/rexml/milestone/3.1.4
For all tickets, see:
http://www.germane-software.com/projects/rexml/ticket/#
Where '#' is replaced with the ticket number.
Changelog:
* Fixed the documentation WRT the raw mode of text nodes (ticket #4)
* Fixes roundup ticket #43: substring-after bug.
* Fixed ticket #44, Element#xpath
* Patch submitted by an anonymous doner to allow parsing of Tempfiles. I was
hoping that, by now, that whole Source thing would have been changed to use
duck typing and avoid this sort of ticket... but in the meantime, the patch
has been applied.
* Fixes ticket:30, XPath default namespace bug. The fix was provided
by Lucas Nussbaum.
* Aliases #size to #length, as per zdennis's request.
* Fixes typo from previous commit
* Fixes ticket #32, preceding-sibling fails attempting delete_if on nil nodeset
* Merges a user-contributed patch for ticket #40
* Adds a forgotten-to-commit unit test for ticket #32
* Changes Date, Version, and Copyright to upper case, to avoid conflicts with
the Date class. All of the other changes in the altered files are because
Subversion doesn't allow block-level commits, like it should. English cased
Version and Copyright are aliased to the upper case versions, for partial
backward compatability.
* Resolves ticket #34, SAX parser change makes it impossible to parse IO feeds.
* Moves parser.source.position() to parser.position()
* Fixes ticket:48, repeated writes munging text content
* Fixes ticket:46, adding methods for accessing notation DTD information.
* Encodes some characters and removes a brokes link in the documentation
* Deals with carriage returns after XML declarations
* Improved doctype handling
* Whitespace handling changes
* Applies a patch by David Tardon, which (incidentally) fixes ticket:50
* Closes #26, allowing anything that walks like an IO to be a source.
* Ticket #31 - One unescape too many
This wasn't really a bug, per se... "value" always returns
a normalized string, and "value" is the method used to get
the text() of an element. However, entities have no meaning
in CDATA sections, so there's no justification for value
to be normalizing the content of CData objects. This behavior
has therefore been changed.
* Ticket #45 -- Now parses notation declarations in DTDs properly.
* Resolves ticket #49, Document.parse_stream returns ArgumentError
* Adds documentation to clarify how XMLDecl works, to avoid invalid bug reports.
* Addresses ticket #10, fixing the StreamParser API for DTDs.
* Fixes ticket #42, XPath node-set function 'name' fails with relative node
set parameter
* Good patch by Aaron to fix ticket #53: REXML ignoring unbalanced tags
at the end of a document.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10092 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-04-15 00:11:04 -04:00
|
|
|
if arg.kind_of? String
|
|
|
|
Source.new(arg)
|
|
|
|
elsif arg.respond_to? :read and
|
|
|
|
arg.respond_to? :readline and
|
|
|
|
arg.respond_to? :nil? and
|
|
|
|
arg.respond_to? :eof?
|
|
|
|
IOSource.new(arg)
|
|
|
|
elsif arg.kind_of? Source
|
|
|
|
arg
|
|
|
|
else
|
|
|
|
raise "#{source.class} is not a valid input stream. It must walk \n"+
|
|
|
|
"like either a String, IO, or Source."
|
|
|
|
end
|
2003-06-09 21:31:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# A Source can be searched for patterns, and wraps buffers and other
|
|
|
|
# objects and provides consumption of text
|
|
|
|
class Source
|
|
|
|
include Encoding
|
|
|
|
# The current buffer (what we're going to read next)
|
|
|
|
attr_reader :buffer
|
|
|
|
# The line number of the last consumed text
|
|
|
|
attr_reader :line
|
|
|
|
attr_reader :encoding
|
|
|
|
|
|
|
|
# Constructor
|
|
|
|
# @param arg must be a String, and should be a valid XML document
|
Merged from REXML main repository:
Fixes ticket:68.
NOTE that this involves an API change! Entity declarations in the doctype
now generate events that carry two, not one, arguments.
Implements ticket:15, using gwrite's suggestion. This allows Element to be
subclassed.
Two unrelated changes, because subversion is retarded and doesn't do
block-level commits:
1) Fixed a typo bug in previous change for ticket:15
2) Fixed namespaces handling in XPath and element.
***** Note that this is an API change!!! *****
Element.namespaces() now returns a hash of namespace mappings which are
relevant for that node.
Fixes a bug in multiple decodings
The changeset 1230:1231 was bad. The default behavior is *not* to use the
native REXML encodings by default, but rather to use ICONV by default. I know
that this will piss some people off, but defaulting to the pure Ruby version
isn't the correct solution, and it breaks other encodings, so I've reverted it.
* Fixes ticket:61 (xpath_parser)
* Fixes ticket:63 (UTF-16; UNILE decoding was bad)
* Cleans up some tests, removing opportunities for test corruption
* Improves parsing error messages a little
* Adds the ability to override the encoding detection in Source construction
* Fixes an edge case in Functions::string, where document nodes weren't
correctly converted
* Fixes Functions::string() for Element and Document nodes
* Fixes some problems in entity handling
Addresses ticket:66
Fixes ticket:71
Addresses ticket:78
NOTE: that this also fixes what is technically another bug in REXML. REXML's
XPath parser used to allow exponential notation in numbers. The XPath spec
is specific about what a number is, and scientific notation is not included.
Therefore, this has been fixed.
Cross-ported a fix for ticket:88 from CVS.
Fixes ticket:80
Documentation cleanup. Ticket:84
Applied Kou's fix for an un-trac'ed bug.
------------------------------------------------------------------------
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-01-19 22:56:02 -05:00
|
|
|
# @param encoding if non-null, sets the encoding of the source to this
|
|
|
|
# value, overriding all encoding detection
|
|
|
|
def initialize(arg, encoding=nil)
|
2003-06-09 21:31:01 -04:00
|
|
|
@orig = @buffer = arg
|
Merged from REXML main repository:
Fixes ticket:68.
NOTE that this involves an API change! Entity declarations in the doctype
now generate events that carry two, not one, arguments.
Implements ticket:15, using gwrite's suggestion. This allows Element to be
subclassed.
Two unrelated changes, because subversion is retarded and doesn't do
block-level commits:
1) Fixed a typo bug in previous change for ticket:15
2) Fixed namespaces handling in XPath and element.
***** Note that this is an API change!!! *****
Element.namespaces() now returns a hash of namespace mappings which are
relevant for that node.
Fixes a bug in multiple decodings
The changeset 1230:1231 was bad. The default behavior is *not* to use the
native REXML encodings by default, but rather to use ICONV by default. I know
that this will piss some people off, but defaulting to the pure Ruby version
isn't the correct solution, and it breaks other encodings, so I've reverted it.
* Fixes ticket:61 (xpath_parser)
* Fixes ticket:63 (UTF-16; UNILE decoding was bad)
* Cleans up some tests, removing opportunities for test corruption
* Improves parsing error messages a little
* Adds the ability to override the encoding detection in Source construction
* Fixes an edge case in Functions::string, where document nodes weren't
correctly converted
* Fixes Functions::string() for Element and Document nodes
* Fixes some problems in entity handling
Addresses ticket:66
Fixes ticket:71
Addresses ticket:78
NOTE: that this also fixes what is technically another bug in REXML. REXML's
XPath parser used to allow exponential notation in numbers. The XPath spec
is specific about what a number is, and scientific notation is not included.
Therefore, this has been fixed.
Cross-ported a fix for ticket:88 from CVS.
Fixes ticket:80
Documentation cleanup. Ticket:84
Applied Kou's fix for an un-trac'ed bug.
------------------------------------------------------------------------
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-01-19 22:56:02 -05:00
|
|
|
if encoding
|
|
|
|
self.encoding = encoding
|
|
|
|
else
|
|
|
|
self.encoding = check_encoding( @buffer )
|
|
|
|
end
|
2003-06-09 21:31:01 -04:00
|
|
|
@line = 0
|
|
|
|
end
|
|
|
|
|
Merged from REXML main repository:
Fixes ticket:68.
NOTE that this involves an API change! Entity declarations in the doctype
now generate events that carry two, not one, arguments.
Implements ticket:15, using gwrite's suggestion. This allows Element to be
subclassed.
Two unrelated changes, because subversion is retarded and doesn't do
block-level commits:
1) Fixed a typo bug in previous change for ticket:15
2) Fixed namespaces handling in XPath and element.
***** Note that this is an API change!!! *****
Element.namespaces() now returns a hash of namespace mappings which are
relevant for that node.
Fixes a bug in multiple decodings
The changeset 1230:1231 was bad. The default behavior is *not* to use the
native REXML encodings by default, but rather to use ICONV by default. I know
that this will piss some people off, but defaulting to the pure Ruby version
isn't the correct solution, and it breaks other encodings, so I've reverted it.
* Fixes ticket:61 (xpath_parser)
* Fixes ticket:63 (UTF-16; UNILE decoding was bad)
* Cleans up some tests, removing opportunities for test corruption
* Improves parsing error messages a little
* Adds the ability to override the encoding detection in Source construction
* Fixes an edge case in Functions::string, where document nodes weren't
correctly converted
* Fixes Functions::string() for Element and Document nodes
* Fixes some problems in entity handling
Addresses ticket:66
Fixes ticket:71
Addresses ticket:78
NOTE: that this also fixes what is technically another bug in REXML. REXML's
XPath parser used to allow exponential notation in numbers. The XPath spec
is specific about what a number is, and scientific notation is not included.
Therefore, this has been fixed.
Cross-ported a fix for ticket:88 from CVS.
Fixes ticket:80
Documentation cleanup. Ticket:84
Applied Kou's fix for an un-trac'ed bug.
------------------------------------------------------------------------
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-01-19 22:56:02 -05:00
|
|
|
|
2003-06-09 21:31:01 -04:00
|
|
|
# Inherited from Encoding
|
|
|
|
# Overridden to support optimized en/decoding
|
|
|
|
def encoding=(enc)
|
2006-09-10 22:48:17 -04:00
|
|
|
return unless super
|
2003-06-09 21:31:01 -04:00
|
|
|
@line_break = encode( '>' )
|
|
|
|
if enc != UTF_8
|
|
|
|
@buffer = decode(@buffer)
|
|
|
|
@to_utf = true
|
|
|
|
else
|
|
|
|
@to_utf = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Scans the source for a given pattern. Note, that this is not your
|
|
|
|
# usual scan() method. For one thing, the pattern argument has some
|
|
|
|
# requirements; for another, the source can be consumed. You can easily
|
|
|
|
# confuse this method. Originally, the patterns were easier
|
|
|
|
# to construct and this method more robust, because this method
|
|
|
|
# generated search regexes on the fly; however, this was
|
|
|
|
# computationally expensive and slowed down the entire REXML package
|
|
|
|
# considerably, since this is by far the most commonly called method.
|
|
|
|
# @param pattern must be a Regexp, and must be in the form of
|
|
|
|
# /^\s*(#{your pattern, with no groups})(.*)/. The first group
|
|
|
|
# will be returned; the second group is used if the consume flag is
|
|
|
|
# set.
|
|
|
|
# @param consume if true, the pattern returned will be consumed, leaving
|
|
|
|
# everything after it in the Source.
|
|
|
|
# @return the pattern, if found, or nil if the Source is empty or the
|
|
|
|
# pattern is not found.
|
2003-12-08 21:41:33 -05:00
|
|
|
def scan(pattern, cons=false)
|
2003-06-09 21:31:01 -04:00
|
|
|
return nil if @buffer.nil?
|
|
|
|
rv = @buffer.scan(pattern)
|
2003-12-08 21:41:33 -05:00
|
|
|
@buffer = $' if cons and rv.size>0
|
2003-06-09 21:31:01 -04:00
|
|
|
rv
|
|
|
|
end
|
|
|
|
|
|
|
|
def read
|
|
|
|
end
|
|
|
|
|
2003-10-10 08:54:46 -04:00
|
|
|
def consume( pattern )
|
|
|
|
@buffer = $' if pattern.match( @buffer )
|
|
|
|
end
|
|
|
|
|
|
|
|
def match_to( char, pattern )
|
|
|
|
return pattern.match(@buffer)
|
|
|
|
end
|
|
|
|
|
|
|
|
def match_to_consume( char, pattern )
|
|
|
|
md = pattern.match(@buffer)
|
|
|
|
@buffer = $'
|
|
|
|
return md
|
|
|
|
end
|
|
|
|
|
2003-12-08 21:41:33 -05:00
|
|
|
def match(pattern, cons=false)
|
2003-10-10 08:54:46 -04:00
|
|
|
md = pattern.match(@buffer)
|
2003-12-08 21:41:33 -05:00
|
|
|
@buffer = $' if cons and md
|
2003-06-09 21:31:01 -04:00
|
|
|
return md
|
|
|
|
end
|
|
|
|
|
|
|
|
# @return true if the Source is exhausted
|
|
|
|
def empty?
|
2004-02-13 17:40:14 -05:00
|
|
|
@buffer == ""
|
2003-06-09 21:31:01 -04:00
|
|
|
end
|
|
|
|
|
Short summary:
This is a version bump to REXML 3.1.4 for Ruby HEAD. This change log is
identical to the log for the 1.8 branch.
It includes numerous bug fixes and is a pretty big patch, but is nonetheless
a minor revision bump, since the API hasn't changed.
For more information, see:
http:/www.germane-software.com/projects/rexml/milestone/3.1.4
For all tickets, see:
http://www.germane-software.com/projects/rexml/ticket/#
Where '#' is replaced with the ticket number.
Changelog:
* Fixed the documentation WRT the raw mode of text nodes (ticket #4)
* Fixes roundup ticket #43: substring-after bug.
* Fixed ticket #44, Element#xpath
* Patch submitted by an anonymous doner to allow parsing of Tempfiles. I was
hoping that, by now, that whole Source thing would have been changed to use
duck typing and avoid this sort of ticket... but in the meantime, the patch
has been applied.
* Fixes ticket:30, XPath default namespace bug. The fix was provided
by Lucas Nussbaum.
* Aliases #size to #length, as per zdennis's request.
* Fixes typo from previous commit
* Fixes ticket #32, preceding-sibling fails attempting delete_if on nil nodeset
* Merges a user-contributed patch for ticket #40
* Adds a forgotten-to-commit unit test for ticket #32
* Changes Date, Version, and Copyright to upper case, to avoid conflicts with
the Date class. All of the other changes in the altered files are because
Subversion doesn't allow block-level commits, like it should. English cased
Version and Copyright are aliased to the upper case versions, for partial
backward compatability.
* Resolves ticket #34, SAX parser change makes it impossible to parse IO feeds.
* Moves parser.source.position() to parser.position()
* Fixes ticket:48, repeated writes munging text content
* Fixes ticket:46, adding methods for accessing notation DTD information.
* Encodes some characters and removes a brokes link in the documentation
* Deals with carriage returns after XML declarations
* Improved doctype handling
* Whitespace handling changes
* Applies a patch by David Tardon, which (incidentally) fixes ticket:50
* Closes #26, allowing anything that walks like an IO to be a source.
* Ticket #31 - One unescape too many
This wasn't really a bug, per se... "value" always returns
a normalized string, and "value" is the method used to get
the text() of an element. However, entities have no meaning
in CDATA sections, so there's no justification for value
to be normalizing the content of CData objects. This behavior
has therefore been changed.
* Ticket #45 -- Now parses notation declarations in DTDs properly.
* Resolves ticket #49, Document.parse_stream returns ArgumentError
* Adds documentation to clarify how XMLDecl works, to avoid invalid bug reports.
* Addresses ticket #10, fixing the StreamParser API for DTDs.
* Fixes ticket #42, XPath node-set function 'name' fails with relative node
set parameter
* Good patch by Aaron to fix ticket #53: REXML ignoring unbalanced tags
at the end of a document.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10092 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-04-15 00:11:04 -04:00
|
|
|
def position
|
|
|
|
@orig.index( @buffer )
|
|
|
|
end
|
|
|
|
|
2003-06-09 21:31:01 -04:00
|
|
|
# @return the current line in the source
|
|
|
|
def current_line
|
|
|
|
lines = @orig.split
|
2003-12-08 21:41:33 -05:00
|
|
|
res = lines.grep @buffer[0..30]
|
2003-06-09 21:31:01 -04:00
|
|
|
res = res[-1] if res.kind_of? Array
|
|
|
|
lines.index( res ) if res
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# A Source that wraps an IO. See the Source class for method
|
|
|
|
# documentation
|
|
|
|
class IOSource < Source
|
|
|
|
#attr_reader :block_size
|
|
|
|
|
2004-02-13 17:40:14 -05:00
|
|
|
# block_size has been deprecated
|
Merged from REXML main repository:
Fixes ticket:68.
NOTE that this involves an API change! Entity declarations in the doctype
now generate events that carry two, not one, arguments.
Implements ticket:15, using gwrite's suggestion. This allows Element to be
subclassed.
Two unrelated changes, because subversion is retarded and doesn't do
block-level commits:
1) Fixed a typo bug in previous change for ticket:15
2) Fixed namespaces handling in XPath and element.
***** Note that this is an API change!!! *****
Element.namespaces() now returns a hash of namespace mappings which are
relevant for that node.
Fixes a bug in multiple decodings
The changeset 1230:1231 was bad. The default behavior is *not* to use the
native REXML encodings by default, but rather to use ICONV by default. I know
that this will piss some people off, but defaulting to the pure Ruby version
isn't the correct solution, and it breaks other encodings, so I've reverted it.
* Fixes ticket:61 (xpath_parser)
* Fixes ticket:63 (UTF-16; UNILE decoding was bad)
* Cleans up some tests, removing opportunities for test corruption
* Improves parsing error messages a little
* Adds the ability to override the encoding detection in Source construction
* Fixes an edge case in Functions::string, where document nodes weren't
correctly converted
* Fixes Functions::string() for Element and Document nodes
* Fixes some problems in entity handling
Addresses ticket:66
Fixes ticket:71
Addresses ticket:78
NOTE: that this also fixes what is technically another bug in REXML. REXML's
XPath parser used to allow exponential notation in numbers. The XPath spec
is specific about what a number is, and scientific notation is not included.
Therefore, this has been fixed.
Cross-ported a fix for ticket:88 from CVS.
Fixes ticket:80
Documentation cleanup. Ticket:84
Applied Kou's fix for an un-trac'ed bug.
------------------------------------------------------------------------
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-01-19 22:56:02 -05:00
|
|
|
def initialize(arg, block_size=500, encoding=nil)
|
2003-06-09 21:31:01 -04:00
|
|
|
@er_source = @source = arg
|
|
|
|
@to_utf = false
|
2004-07-18 10:04:03 -04:00
|
|
|
# Determining the encoding is a deceptively difficult issue to resolve.
|
|
|
|
# First, we check the first two bytes for UTF-16. Then we
|
|
|
|
# assume that the encoding is at least ASCII enough for the '>', and
|
|
|
|
# we read until we get one of those. This gives us the XML declaration,
|
|
|
|
# if there is one. If there isn't one, the file MUST be UTF-8, as per
|
|
|
|
# the XML spec. If there is one, we can determine the encoding from
|
|
|
|
# it.
|
Merged from REXML main repository:
Fixes ticket:68.
NOTE that this involves an API change! Entity declarations in the doctype
now generate events that carry two, not one, arguments.
Implements ticket:15, using gwrite's suggestion. This allows Element to be
subclassed.
Two unrelated changes, because subversion is retarded and doesn't do
block-level commits:
1) Fixed a typo bug in previous change for ticket:15
2) Fixed namespaces handling in XPath and element.
***** Note that this is an API change!!! *****
Element.namespaces() now returns a hash of namespace mappings which are
relevant for that node.
Fixes a bug in multiple decodings
The changeset 1230:1231 was bad. The default behavior is *not* to use the
native REXML encodings by default, but rather to use ICONV by default. I know
that this will piss some people off, but defaulting to the pure Ruby version
isn't the correct solution, and it breaks other encodings, so I've reverted it.
* Fixes ticket:61 (xpath_parser)
* Fixes ticket:63 (UTF-16; UNILE decoding was bad)
* Cleans up some tests, removing opportunities for test corruption
* Improves parsing error messages a little
* Adds the ability to override the encoding detection in Source construction
* Fixes an edge case in Functions::string, where document nodes weren't
correctly converted
* Fixes Functions::string() for Element and Document nodes
* Fixes some problems in entity handling
Addresses ticket:66
Fixes ticket:71
Addresses ticket:78
NOTE: that this also fixes what is technically another bug in REXML. REXML's
XPath parser used to allow exponential notation in numbers. The XPath spec
is specific about what a number is, and scientific notation is not included.
Therefore, this has been fixed.
Cross-ported a fix for ticket:88 from CVS.
Fixes ticket:80
Documentation cleanup. Ticket:84
Applied Kou's fix for an un-trac'ed bug.
------------------------------------------------------------------------
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-01-19 22:56:02 -05:00
|
|
|
@buffer = ""
|
2004-07-18 10:04:03 -04:00
|
|
|
str = @source.read( 2 )
|
Merged from REXML main repository:
Fixes ticket:68.
NOTE that this involves an API change! Entity declarations in the doctype
now generate events that carry two, not one, arguments.
Implements ticket:15, using gwrite's suggestion. This allows Element to be
subclassed.
Two unrelated changes, because subversion is retarded and doesn't do
block-level commits:
1) Fixed a typo bug in previous change for ticket:15
2) Fixed namespaces handling in XPath and element.
***** Note that this is an API change!!! *****
Element.namespaces() now returns a hash of namespace mappings which are
relevant for that node.
Fixes a bug in multiple decodings
The changeset 1230:1231 was bad. The default behavior is *not* to use the
native REXML encodings by default, but rather to use ICONV by default. I know
that this will piss some people off, but defaulting to the pure Ruby version
isn't the correct solution, and it breaks other encodings, so I've reverted it.
* Fixes ticket:61 (xpath_parser)
* Fixes ticket:63 (UTF-16; UNILE decoding was bad)
* Cleans up some tests, removing opportunities for test corruption
* Improves parsing error messages a little
* Adds the ability to override the encoding detection in Source construction
* Fixes an edge case in Functions::string, where document nodes weren't
correctly converted
* Fixes Functions::string() for Element and Document nodes
* Fixes some problems in entity handling
Addresses ticket:66
Fixes ticket:71
Addresses ticket:78
NOTE: that this also fixes what is technically another bug in REXML. REXML's
XPath parser used to allow exponential notation in numbers. The XPath spec
is specific about what a number is, and scientific notation is not included.
Therefore, this has been fixed.
Cross-ported a fix for ticket:88 from CVS.
Fixes ticket:80
Documentation cleanup. Ticket:84
Applied Kou's fix for an un-trac'ed bug.
------------------------------------------------------------------------
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-01-19 22:56:02 -05:00
|
|
|
if encoding
|
|
|
|
self.encoding = encoding
|
|
|
|
elsif /\A(?:\xfe\xff|\xff\xfe)/n =~ str
|
2006-08-22 11:25:43 -04:00
|
|
|
self.encoding = check_encoding( str )
|
2004-07-18 10:04:03 -04:00
|
|
|
else
|
|
|
|
@line_break = '>'
|
|
|
|
end
|
|
|
|
super str+@source.readline( @line_break )
|
2006-08-22 11:25:43 -04:00
|
|
|
end
|
2003-06-09 21:31:01 -04:00
|
|
|
|
2003-12-08 21:41:33 -05:00
|
|
|
def scan(pattern, cons=false)
|
2003-06-09 21:31:01 -04:00
|
|
|
rv = super
|
|
|
|
# You'll notice that this next section is very similar to the same
|
|
|
|
# section in match(), but just a liiittle different. This is
|
|
|
|
# because it is a touch faster to do it this way with scan()
|
|
|
|
# than the way match() does it; enough faster to warrent duplicating
|
|
|
|
# some code
|
|
|
|
if rv.size == 0
|
|
|
|
until @buffer =~ pattern or @source.nil?
|
|
|
|
begin
|
|
|
|
# READLINE OPT
|
|
|
|
#str = @source.read(@block_size)
|
|
|
|
str = @source.readline(@line_break)
|
|
|
|
str = decode(str) if @to_utf and str
|
|
|
|
@buffer << str
|
Merged from REXML main repository:
Fixes ticket:68.
NOTE that this involves an API change! Entity declarations in the doctype
now generate events that carry two, not one, arguments.
Implements ticket:15, using gwrite's suggestion. This allows Element to be
subclassed.
Two unrelated changes, because subversion is retarded and doesn't do
block-level commits:
1) Fixed a typo bug in previous change for ticket:15
2) Fixed namespaces handling in XPath and element.
***** Note that this is an API change!!! *****
Element.namespaces() now returns a hash of namespace mappings which are
relevant for that node.
Fixes a bug in multiple decodings
The changeset 1230:1231 was bad. The default behavior is *not* to use the
native REXML encodings by default, but rather to use ICONV by default. I know
that this will piss some people off, but defaulting to the pure Ruby version
isn't the correct solution, and it breaks other encodings, so I've reverted it.
* Fixes ticket:61 (xpath_parser)
* Fixes ticket:63 (UTF-16; UNILE decoding was bad)
* Cleans up some tests, removing opportunities for test corruption
* Improves parsing error messages a little
* Adds the ability to override the encoding detection in Source construction
* Fixes an edge case in Functions::string, where document nodes weren't
correctly converted
* Fixes Functions::string() for Element and Document nodes
* Fixes some problems in entity handling
Addresses ticket:66
Fixes ticket:71
Addresses ticket:78
NOTE: that this also fixes what is technically another bug in REXML. REXML's
XPath parser used to allow exponential notation in numbers. The XPath spec
is specific about what a number is, and scientific notation is not included.
Therefore, this has been fixed.
Cross-ported a fix for ticket:88 from CVS.
Fixes ticket:80
Documentation cleanup. Ticket:84
Applied Kou's fix for an un-trac'ed bug.
------------------------------------------------------------------------
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-01-19 22:56:02 -05:00
|
|
|
rescue Iconv::IllegalSequence
|
|
|
|
raise
|
2003-06-09 21:31:01 -04:00
|
|
|
rescue
|
|
|
|
@source = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
rv = super
|
|
|
|
end
|
|
|
|
rv.taint
|
|
|
|
rv
|
|
|
|
end
|
|
|
|
|
|
|
|
def read
|
|
|
|
begin
|
2004-04-23 11:44:30 -04:00
|
|
|
str = @source.readline(@line_break)
|
2003-06-09 21:31:01 -04:00
|
|
|
str = decode(str) if @to_utf and str
|
|
|
|
@buffer << str
|
2003-10-10 08:54:46 -04:00
|
|
|
rescue Exception, NameError
|
2003-06-09 21:31:01 -04:00
|
|
|
@source = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-10-10 08:54:46 -04:00
|
|
|
def consume( pattern )
|
|
|
|
match( pattern, true )
|
|
|
|
end
|
|
|
|
|
2003-12-08 21:41:33 -05:00
|
|
|
def match( pattern, cons=false )
|
2003-06-09 21:31:01 -04:00
|
|
|
rv = pattern.match(@buffer)
|
2003-12-08 21:41:33 -05:00
|
|
|
@buffer = $' if cons and rv
|
2003-06-09 21:31:01 -04:00
|
|
|
while !rv and @source
|
|
|
|
begin
|
2004-04-23 11:44:30 -04:00
|
|
|
str = @source.readline(@line_break)
|
2003-06-09 21:31:01 -04:00
|
|
|
str = decode(str) if @to_utf and str
|
|
|
|
@buffer << str
|
|
|
|
rv = pattern.match(@buffer)
|
2003-12-08 21:41:33 -05:00
|
|
|
@buffer = $' if cons and rv
|
2003-06-09 21:31:01 -04:00
|
|
|
rescue
|
|
|
|
@source = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
rv.taint
|
|
|
|
rv
|
|
|
|
end
|
|
|
|
|
|
|
|
def empty?
|
|
|
|
super and ( @source.nil? || @source.eof? )
|
|
|
|
end
|
|
|
|
|
Short summary:
This is a version bump to REXML 3.1.4 for Ruby HEAD. This change log is
identical to the log for the 1.8 branch.
It includes numerous bug fixes and is a pretty big patch, but is nonetheless
a minor revision bump, since the API hasn't changed.
For more information, see:
http:/www.germane-software.com/projects/rexml/milestone/3.1.4
For all tickets, see:
http://www.germane-software.com/projects/rexml/ticket/#
Where '#' is replaced with the ticket number.
Changelog:
* Fixed the documentation WRT the raw mode of text nodes (ticket #4)
* Fixes roundup ticket #43: substring-after bug.
* Fixed ticket #44, Element#xpath
* Patch submitted by an anonymous doner to allow parsing of Tempfiles. I was
hoping that, by now, that whole Source thing would have been changed to use
duck typing and avoid this sort of ticket... but in the meantime, the patch
has been applied.
* Fixes ticket:30, XPath default namespace bug. The fix was provided
by Lucas Nussbaum.
* Aliases #size to #length, as per zdennis's request.
* Fixes typo from previous commit
* Fixes ticket #32, preceding-sibling fails attempting delete_if on nil nodeset
* Merges a user-contributed patch for ticket #40
* Adds a forgotten-to-commit unit test for ticket #32
* Changes Date, Version, and Copyright to upper case, to avoid conflicts with
the Date class. All of the other changes in the altered files are because
Subversion doesn't allow block-level commits, like it should. English cased
Version and Copyright are aliased to the upper case versions, for partial
backward compatability.
* Resolves ticket #34, SAX parser change makes it impossible to parse IO feeds.
* Moves parser.source.position() to parser.position()
* Fixes ticket:48, repeated writes munging text content
* Fixes ticket:46, adding methods for accessing notation DTD information.
* Encodes some characters and removes a brokes link in the documentation
* Deals with carriage returns after XML declarations
* Improved doctype handling
* Whitespace handling changes
* Applies a patch by David Tardon, which (incidentally) fixes ticket:50
* Closes #26, allowing anything that walks like an IO to be a source.
* Ticket #31 - One unescape too many
This wasn't really a bug, per se... "value" always returns
a normalized string, and "value" is the method used to get
the text() of an element. However, entities have no meaning
in CDATA sections, so there's no justification for value
to be normalizing the content of CData objects. This behavior
has therefore been changed.
* Ticket #45 -- Now parses notation declarations in DTDs properly.
* Resolves ticket #49, Document.parse_stream returns ArgumentError
* Adds documentation to clarify how XMLDecl works, to avoid invalid bug reports.
* Addresses ticket #10, fixing the StreamParser API for DTDs.
* Fixes ticket #42, XPath node-set function 'name' fails with relative node
set parameter
* Good patch by Aaron to fix ticket #53: REXML ignoring unbalanced tags
at the end of a document.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10092 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-04-15 00:11:04 -04:00
|
|
|
def position
|
|
|
|
@er_source.stat.pipe? ? 0 : @er_source.pos
|
|
|
|
end
|
|
|
|
|
2003-06-09 21:31:01 -04:00
|
|
|
# @return the current line in the source
|
|
|
|
def current_line
|
2004-04-23 11:44:30 -04:00
|
|
|
begin
|
|
|
|
pos = @er_source.pos # The byte position in the source
|
|
|
|
lineno = @er_source.lineno # The XML < position in the source
|
|
|
|
@er_source.rewind
|
|
|
|
line = 0 # The \r\n position in the source
|
|
|
|
begin
|
|
|
|
while @er_source.pos < pos
|
|
|
|
@er_source.readline
|
|
|
|
line += 1
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
rescue IOError
|
|
|
|
pos = -1
|
|
|
|
line = -1
|
|
|
|
end
|
2003-06-09 21:31:01 -04:00
|
|
|
[pos, lineno, line]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|