Module:String2: Difference between revisions

Content deleted Content added
catch fragment that starts with lower case
sync from sandbox - handling UTF-8 in ucfirst
Line 21:
local s1 = ""
-- if it's a list chop off and (store as s1) everything up to the first <li>
local lipos = stringmw.ustring.find(s, "<li>" )
if lipos then
s1 = stringmw.ustring.sub(s, 1, lipos + 3)
s = stringmw.ustring.sub(s, lipos + 4)
end
-- s1 is either "" or the first part of the list markup, so we can continue
-- and prepend s1 to the returned string
local letterpos
if stringmw.ustring.find(s, "^%[%[[^|]+|[^%]]+%]%]") then
-- this is a piped wikilink, so we capitalise the text, not the pipe
local _
_, letterpos = stringmw.ustring.find(s, "|%A*%a") -- find the first letter after the pipe
else
letterpos = stringmw.ustring.find(s, '%a')
end
if letterpos then
local first = stringmw.ustring.sub(s, 1, letterpos - 1)
local letter = stringmw.ustring.sub(s, letterpos, letterpos)
local rest = stringmw.ustring.sub(s, letterpos + 1)
return s1 .. first .. stringmw.ustring.upper(letter) .. rest
else
return s1 .. s