<commit_before># -*- encoding : utf-8 -*-

require "bindata"

# A cursor to walk through data structures to read fields. The cursor can move
# forwards, backwards, is seekable, and supports peeking without moving the
# cursor. The BinData module is used for interpreting bytes as desired.
class BufferCursor
  VERSION = "0.9.0"

  # An entry in a stack of cursors. The cursor position, direction, and
  # name array are each attributes of the current cursor stack and are
  # manipulated together.
  class StackEntry
    attr_accessor :cursor
    attr_accessor :position
    attr_accessor :direction
    attr_accessor :name

    def initialize(cursor, position=0, direction=:forward, name=nil)
      @cursor = cursor
      @position = position
      @direction = direction
      @name = name || []
    end

    def dup
      StackEntry.new(cursor, position, direction, name.dup)
    end
  end

  @@global_tracing = false

  # Enable tracing for all BufferCursor objects globally.
  def self.trace!(arg=true)
    @@global_tracing = arg
  end

  # Initialize a cursor within a buffer at the given position.
  def initialize(buffer, position)
    @buffer = buffer
    @stack = [ StackEntry.new(self, position) ]

    trace false
    trace_with :print_trace
    trace_to STDOUT
  end

  def trace(arg=true)
    @instance_tracing = arg
    self<commit_msg>Add inspect method for BufferCursor<commit_after># -*- encoding : utf-8 -*-

require "bindata"

# A cursor to walk through data structures to read fields. The cursor can move
# forwards, backwards, is seekable, and supports peeking without moving the
# cursor. The BinData module is used for interpreting bytes as desired.
class BufferCursor
  VERSION = "0.9.0"

  # An entry in a stack of cursors. The cursor position, direction, and
  # name array are each attributes of the current cursor stack and are
  # manipulated together.
  class StackEntry
    attr_accessor :cursor
    attr_accessor :position
    attr_accessor :direction
    attr_accessor :name

    def initialize(cursor, position=0, direction=:forward, name=nil)
      @cursor = cursor
      @position = position
      @direction = direction
      @name = name || []
    end

    def inspect
      "<%s direction=%s position=%s>" % [
        self.class.name,
        @direction.inspect,
        @position,
      ]
    end

    def dup
      StackEntry.new(cursor, position, direction, name.dup)
    end
  end

  @@global_tracing = false

  # Enable tracing for all BufferCursor objects globally.
  def self.trace!(arg=true)
    @@global_tracing = arg
  end

  # Initialize a cursor within a buffer at the given position.
  def initialize(buffer, position)
    @buffer = buffer
    @stack = [ StackEntry.new(self, position) ]

    trace false
    trace_with :print_trace
    trace_to STDOUT
  end

  def inspect
    "<%s size=%i current=%s>" % [
      self.class.name,
      @buffer.size,
      current.inspect,
    ]
  end

  def trace(arg=true)
    @instance_tracing = arg
    self
{'fraction_non_alphanumeric': 0.08072048032021348, 'fraction_numerical': 0.00333555703802535, 'mean_word_length': 2.988031914893617, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1057381', 'n_tokens_mistral': 885, 'n_tokens_neox': 848, 'n_words': 313}