Sha256: 76609ba9a5f1fba1ea86d02d5fb10c1a936ec4957471212e21159b58f871d349

Contents?: true

Size: 744 Bytes

Versions: 4

Compression:

Stored size: 744 Bytes

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

module TwitterCldr
  module Segmentation
    class Cursor
      attr_reader :text, :codepoints
      attr_accessor :position

      def initialize(text)
        @text = text
        @codepoints = text.codepoints
        reset
      end

      def advance(amount = 1)
        if @position + amount > text.size
          @position = text.size
        else
          @position += amount
        end
      end

      def reset
        @position = 0
      end

      def eos?
        position >= text.size
      end

      def codepoint(pos = @position)
        codepoints[pos]
      end

      def length
        text.length
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
twitter_cldr-6.12.1 lib/twitter_cldr/segmentation/cursor.rb
twitter_cldr-6.12.0 lib/twitter_cldr/segmentation/cursor.rb
twitter_cldr-6.11.5 lib/twitter_cldr/segmentation/cursor.rb
twitter_cldr-6.11.4 lib/twitter_cldr/segmentation/cursor.rb