X7ROOT File Manager
Current Path:
/opt/alt/ruby19/lib64/ruby/1.9.1
opt
/
alt
/
ruby19
/
lib64
/
ruby
/
1.9.1
/
??
..
??
English.rb
(5.59 KB)
??
abbrev.rb
(2.57 KB)
??
base64.rb
(2.63 KB)
??
benchmark.rb
(18 KB)
??
cgi
??
cgi.rb
(9.3 KB)
??
cmath.rb
(7.22 KB)
??
complex.rb
(380 B)
??
csv.rb
(82.66 KB)
??
date
??
date.rb
(946 B)
??
debug.rb
(23.23 KB)
??
delegate.rb
(9.74 KB)
??
digest
??
digest.rb
(2.24 KB)
??
dl
??
dl.rb
(176 B)
??
drb
??
drb.rb
(19 B)
??
e2mmap.rb
(3.8 KB)
??
erb.rb
(25.72 KB)
??
expect.rb
(1.33 KB)
??
fiddle
??
fiddle.rb
(928 B)
??
fileutils.rb
(45.32 KB)
??
find.rb
(2.03 KB)
??
forwardable.rb
(7.64 KB)
??
getoptlong.rb
(15.38 KB)
??
gserver.rb
(8.83 KB)
??
ipaddr.rb
(24.92 KB)
??
irb
??
irb.rb
(8.34 KB)
??
json
??
json.rb
(1.74 KB)
??
kconv.rb
(5.74 KB)
??
logger.rb
(20.85 KB)
??
mathn.rb
(6.52 KB)
??
matrix
??
matrix.rb
(47.65 KB)
??
mkmf.rb
(68.9 KB)
??
monitor.rb
(6.94 KB)
??
mutex_m.rb
(1.61 KB)
??
net
??
observer.rb
(5.69 KB)
??
open-uri.rb
(25.84 KB)
??
open3.rb
(20.64 KB)
??
openssl
??
openssl.rb
(547 B)
??
optparse
??
optparse.rb
(51.13 KB)
??
ostruct.rb
(6.49 KB)
??
pathname.rb
(14.21 KB)
??
pp.rb
(13.31 KB)
??
prettyprint.rb
(9.63 KB)
??
prime.rb
(13.98 KB)
??
profile.rb
(205 B)
??
profiler.rb
(1.59 KB)
??
pstore.rb
(15.81 KB)
??
psych
??
psych.rb
(9.82 KB)
??
racc
??
rake
??
rake.rb
(2.02 KB)
??
rational.rb
(308 B)
??
rbconfig
??
rdoc
??
rdoc.rb
(4.29 KB)
??
resolv-replace.rb
(1.74 KB)
??
resolv.rb
(59.91 KB)
??
rexml
??
rinda
??
ripper
??
ripper.rb
(91 B)
??
rss
??
rss.rb
(2.84 KB)
??
rubygems
??
rubygems.rb
(34.13 KB)
??
scanf.rb
(23.53 KB)
??
securerandom.rb
(8.46 KB)
??
set.rb
(29.91 KB)
??
shell
??
shell.rb
(5.9 KB)
??
shellwords.rb
(3.88 KB)
??
singleton.rb
(4.02 KB)
??
socket.rb
(23.22 KB)
??
syck
??
syck.rb
(13.91 KB)
??
sync.rb
(6.87 KB)
??
tempfile.rb
(10.42 KB)
??
test
??
thread.rb
(6.59 KB)
??
thwait.rb
(3.38 KB)
??
time.rb
(17.03 KB)
??
timeout.rb
(3.26 KB)
??
tmpdir.rb
(3.72 KB)
??
tracer.rb
(6.63 KB)
??
tsort.rb
(6.79 KB)
??
ubygems.rb
(268 B)
??
un.rb
(8.32 KB)
??
uri
??
uri.rb
(3.07 KB)
??
weakref.rb
(2.29 KB)
??
webrick
??
webrick.rb
(6.8 KB)
??
x86_64-linux
??
xmlrpc
??
yaml
??
yaml.rb
(2.58 KB)
Editing: prettyprint.rb
# This class implements a pretty printing algorithm. It finds line breaks and # nice indentations for grouped structure. # # By default, the class assumes that primitive elements are strings and each # byte in the strings have single column in width. But it can be used for # other situations by giving suitable arguments for some methods: # * newline object and space generation block for PrettyPrint.new # * optional width argument for PrettyPrint#text # * PrettyPrint#breakable # # There are several candidate uses: # * text formatting using proportional fonts # * multibyte characters which has columns different to number of bytes # * non-string formatting # # == Bugs # * Box based formatting? # * Other (better) model/algorithm? # # == References # Christian Lindig, Strictly Pretty, March 2000, # http://www.st.cs.uni-sb.de/~lindig/papers/#pretty # # Philip Wadler, A prettier printer, March 1998, # http://homepages.inf.ed.ac.uk/wadler/topics/language-design.html#prettier # # == Author # Tanaka Akira <akr@m17n.org> # class PrettyPrint # This is a convenience method which is same as follows: # # begin # q = PrettyPrint.new(output, maxwidth, newline, &genspace) # ... # q.flush # output # end # def PrettyPrint.format(output='', maxwidth=79, newline="\n", genspace=lambda {|n| ' ' * n}) q = PrettyPrint.new(output, maxwidth, newline, &genspace) yield q q.flush output end # This is similar to PrettyPrint::format but the result has no breaks. # # +maxwidth+, +newline+ and +genspace+ are ignored. # # The invocation of +breakable+ in the block doesn't break a line and is # treated as just an invocation of +text+. # def PrettyPrint.singleline_format(output='', maxwidth=nil, newline=nil, genspace=nil) q = SingleLine.new(output) yield q output end # Creates a buffer for pretty printing. # # +output+ is an output target. If it is not specified, '' is assumed. It # should have a << method which accepts the first argument +obj+ of # PrettyPrint#text, the first argument +sep+ of PrettyPrint#breakable, the # first argument +newline+ of PrettyPrint.new, and the result of a given # block for PrettyPrint.new. # # +maxwidth+ specifies maximum line length. If it is not specified, 79 is # assumed. However actual outputs may overflow +maxwidth+ if long # non-breakable texts are provided. # # +newline+ is used for line breaks. "\n" is used if it is not specified. # # The block is used to generate spaces. {|width| ' ' * width} is used if it # is not given. # def initialize(output='', maxwidth=79, newline="\n", &genspace) @output = output @maxwidth = maxwidth @newline = newline @genspace = genspace || lambda {|n| ' ' * n} @output_width = 0 @buffer_width = 0 @buffer = [] root_group = Group.new(0) @group_stack = [root_group] @group_queue = GroupQueue.new(root_group) @indent = 0 end attr_reader :output, :maxwidth, :newline, :genspace attr_reader :indent, :group_queue # Returns the group most recently added to the stack. def current_group @group_stack.last end # first? is a predicate to test the call is a first call to first? with # current group. # # It is useful to format comma separated values as: # # q.group(1, '[', ']') { # xxx.each {|yyy| # unless q.first? # q.text ',' # q.breakable # end # ... pretty printing yyy ... # } # } # # first? is obsoleted in 1.8.2. # def first? warn "PrettyPrint#first? is obsoleted at 1.8.2." current_group.first? end # Breaks the buffer into lines that are shorter than #maxwidth def break_outmost_groups while @maxwidth < @output_width + @buffer_width return unless group = @group_queue.deq until group.breakables.empty? data = @buffer.shift @output_width = data.output(@output, @output_width) @buffer_width -= data.width end while !@buffer.empty? && Text === @buffer.first text = @buffer.shift @output_width = text.output(@output, @output_width) @buffer_width -= text.width end end end # This adds +obj+ as a text of +width+ columns in width. # # If +width+ is not specified, obj.length is used. # def text(obj, width=obj.length) if @buffer.empty? @output << obj @output_width += width else text = @buffer.last unless Text === text text = Text.new @buffer << text end text.add(obj, width) @buffer_width += width break_outmost_groups end end # This is similar to #breakable except # the decision to break or not is determined individually. # # Two #fill_breakable under a group may cause 4 results: # (break,break), (break,non-break), (non-break,break), (non-break,non-break). # This is different to #breakable because two #breakable under a group # may cause 2 results: # (break,break), (non-break,non-break). # # The text sep+ is inserted if a line is not broken at this point. # # If +sep+ is not specified, " " is used. # # If +width+ is not specified, +sep.length+ is used. You will have to # specify this when +sep+ is a multibyte character, for example. # def fill_breakable(sep=' ', width=sep.length) group { breakable sep, width } end # This says "you can break a line here if necessary", and a +width+\-column # text +sep+ is inserted if a line is not broken at the point. # # If +sep+ is not specified, " " is used. # # If +width+ is not specified, +sep.length+ is used. You will have to # specify this when +sep+ is a multibyte character, for example. # def breakable(sep=' ', width=sep.length) group = @group_stack.last if group.break? flush @output << @newline @output << @genspace.call(@indent) @output_width = @indent @buffer_width = 0 else @buffer << Breakable.new(sep, width, self) @buffer_width += width break_outmost_groups end end # Groups line break hints added in the block. The line break hints are all # to be used or not. # # If +indent+ is specified, the method call is regarded as nested by # nest(indent) { ... }. # # If +open_obj+ is specified, <tt>text open_obj, open_width</tt> is called # before grouping. If +close_obj+ is specified, <tt>text close_obj, # close_width</tt> is called after grouping. # def group(indent=0, open_obj='', close_obj='', open_width=open_obj.length, close_width=close_obj.length) text open_obj, open_width group_sub { nest(indent) { yield } } text close_obj, close_width end def group_sub group = Group.new(@group_stack.last.depth + 1) @group_stack.push group @group_queue.enq group begin yield ensure @group_stack.pop if group.breakables.empty? @group_queue.delete group end end end # Increases left margin after newline with +indent+ for line breaks added in # the block. # def nest(indent) @indent += indent begin yield ensure @indent -= indent end end # outputs buffered data. # def flush @buffer.each {|data| @output_width = data.output(@output, @output_width) } @buffer.clear @buffer_width = 0 end class Text def initialize @objs = [] @width = 0 end attr_reader :width def output(out, output_width) @objs.each {|obj| out << obj} output_width + @width end def add(obj, width) @objs << obj @width += width end end class Breakable def initialize(sep, width, q) @obj = sep @width = width @pp = q @indent = q.indent @group = q.current_group @group.breakables.push self end attr_reader :obj, :width, :indent def output(out, output_width) @group.breakables.shift if @group.break? out << @pp.newline out << @pp.genspace.call(@indent) @indent else @pp.group_queue.delete @group if @group.breakables.empty? out << @obj output_width + @width end end end class Group def initialize(depth) @depth = depth @breakables = [] @break = false end attr_reader :depth, :breakables def break @break = true end def break? @break end def first? if defined? @first false else @first = false true end end end class GroupQueue def initialize(*groups) @queue = [] groups.each {|g| enq g} end def enq(group) depth = group.depth @queue << [] until depth < @queue.length @queue[depth] << group end def deq @queue.each {|gs| (gs.length-1).downto(0) {|i| unless gs[i].breakables.empty? group = gs.slice!(i, 1).first group.break return group end } gs.each {|group| group.break} gs.clear } return nil end def delete(group) @queue[group.depth].delete(group) end end class SingleLine def initialize(output, maxwidth=nil, newline=nil) @output = output @first = [true] end def text(obj, width=nil) @output << obj end def breakable(sep=' ', width=nil) @output << sep end def nest(indent) yield end def group(indent=nil, open_obj='', close_obj='', open_width=nil, close_width=nil) @first.push true @output << open_obj yield @output << close_obj @first.pop end def flush end def first? result = @first[-1] @first[-1] = false result end end end
Upload File
Create Folder