<commit_before>local current_folder = ... and (...):match '(.-%.?)[^%.]+$' or ''
local libquadtastic = require(current_folder.. ".libquadtastic")

-- Utility functions that don't deserve their own module

local common = {}

-- Load imagedata from outside the game's source and save folder
function common.load_imagedata(filepath)
  local filehandle, err = io.open(filepath, "rb")
  if err then
    error(err, 0)
  end
  local filecontent = filehandle:read("*a")
  filehandle:close()
  return love.image.newImageData(
    love.filesystem.newFileData(filecontent, 'img', 'file'))
end

-- Load an image from outside the game's source and save folder
function common.load_image(filepath)
  local imagedata = common.load_imagedata(filepath)
  return love.graphics.newImage(imagedata)
end

-- Split a filepath into the path of the containing directory and a filename.
-- Note that a trailing slash will result in an empty filename
function common.split(filepath)
  local dirname, basename = string.gmatch(filepath, "(.*/)([^/]*)")()
  return dirname, basename
end

-- Returns the filename without extension as the first return value, and the
-- extension as the second return value
function common.split_extension(filename)
  return string.gmatch(filename, "(.*)%.([^%.]*)")()
end

local function export_quad(handle, quadtable)
  handle(string.format(
    "{x = %d, y = %d, w = %d, h = %d}",
    quadtable.x, quadtable.y, quadtable.w, quadtable.h))
end

local function escape(str)
  str = string.gsub(str, "\\", "\\\\")
  str = string.gsub(str, "\"", "\\\"")
  return str
end
<commit_msg>Add function to check if a string is a valid Lua Name<commit_after>local current_folder = ... and (...):match '(.-%.?)[^%.]+$' or ''
local libquadtastic = require(current_folder.. ".libquadtastic")

-- Utility functions that don't deserve their own module

local common = {}

-- Load imagedata from outside the game's source and save folder
function common.load_imagedata(filepath)
  local filehandle, err = io.open(filepath, "rb")
  if err then
    error(err, 0)
  end
  local filecontent = filehandle:read("*a")
  filehandle:close()
  return love.image.newImageData(
    love.filesystem.newFileData(filecontent, 'img', 'file'))
end

-- Load an image from outside the game's source and save folder
function common.load_image(filepath)
  local imagedata = common.load_imagedata(filepath)
  return love.graphics.newImage(imagedata)
end

-- Split a filepath into the path of the containing directory and a filename.
-- Note that a trailing slash will result in an empty filename
function common.split(filepath)
  local dirname, basename = string.gmatch(filepath, "(.*/)([^/]*)")()
  return dirname, basename
end

-- Returns the filename without extension as the first return value, and the
-- extension as the second return value
function common.split_extension(filename)
  return string.gmatch(filename, "(.*)%.([^%.]*)")()
end

local function export_quad(handle, quadtable)
  handle(string.format(
    "{x = %d, y = %d, w = %d, h = %d}",
    quadtable.x, quadtable.y, quadtable.w, quadtable.h))
end

-- Checks if a given string qualifies as a Lua Name, see "Lexical Conventions"
function common.is_lua_Name(str)
  -- Names (also called identifiers) in Lua can be any string of letters,
  -- digits, and underscores, not beginning with a digit.
  -- http://www.lua.org/manual/5.1/manual.html#2.1
  return str and str == string.gmatch(str, "[A-Za-z_][A-Za-z0-9_]*")()
end

local function escape(str)
  str = string.gsub(str, "\\", "\\\\")
  str = string.gsub(str, "\"", "\\\"")
  return str
end

{'fraction_non_alphanumeric': 0.14097902097902099, 'fraction_numerical': 0.0022377622377622378, 'mean_word_length': 4.072340425531915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '6304335', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1130, 'n_words': 366}