Skip to content

add non-UTF-8 escaping to toLua #12

Description

@7aGiven

add a config for toLua for non-UTF-8 escape to hex.

-- lua-parser internal function
function escape(s)
  if checkutf8 and utf8.len(s) == nil then
    local r = ""
    for i=1, #s do
      r = r .. string.format("\\x%02X", string.byte(s, i))
    end
    return r
  else
    return defaultEscape(s)
  end
end
--
toLua()

or allow custom escape

function escape(s, default)
  if utf8.len(s) == nil then
    local r = ""
    for i=1, #s do
      r = r .. string.format("\\x%02X", string.byte(s, i))
    end
    return r
  else
    return default(s)
  end
end
toLua({escape=escape})

or custom function return nil for default

function escape(s)
  if utf8.len(s) == nil then
    local r = ""
    for i=1, #s do
      r = r .. string.format("\\x%02X", string.byte(s, i))
    end
    return r
  else
    return nil
  end
end
toLua({escape=escape})

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions