vendor/bundle/ruby/2.6.0/gems/coderay-1.1.3/lib/coderay/tokens.rb
def split_into_parts *sizes
      return Array.new(sizes.size) { Tokens.new } if size == 2 && first == ''
      parts = []
      opened = []
      content = nil
      part = Tokens.new
      part_size = 0
      size = sizes.first
      i = 0
      for item in self
        case content
        when nil
          content = item
        when String
          if size && part_size + content.size > size  # token must be cut
            if part_size < size  # some part of the token goes into this part
              content = content.dup  # content may no be safe to change
              part << content.slice!(0, size - part_size) << item
            end
            # close all open groups and lines...
            closing = opened.reverse.flatten.map do |content_or_kind|
              case content_or_kind
              when :begin_group
                :end_group
              when :begin_line
                :end_line
              else
                content_or_kind
              end
            end
            part.concat closing
            begin
              parts << part
              part = Tokens.new
              size = sizes[i += 1]
            end until size.nil? || size > 0
            # ...and open them again.
            part.concat opened.flatten
            part_size = 0
            redo unless content.empty?
          else
            part << content << item
            part_size += content.size
          end
          content = nil
        when Symbol
          case content
          when :begin_group, :begin_line
            opened << [content, item]
          when :end_group, :end_line
            opened.pop
          else
            raise ArgumentError, 'Unknown token action: %p, kind = %p' % [content, item]
          end
          part << content << item
          content = nil
        else
          raise ArgumentError, 'Token input junk: %p, kind = %p' % [content, item]
        end
      end
      parts << part
      parts << Tokens.new while parts.size < sizes.size
      parts
    end
# Split the tokens into parts of the given +sizes+.
# 
# The result will be an Array of Tokens objects. The parts have
# the text size specified by the parameter. In addition, each
# part closes all opened tokens. This is useful to insert tokens
# betweem them.
# 
# This method is used by @Scanner#tokenize@ when called with an Array
# of source strings. The Diff encoder uses it for inline highlighting.
Split the tokens into parts of the given +sizes+.
The result will be an Array of Tokens objects. The parts have
the text size specified by the parameter. In addition, each
part closes all opened tokens. This is useful to insert tokens
betweem them.

This method is used by @Scanner#tokenize@ when called with an Array
of source strings. The Diff encoder uses it for inline highlighting.
Split the tokens into parts of the given + sizes + . The result will be an Array of Tokens objects . The parts have the text size specified by the parameter . In addition each part closes all opened tokens . This is useful to insert tokens betweem them . This method is used by @Scanner#tokenize@ when called with an Array of source strings . The Diff encoder uses it for inline highlighting .
def split_into_parts *sizes
      return Array.new(sizes.size) { Tokens.new } if size == 2 && first == ''
      parts = []
      opened = []
      content = nil
      part = Tokens.new
      part_size = 0
      size = sizes.first
      i = 0
      for item in self
        case content
        when nil
          content = item
        when String
          if size && part_size + content.size > size  
            if part_size < size  
              content = content.dup  
              part << content.slice!(0, size - part_size) << item
            end
            closing = opened.reverse.flatten.map do |content_or_kind|
              case content_or_kind
              when :begin_group
                :end_group
              when :begin_line
                :end_line
              else
                content_or_kind
              end
            end
            part.concat closing
            begin
              parts << part
              part = Tokens.new
              size = sizes[i += 1]
            end until size.nil? || size > 0
            part.concat opened.flatten
            part_size = 0
            redo unless content.empty?
          else
            part << content << item
            part_size += content.size
          end
          content = nil
        when Symbol
          case content
          when :begin_group, :begin_line
            opened << [content, item]
          when :end_group, :end_line
            opened.pop
          else
            raise ArgumentError, 'Unknown token action: %p, kind = %p' % [content, item]
          end
          part << content << item
          content = nil
        else
          raise ArgumentError, 'Token input junk: %p, kind = %p' % [content, item]
        end
      end
      parts << part
      parts << Tokens.new while parts.size < sizes.size
      parts
    end
def split_into_parts * sizes return Array . new ( sizes . size ) { Tokens . new } if size == 2 && first == '' parts = [ ] opened = [ ] content = nil part = Tokens . new part_size = 0 size = sizes . first i = 0 for item in self case content when nil content = item when String if size && part_size + content . size > size if part_size < size content = content . dup part << content . slice! ( 0 , size - part_size ) << item end closing = opened . reverse . flatten . map do | content_or_kind | case content_or_kind when :begin_group :end_group when :begin_line :end_line else content_or_kind end end part . concat closing begin parts << part part = Tokens . new size = sizes [ i += 1 ] end until size . nil? || size > 0 part . concat opened . flatten part_size = 0 redo unless content . empty? else part << content << item part_size += content . size end content = nil when Symbol case content when :begin_group , :begin_line opened << [ content , item ] when :end_group , :end_line opened . pop else raise ArgumentError , 'Unknown token action: %p, kind = %p' % [ content , item ] end part << content << item content = nil else raise ArgumentError , 'Token input junk: %p, kind = %p' % [ content , item ] end end parts << part parts << Tokens . new while parts . size < sizes . size parts end
Split the tokens into parts of the given +sizes+.
Split the tokens into parts of the given + sizes + .
# token must be cut # some part of the token goes into this part # content may no be safe to change # close all open groups and lines... # ...and open them again.
sizes