<commit_before>require 'active_support/core_ext/string/output_safety'

require "fast_safe_buffer/version"
require "fast_safe_buffer_ext"

class FastSafeBuffer
  class SafeConcatError < StandardError
    def initialize
      super 'Could not concatenate to the buffer because it is not html safe.'
    end
  end

  def initialize(buffer=nil)
    concat buffer if buffer
  end

  def safe_concat(value)
    raise SafeConcatError unless html_safe?
    unsafe_concat(value)
  end

  def to_s
    to_str
  end

  def to_param
    to_str
  end

  def clone_empty
    self.class.new
  end

  def encode_with(coder)
    coder.represent_scalar nil, to_str
  end

  def force_encoding(encoding)
    encoding = Encoding.find(encoding)
    raise EncodingError.new("buffer only supports UTF-8 encoding") unless encoding == Encoding::UTF_8
    self
  end

  def encoding
    Encoding::UTF_8
  end
end<commit_msg>Add aliases used in ERB.<commit_after>require 'active_support/core_ext/string/output_safety'

require "fast_safe_buffer/version"
require "fast_safe_buffer_ext"

class FastSafeBuffer
  class SafeConcatError < StandardError
    def initialize
      super 'Could not concatenate to the buffer because it is not html safe.'
    end
  end

  def initialize(buffer=nil)
    concat buffer if buffer
  end

  # Aliases used in ERB
  alias :append= :<<
  alias :safe_append= :safe_concat

  def safe_concat(value)
    raise SafeConcatError unless html_safe?
    unsafe_concat(value)
  end

  def to_s
    to_str
  end

  def to_param
    to_str
  end

  def clone_empty
    self.class.new
  end

  def encode_with(coder)
    coder.represent_scalar nil, to_str
  end

  def force_encoding(encoding)
    encoding = Encoding.find(encoding)
    raise EncodingError.new("buffer only supports UTF-8 encoding") unless encoding == Encoding::UTF_8
    self
  end

  def encoding
    Encoding::UTF_8
  end

  def encode!
    # noop
    self
  end
end
{'fraction_non_alphanumeric': 0.05702436495593572, 'fraction_numerical': 0.003110419906687403, 'mean_word_length': 3.3963553530751707, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '7185226', 'n_tokens_mistral': 642, 'n_tokens_neox': 611, 'n_words': 179}