mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* ext/syck/token.c: preserve newlines prepended to a block.
* ext/syck/implicit.c (syck_match_implicit): added !merge and !default. * lib/yaml/constants.rb: remove '\z' escape. * lib/yaml/emitter.rb: ensure reset of @seq_map shortcut flag. * lib/yaml/encoding.rb: remove Unicode translation methods. * lib/yaml/rubytypes.rb: improved round-tripping of Strings. [ruby-core:1134] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3937 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									3079dcab4a
								
							
						
					
					
						commit
						e921ea2d78
					
				
					 7 changed files with 2019 additions and 1967 deletions
				
			
		
							
								
								
									
										15
									
								
								ChangeLog
									
										
									
									
									
								
							
							
						
						
									
										15
									
								
								ChangeLog
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,3 +1,18 @@
 | 
			
		|||
Tue Jun 10 14:26:30 2003  why the lucky stiff  <ruby-cvs@whytheluckystiff.net>
 | 
			
		||||
 | 
			
		||||
    * ext/syck/token.c: preserve newlines prepended to a block.
 | 
			
		||||
 | 
			
		||||
    * ext/syck/implicit.c (syck_match_implicit): added !merge and !default.
 | 
			
		||||
 | 
			
		||||
    * lib/yaml/constants.rb: remove '\z' escape.
 | 
			
		||||
 | 
			
		||||
    * lib/yaml/emitter.rb: ensure reset of @seq_map shortcut flag.
 | 
			
		||||
 | 
			
		||||
    * lib/yaml/encoding.rb: remove Unicode translation methods.
 | 
			
		||||
 | 
			
		||||
    * lib/yaml/rubytypes.rb: improved round-tripping of Strings.
 | 
			
		||||
      [ruby-core:1134]
 | 
			
		||||
 | 
			
		||||
Tue Jun 10 01:07:54 2003  Yukihiro Matsumoto  <matz@ruby-lang.org>
 | 
			
		||||
 | 
			
		||||
	* lib/irb.rb (IRB::Irb::eval_input): warn and exit if $SAFE >=3
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2763
									
								
								ext/syck/implicit.c
									
										
									
									
									
								
							
							
						
						
									
										2763
									
								
								ext/syck/implicit.c
									
										
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
							
								
								
									
										1083
									
								
								ext/syck/token.c
									
										
									
									
									
								
							
							
						
						
									
										1083
									
								
								ext/syck/token.c
									
										
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							| 
						 | 
				
			
			@ -15,19 +15,19 @@ module YAML
 | 
			
		|||
	WORD_CHAR = 'A-Za-z0-9'
 | 
			
		||||
	PRINTABLE_CHAR = '-_A-Za-z0-9!?/()$\'". ' 
 | 
			
		||||
	NOT_PLAIN_CHAR = '\x7f\x0-\x1f\x80-\x9f'
 | 
			
		||||
	ESCAPE_CHAR = '[\\x00-\\x08\\x0b-\\x0d\\x0e-\\x1f]'
 | 
			
		||||
	ESCAPE_CHAR = '[\\x00-\\x09\\x0b-\\x1f]'
 | 
			
		||||
	INDICATOR_CHAR = '*&!|\\\\^@%{}[]='
 | 
			
		||||
	SPACE_INDICATORS = '-#:,?'
 | 
			
		||||
	RESTRICTED_INDICATORS = '#:,}]'
 | 
			
		||||
	DNS_COMP_RE = "\\w(?:[-\\w]*\\w)?"
 | 
			
		||||
	DNS_NAME_RE = "(?:(?:#{DNS_COMP_RE}\\.)+#{DNS_COMP_RE}|#{DNS_COMP_RE})"
 | 
			
		||||
	ESCAPES = %w{\z		\x01	\x02	\x03	\x04	\x05	\x06	\a
 | 
			
		||||
	ESCAPES = %w{\x00   \x01	\x02	\x03	\x04	\x05	\x06	\a
 | 
			
		||||
			     \x08	\t		\n		\v		\f		\r		\x0e	\x0f
 | 
			
		||||
				 \x10	\x11	\x12	\x13	\x14	\x15	\x16	\x17
 | 
			
		||||
				 \x18	\x19	\x1a	\e		\x1c	\x1d	\x1e	\x1f
 | 
			
		||||
			    }
 | 
			
		||||
	UNESCAPES = {
 | 
			
		||||
				'z' => "\x00", 'a' => "\x07", 'b' => "\x08", 't' => "\x09", 
 | 
			
		||||
				'a' => "\x07", 'b' => "\x08", 't' => "\x09", 
 | 
			
		||||
				'n' => "\x0a", 'v' => "\x0b", 'f' => "\x0c",
 | 
			
		||||
				'r' => "\x0d", 'e' => "\x1b", '\\' => '\\',
 | 
			
		||||
			    }
 | 
			
		||||
| 
						 | 
				
			
			@ -41,11 +41,5 @@ module YAML
 | 
			
		|||
		:WidthType => 'absolute', :BestWidth => 80,
 | 
			
		||||
		:UseBlock => false, :UseFold => false, :Encoding => :None
 | 
			
		||||
	}
 | 
			
		||||
	TRANSFER_DOMAINS = {
 | 
			
		||||
		'yaml.org,2002' => {},
 | 
			
		||||
		'ruby.yaml.org,2002' => {}
 | 
			
		||||
	}
 | 
			
		||||
	PRIVATE_TYPES = {}
 | 
			
		||||
	IMPLICIT_TYPES = [ 'null', 'bool', 'time', 'int', 'float' ]
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -60,6 +60,7 @@ module YAML
 | 
			
		|||
		# Emit plain, normal flowing text
 | 
			
		||||
		#
 | 
			
		||||
		def node_text( value, block = '>' )
 | 
			
		||||
            @seq_map = false
 | 
			
		||||
			valx = value.dup
 | 
			
		||||
			if @options[:UseBlock]
 | 
			
		||||
				block = '|'
 | 
			
		||||
