<commit_before>

module("snowplow-payload")

function newPayloadBuilder (initial_value)

  local payload

  -- Type and value checks
  if type(initial_value) ~= "string" and initial_value ~= nil then
    error("initial_value must be a string or nil")
  end

  -- Initialize
  if initial_value then
    payload = initial_value
  else
    payload = ""
  end

  local add_nv_pair = function (key, value, encode)
    --[[--
    Helper to add a &name=value pair to our payload
    aka querystring. Closure around payload
    --]]--

    local a, v

    if value ~= nil and value ~= "" then
      if payload:len() > 0 then a = "&" else a = "" end

      -- TODO: add in encoding to the below
      if encode then v = value else v = value end

      payload = payload .. a .. key .. "=" .. v
    end
  end

  -- Return a table of closure functions to build
  -- our payload string.
  return {
    add = function (key, value)
            --[[--
            Add a &name=value pair with the value encoded,
            --]]--
            add_nv_pair(key, value, true)
          end,

    add_raw = function (key, value)
                --[[--
                Add a &name=value pair with the value
                not encoded.
                --]]--
                add_nv_pair(key, value, false)
              end,

    build = function ()
              --[[--
              Our "builder" returns the closed-over
              payload string.
              --]]--
              return payload<commit_msg>Some updates<commit_after>

module("snowplow-payload")

function newPayloadBuilder (initial_value)

  local payload

  -- Type and value checks
  if type(initialValue) ~= "string" and initialValue ~= nil then
    error("initial_value must be a string or nil")
  end

  -- Initialize
  if initialValue then
    payload = initialValue
  else
    payload = ""
  end

  local addNvPair = function (key, value, encode)
    --[[--
    Helper to add a &name=value pair to our payload
    aka querystring. Closure around payload
    --]]--

    local a, v

    if value ~= nil and value ~= "" then
      if payload:len() > 0 then a = "&" else a = "" end

      -- TODO: add in encoding to the below
      if encode then v = value else v = value end

      payload = payload .. a .. key .. "=" .. v
    end
  end

  -- Return a table of closure functions to build
  -- our payload string.
  return {
    add = function (key, value)
            --[[--
            Add a &name=value pair with the value encoded,
            --]]--
            addNvPair(key, value, true)
          end,

    addRaw = function (key, value)
                --[[--
                Add a &name=value pair with the value
                not encoded.
                --]]--
                addNvPair(key, value, false)
              end,

    build = function ()
              --[[--
              Our "builder" returns the closed-over
              payload string.
              --]]--
              return payload
{'fraction_non_alphanumeric': 0.1062542030934768, 'fraction_numerical': 0.0006724949562878278, 'mean_word_length': 1.5470890410958904, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3159517', 'n_tokens_mistral': 848, 'n_tokens_neox': 813, 'n_words': 302}