<commit_before>#This class was heavily inspired by the great Dipth! https://github.com/dipth
class WindowsCsv
  ENCODING = Encoding::UTF_8
  
  BOM = "\377\376".force_encoding(Encoding::UTF_16LE) # Byte Order Mark
  COL_SEP = "\t"
  QUOTE_CHAR = "\""
  
  def self.foreach(path, args = {})
    require "rubygems"
    require "csv_lazy"
    
    File.open(path, "rb:bom|utf-16le") do |fp|
      csv_args = {:debug => false, :io => fp, :col_sep => COL_SEP, :quote_char => QUOTE_CHAR}
      csv_args.merge!(args[:csv_args]) if args[:csv_args]
      
      Csv_lazy.new(csv_args) do |row|
        real = []
        row.each do |col|
          real << col
        end
        
        yield row
      end
    end
    
    nil
  end
  
  def initialize(args)
    require "csv"
    
    @args = args
    
    if @args[:path]
      fp = File.open(@args[:path], "w", :encoding => ENCODING)
      @args[:io] = fp
    end
    
    begin
      @args[:io].write(BOM)
      yield self
    ensure
      fp.close if fp
    end
  end
  
  def <<(row)
    encoded = []
    
    row.each do |col|
      if col.is_a?(Time) or col.is_a?(DateTime)
        encoded << col.strftime("%Y-%m-%d %H:%M")
      elsif col.is_a?(Date)
        encoded << col.strftime("%Y-%m-%d")
      else
        encoded << WindowsCsv.escape(col)
      end
    end
    
    @args[:io].puts CSV.generate_line(encoded, :col_sep => COL_SEP, :quote_char => QUOTE_CHAR, :force_quotes => true).encode(Encoding::UTF_16LE)<commit_msg>No longer forcing quotes.<commit_after>#This class was heavily inspired by the great Dipth! https://github.com/dipth
class WindowsCsv
  ENCODING = Encoding::UTF_8
  
  BOM = "\377\376".force_encoding(Encoding::UTF_16LE) # Byte Order Mark
  COL_SEP = "\t"
  QUOTE_CHAR = "\""
  
  def self.foreach(path, args = {})
    require "rubygems"
    require "csv_lazy"
    
    File.open(path, "rb:bom|utf-16le") do |fp|
      csv_args = {:debug => false, :io => fp, :col_sep => COL_SEP, :quote_char => QUOTE_CHAR}
      csv_args.merge!(args[:csv_args]) if args[:csv_args]
      
      Csv_lazy.new(csv_args) do |row|
        real = []
        row.each do |col|
          real << col
        end
        
        yield row
      end
    end
    
    nil
  end
  
  def initialize(args)
    require "csv"
    
    @args = args
    
    if @args[:path]
      fp = File.open(@args[:path], "w", :encoding => ENCODING)
      @args[:io] = fp
    end
    
    begin
      @args[:io].write(BOM)
      yield self
    ensure
      fp.close if fp
    end
  end
  
  def <<(row)
    encoded = []
    
    row.each do |col|
      if col.is_a?(Time) or col.is_a?(DateTime)
        encoded << col.strftime("%Y-%m-%d %H:%M")
      elsif col.is_a?(Date)
        encoded << col.strftime("%Y-%m-%d")
      else
        encoded << WindowsCsv.escape(col)
      end
    end
    
    @args[:io].puts CSV.generate_line(encoded, :col_sep => COL_SEP, :quote_char => QUOTE_CHAR).encode(Encoding::UTF_16LE)
{'fraction_non_alphanumeric': 0.14343845371312308, 'fraction_numerical': 0.008816547982366904, 'mean_word_length': 2.165236051502146, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 18, 'https://': 2, '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': '3468599', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1076, 'n_words': 234}