| 
						 | 
				
			
			@ -89,6 +90,7 @@ module YAML
 | 
			
		|||
		# Emit a simple, unqouted string
 | 
			
		||||
		#
 | 
			
		||||
		def simple( value )
 | 
			
		||||
            @seq_map = false
 | 
			
		||||
            self << value.to_s
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -168,6 +170,7 @@ module YAML
 | 
			
		|||
			#
 | 
			
		||||
			if val.length.zero?
 | 
			
		||||
				self << "{}"
 | 
			
		||||
                @seq_map = false
 | 
			
		||||
			else
 | 
			
		||||
                if @buffer.length == 1 and @options[:UseHeader] == false and type.length.zero? 
 | 
			
		||||
			        @headless = 1 
 | 
			
		||||
| 
						 | 
				
			
			@ -213,6 +216,7 @@ module YAML
 | 
			
		|||
        # Quick sequence
 | 
			
		||||
        #
 | 
			
		||||
        def seq( type, &e )
 | 
			
		||||
            @seq_map = false
 | 
			
		||||
            val = Sequence.new
 | 
			
		||||
            e.call( val )
 | 
			
		||||
			self << "#{type} " if type.length.nonzero?
 | 
			
		||||
| 
						 | 
				
			
			@ -282,7 +286,7 @@ module YAML
 | 
			
		|||
            @buffer.push( "" )
 | 
			
		||||
            #p [ self.id, @level, :END ]
 | 
			
		||||
			if @level < 0
 | 
			
		||||
				YAML.internal_to_utf( header + @buffer.to_s[@headless..-1], @options[:Encoding] )
 | 
			
		||||
				header + @buffer.to_s[@headless..-1]
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,100 +4,6 @@
 | 
			
		|||
 | 
			
		||||
