Module:String: Difference between revisions
m 1 revision imported |
|||
Line 59: | Line 59: | ||
Parameters | Parameters | ||
s: The string to return a subset of | s: The string to return a subset of | ||
i: The | i: The fist index of the substring to return, defaults to 1. | ||
j: The last index of the string to return, defaults to the last character. | j: The last index of the string to return, defaults to the last character. | ||
Line 94: | Line 94: | ||
return mw.ustring.sub( s, i, j ) | return mw.ustring.sub( s, i, j ) | ||
end | end | ||
Line 289: | Line 279: | ||
return mw.ustring.sub( target_str, pos, pos ) | return mw.ustring.sub( target_str, pos, pos ) | ||
end | end | ||
Line 407: | Line 366: | ||
if plain then | if plain then | ||
pattern = str._escapePattern( pattern ) | pattern = str._escapePattern( pattern ) | ||
replace = | replace = mw.ustring.gsub( replace, "%%", "%%%%" ) --Only need to escape replacement sequences. | ||
end | end | ||
Line 510: | Line 469: | ||
end | end | ||
return table.concat( args, sep or '' ) | return table.concat( args, sep or '' ) | ||
end | |||
function str.sentenceTerminated( frame ) | |||
-- Is string terminated by dot, question or exclamation mark? | |||
-- Quotation, link termination and so on granted | |||
-- Parameter: | |||
-- analyse -- string | |||
-- Returns: true, if sentence terminated | |||
local sentence = frame.args[1] | |||
local PatternTerminated = mw.ustring.char( 91, | |||
12290, | |||
65281, | |||
65294, | |||
65311 ) | |||
.. "!%.%?…][\"'%]‹›«»‘’“”]*$" | |||
if mw.ustring.find( sentence, PatternTerminated ) then | |||
return "yes" | |||
end | |||
end | end | ||
Line 583: | Line 560: | ||
]] | ]] | ||
function str._escapePattern( pattern_str ) | function str._escapePattern( pattern_str ) | ||
return | return mw.ustring.gsub( pattern_str, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" ) | ||
end | end | ||
return str | return str |