module JSON::TruffleRuby::Generator

def self.utf8_to_json(string, script_safe = false) # :nodoc:

:nodoc:
UTF16 big endian characters as \u????, and return it.
Convert a UTF8 encoded Ruby string _string_ to a JSON string, encoded with
def self.utf8_to_json(string, script_safe = false) # :nodoc:
  if script_safe
    if SCRIPT_SAFE_ESCAPE_PATTERN.match?(string)
      string.gsub(SCRIPT_SAFE_ESCAPE_PATTERN, SCRIPT_SAFE_MAP)
    else
      string
    end
  else
    if /["\\\x0-\x1f]/.match?(string)
      string.gsub(/["\\\x0-\x1f]/, MAP)
    else
      string
    end
  end
end