Sha256: ee82622f1b749e6c39a525ea5328f665415e634f897a971db3d766b1d4f71b7e

Contents?: true

Size: 595 Bytes

Versions: 15

Compression:

Stored size: 595 Bytes

Contents

class String

  # Like index but returns an array of all index locations.
  # The reuse flag allows the trailing portion of a match to be
  # reused for subsquent matches.
  #
  #   "abcabcabc".index_all('a')  #=> [0,3,6]
  #
  #   "bbb".index_all('bb', false)  #=> [0]
  #   "bbb".index_all('bb', true)   #=> [0,1]
  #
  # TODO: Culd probably be defined for Indexable in general too.

  def index_all(s, reuse=false)
    s = Regexp.new(Regexp.escape(s)) unless Regexp===s
    ia = []; i = 0
    while (i = index(s,i))
      ia << i
      i += (reuse ? 1 : $~[0].size)
    end
    ia
  end

end

Version data entries

15 entries across 14 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/string/index_all.rb
facets-3.1.0 lib/core/facets/string/index_all.rb
facets-3.0.0 lib/core/facets/string/index_all.rb
facets-2.9.3 lib/core/facets/string/index_all.rb
facets-2.9.2 lib/core/facets/string/index_all.rb
facets-2.9.2 src/core/facets/string/index_all.rb
facets-2.9.1 lib/core/facets/string/index_all.rb
facets-2.9.0 lib/core/facets/string/index_all.rb
facets-2.9.0.pre.2 lib/core/facets/string/index_all.rb
facets-2.9.0.pre.1 lib/core/facets/string/index_all.rb
facets-2.8.4 lib/core/facets/string/index_all.rb
facets-2.8.3 lib/core/facets/string/index_all.rb
facets-2.8.2 lib/core/facets/string/index_all.rb
facets-2.8.1 lib/core/facets/string/index_all.rb
facets-2.8.0 lib/core/facets/string/index_all.rb