Обсуждение модуля:String2

Материал из Википедии — свободной энциклопедии
Перейти к навигации Перейти к поиску

Написал функцию increase для увеличения числа в строке. Предлагаю добавить ее в модуль String2. См. юнит-тесты на Обсуждение модуля:String2/песочница/tests. — Алексей Копылов 02:00, 10 июня 2017 (UTC)[ответить]

Прошу перенести функцию ucfirst из английской версии модуля. Мне это нужно для работы шаблона {{Infobox medical condition}}: p.ucfirst = function (frame ) local s = mw.text.trim( frame.args[1] or "" ) local s1 = "" -- if it's a list chop off and (store as s1) everything up to the first <li> local lipos = string.find(s, "<li>" ) if lipos then s1 = string.sub(s, 1, lipos + 3) s = string.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 string.find(s, "^%[%[[^|]+|[^%]]+%]%]") then -- this is a piped wikilink, so we capitalise the text, not the pipe local _ _, letterpos = string.find(s, "|%A*%a") -- find the first letter after the pipe else letterpos = string.find(s, '%a') end if letterpos then local first = string.sub(s, 1, letterpos - 1) local letter = string.sub(s, letterpos, letterpos) local rest = string.sub(s, letterpos + 1) return s1 .. first .. string.upper(letter) .. rest else return s1 .. s end end Раммон (обс.)