このテンプレートは、以下のLuaモジュールを使用しています。 |
このモジュールは、リンクを生成するモジュールで使用される基本的な関数を提供します。
使用状況
このモジュールを使用しているモジュールは以下の通りです:
関数
function lu.splitItems( s, delimiters, defaultDelimiter )
s: string;
delimiters: array;
defaultDelimiter: string;
文字列 s
を要素ごとに分割し、その結果の配列を返します。デフォルトの区切り文字(カンマが指定されていない場合)に加えて追加の区切り文字を含む両方が区切り文字として使用されます。括弧の区切り文字は考慮されません。
function lu.extractComment( s )
s: string;
括弧で囲まれたコメントとその前の文字列を分離します。返り値はコメントを除いた文字列とコメント部分の2つになります。
function lu.errorInfo( catPrefix, aCat, aClass )
catPrefix: string;
aCat: string;
aClass: string;
標準名前空間またはモジュール名前空間にエラーメッセージ aCat
を出力し、メンテナンスカテゴリを追加します。エラーメッセージを含む文字列は、クラス aClass
が付与された <span>
タグで囲まれています。クラスが指定されていない場合、error
クラスが使用されます。モジュールパラメータ demo
によって、カテゴリを作成するか単にリンクするかが決定されます。
この解説は、モジュール:Link utilities/docから呼び出されています。 (編集 | 履歴) 編集者は、このモジュールをサンドボックス (作成 | 複製)とテストケース (作成)で試すことができます。(解説) このモジュールのサブページ一覧。 |
-- module variable and administration local lu = { moduleInterface = { suite = 'Link utilities', serial = '2023-12-09', item = 65228027 } } -- module import local li = require( 'Module:Link utilities/i18n' ) -- require( 'strict' ) -- split separate items like numbers function lu.splitItems( s, delimiters, defaultDelimiter ) defaultDelimiter = defaultDelimiter or ',' -- wrap delimiters with zero marks s = mw.ustring.gsub( s, defaultDelimiter, '\0%1\0' ); -- substitude delimiters for i, delimiter in ipairs( delimiters ) do s = mw.ustring.gsub( s, delimiter, '\0%1\0' ); -- remove zero marks from inside parentheses () s = mw.ustring.gsub( s, '%b'.. li.texts.parentheses, function( t ) return t:gsub( '%z', '' ) end ) -- replace delimeters by the default delimiter s = mw.ustring.gsub( s, '\0' .. delimiter .. '\0', '\0' .. defaultDelimiter .. '\0' ); end -- results to an array s = mw.text.split( s, '\0' .. defaultDelimiter .. '\0' ) for i = #s, 1, -1 do s[ i ] = mw.text.trim( s[ i ] ) if s[ i ] == '' then table.remove( s, i ) end end return s end -- extract comment written in parentheses -- remove spaces between value like phone numbers and comment function lu.extractComment( s ) local comment = '' if s:find( '(', 1, true ) then local t = mw.ustring.gsub( s, '^.*(%b' .. li.texts.parentheses .. ')$', '%1' ) if t ~= s then comment = t s = mw.ustring.gsub( s, '[%s%c]*%b' .. li.texts.parentheses .. '$', '' ) end end return s, comment end return lu