Sha256: 1dcadecc2b039f3ec486e21f43cd66abe840909c0cf6b83a6b7e3e820fc34662

Contents?: true

Size: 757 Bytes

Versions: 10

Compression:

Stored size: 757 Bytes

Contents

class String

  # Breaks a string up into an array based on a regular expression.
  # Similar to scan, but includes the matches.
  #
  #   s = "<p>This<b>is</b>a test.</p>"
  #   s.divide( /\<.*?\>/ )
  #
  # _produces_
  #
  #   ["<p>This", "<b>is", "</b>a test.", "</p>"]
  #
  def divide( re )
    re2 = /#{re}.*?(?=#{re}|\Z)/
    self.scan(re2) #{re}(?=#{re})/)
  end

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCString < Test::Unit::TestCase

    def test_shatter
      s = "<p>This<b>is</b>a test.</p>"
      sh = s.divide( /<.*?>/ )
      e = ["<p>This", "<b>is", "</b>a test.", "</p>"]
      assert_equal(e, sh)
    end

  end

=end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facets-1.7.0 lib/facets/core/string/divide.rb
facets-1.7.30 lib/facets/core/string/divide.rb
facets-1.7.38 lib/facets/core/string/divide.rb
facets-1.7.46 lib/facets/core/string/divide.rb
facets-1.8.49 lib/facets/core/string/divide.rb
facets-1.8.0 lib/facets/core/string/divide.rb
facets-1.8.20 lib/facets/core/string/divide.rb
facets-1.8.51 lib/facets/core/string/divide.rb
facets-1.8.8 lib/facets/core/string/divide.rb
facets-1.8.54 lib/facets/core/string/divide.rb