Jump to content

Module:Sandbox/Desb42

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Desb42 (talk | contribs) at 15:59, 23 November 2021. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}

function p.siteinfo(frame)
  return mw.site.siteName .. '--' .. '(' .. mw.site.server .. ')'
end

local serialize_replacements = {
	['\r'] = '\\r',
	['\n'] = '\\n',
	['\\'] = '\\\\',
	[' '] = 'X',
}

local dump_table_count = 0;
local function dump_table(o)
  if dump_table_count == 10 then
    return "overflow";
  end
  
  if type(o) == 'table' then
    local s = '{ '
    for k,v in pairs(o) do
      if type(k) == 'table' then
        k = dump_table(k)
      elseif type(k) ~= 'number' then
        k = '"'..k..'"'
      end
      dump_table_count = dump_table_count + 1;
      s = s .. '['..k..'] = ' .. dump_table(v) .. ','
      dump_table_count = dump_table_count - 1;
    end
    return s .. '} '
  else
  	st = tostring(o)
  	rst = st:gsub( '[\r\n\\ ]', serialize_replacements )
    return rst
  end
end

local diagnostic_preprocess_nested_data = ''
function mw.diagnostic_preprocess_nested(o)
  if o == 'clear' then
    diagnostic_preprocess_nested_data = ''
  elseif o == 'exec' then
    diagnostic_preprocess_nested_data = diagnostic_preprocess_nested_data .. 'once';
  end
  return diagnostic_preprocess_nested_data
end

function p.info(frame)
	mw.logObject(frame)
  return dump_table(frame)
end
local htmlencodeMap = {
	['>'] = '>',
	['<'] = '&lt;',
	['&'] = '&amp;',
	['"'] = '&quot;',
	[3] = 'XxX',
	[1] = 'ZzZ',
	[2] = 'YyY',
}

function p.ta(frame)
	s = 'abcdef&'
	s = '𐌰𐌽𐌰𐍃𐍄𐍉'
	a = mw.ustring.gsub( s, '()', htmlencodeMap )
	--a = mw.ustring.gsub("abcd", "b(.)()", "%1-%2")
	return s .. "|" .. a
end
function p.tb()
    mw.ustring.gsub("abcd", "a(bc)d", function(arg1)
        mw.log('basic', arg1); -- arg1 is the matched string or "bc"
    end)

    mw.ustring.gsub("abcd", "()bcd", function(arg1)
        mw.log('empty', arg1); -- arg1 is the position of the empty capture or "2"
    end)
end
function p.tc()
candidateString = 'Geography'
page, candidateArgs = mw.ustring.match(candidateString, "^%s*(%[%b[]%])%s*|?(.*)")
mw.log(page, candidateArgs )
page, candidateArgs = mw.ustring.match(candidateString, "%s*([^|]*[^|%s])%s*|?(.*)")
mw.log(page, candidateArgs )
c = '#d8d8d8'
c = mw.ustring.match(c, '^[%s#]*([a-f0-9]*)[%s]*$')
return c
end

return p