module YAML
 | 
			
		||||
 | 
			
		||||
	#
 | 
			
		||||
	# Encodings ( $-K to ICONV )
 | 
			
		||||
	#
 | 
			
		||||
	CHARSETS = {
 | 
			
		||||
		'NONE' => 'LATIN1',
 | 
			
		||||
		'ASCII' => 'US-ASCII',
 | 
			
		||||
		'UTF-8' => 'UTF-8',
 | 
			
		||||
		'EUC' => 'EUC-JP',
 | 
			
		||||
		'SJIS' => 'SHIFT-JIS'
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	#
 | 
			
		||||
	# YAML documents can be in UTF-8, UTF-16 or UTF-32
 | 
			
		||||
	# So let's read and write in Unicode
 | 
			
		||||
	#
 | 
			
		||||
 | 
			
		||||
    @@unicode = false
 | 
			
		||||
	begin
 | 
			
		||||
		require 'iconv'
 | 
			
		||||
		DEFAULTS[:Encoding] = :Utf8
 | 
			
		||||
	rescue LoadError
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
    def YAML.unicode; @@unicode; end
 | 
			
		||||
    def YAML.unicode=( bool ); @@unicode = bool; end
 | 
			
		||||
 | 
			
		||||
	#
 | 
			
		||||
	# Unicode conversion
 | 
			
		||||
	#
 | 
			
		||||
    
 | 
			
		||||
	def YAML.utf_to_internal( str, from_enc )
 | 
			
		||||
		return unless str
 | 
			
		||||
		to_enc = CHARSETS[$-K]
 | 
			
		||||
		case from_enc
 | 
			
		||||
			when :Utf32
 | 
			
		||||
				Iconv.iconv( to_enc, 'UTF-32', str )[0]
 | 
			
		||||
			when :Utf16
 | 
			
		||||
				Iconv.iconv( to_enc, 'UTF-16', str )[0]
 | 
			
		||||
			when :Utf8
 | 
			
		||||
				Iconv.iconv( to_enc, 'UTF-8', str )[0]
 | 
			
		||||
			when :None
 | 
			
		||||
				str
 | 
			
		||||
			else
 | 
			
		||||
				raise YAML::Error, ERROR_UNSUPPORTED_ENCODING % from_enc.inspect
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	def YAML.internal_to_utf( str, to_enc )
 | 
			
		||||
		return unless str
 | 
			
		||||
		from_enc = CHARSETS[$-K]
 | 
			
		||||
		case to_enc
 | 
			
		||||
			when :Utf32
 | 
			
		||||
				Iconv.iconv( 'UTF-32', from_enc, str )[0]
 | 
			
		||||
			when :Utf16                        
 | 
			
		||||
				Iconv.iconv( 'UTF-16', from_enc, str )[0]
 | 
			
		||||
			when :Utf8                         
 | 
			
		||||
				Iconv.iconv( 'UTF-8', from_enc, str )[0]
 | 
			
		||||
			when :None
 | 
			
		||||
				str
 | 
			
		||||
			else
 | 
			
		||||
				raise YAML::Error, ERROR_UNSUPPORTED_ENCODING % to_enc.inspect
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	def YAML.sniff_encoding( str )
 | 
			
		||||
		unless YAML::unicode
 | 
			
		||||
			:None
 | 
			
		||||
		else
 | 
			
		||||
			case str
 | 
			
		||||
				when /^\x00\x00\xFE\xFF/	# UTF-32
 | 
			
		||||
					:Utf32
 | 
			
		||||
				when /^\xFE\xFF/	# UTF-32BE
 | 
			
		||||
					:Utf16
 | 
			
		||||
				else
 | 
			
		||||
					:Utf8
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	def YAML.enc_separator( enc )
 | 
			
		||||
		case enc
 | 
			
		||||
			when :Utf32
 | 
			
		||||
				"\000\000\000\n"
 | 
			
		||||
			when :Utf16
 | 
			
		||||
				"\000\n"
 | 
			
		||||
			when :Utf8
 | 
			
		||||
				"\n"
 | 
			
		||||
			when :None
 | 
			
		||||
				"\n"
 | 
			
		||||
			else
 | 
			
		||||
				raise YAML::Error, ERROR_UNSUPPORTED_ENCODING % enc.inspect
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	#
 | 
			
		||||
	# Escape the string, condensing common escapes
 | 
			
		||||
	#
 | 
			
		||||
| 
						 | 
				
			
			@ -109,7 +15,7 @@ module YAML
 | 
			
		|||
	# Unescape the condenses escapes
 | 
			
		||||
	#
 | 
			
		||||
	def YAML.unescape( value )
 | 
			
		||||
		value.gsub( /\\(?:([nevbr\\fartz])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) { |x| 
 | 
			
		||||
		value.gsub( /\\(?:([nevfbart\\])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) { |x| 
 | 
			
		||||
			if $3
 | 
			
		||||
				["#$3".hex ].pack('U*')
 | 
			
		||||
			elsif $2
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -295,20 +295,21 @@ class String
 | 
			
		|||
            if complex
 | 
			
		||||
                if self.is_binary_data?
 | 
			
		||||
                    out.binary_base64( self )
 | 
			
		||||
                elsif self =~ /^ |#{YAML::ESCAPE_CHAR}| $/
 | 
			
		||||
                    complex = false
 | 
			
		||||
                else
 | 
			
		||||
                    out.node_text( self )
 | 
			
		||||
                end
 | 
			
		||||
            else
 | 
			
		||||
            end
 | 
			
		||||
            if not complex
 | 
			
		||||
                ostr = 	if out.options[:KeepValue]
 | 
			
		||||
                            self
 | 
			
		||||
                        elsif empty?
 | 
			
		||||
                            "''"
 | 
			
		||||
                        elsif self =~ /^[^#{YAML::WORD_CHAR}]|#{YAML::ESCAPE_CHAR}|[#{YAML::SPACE_INDICATORS}]( |$)| $|\n|\'/
 | 
			
		||||
                            "\"#{YAML.escape( self )}\"" 
 | 
			
		||||
                        elsif YAML.detect_implicit( self ) != 'str'
 | 
			
		||||
                            "\"#{YAML.escape( self )}\"" 
 | 
			
		||||
                        elsif self =~ /#{YAML::ESCAPE_CHAR}|[#{YAML::SPACE_INDICATORS}] |\n|\'/
 | 
			
		||||
                            "\"#{YAML.escape( self )}\"" 
 | 
			
		||||
                        elsif self =~ /^[^#{YAML::WORD_CHAR}]/
 | 
			
		||||
                            "\"#{YAML.escape( self )}\"" 
 | 
			
		||||
                        else
 | 
			
		||||
                            self
 | 
			
		||||
                        end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue