šŸ‡®šŸ‡· Iran Proxy | https://www.wikipedia.org/wiki/Module_talk:String2/Archive_1
Jump to content

Module talk:String2/Archive 1

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
Archive 1

New function "label" added

I added new function "label" which capitalize only first letter for fetched wikidata labels (diff). Because Wikidata English labels generally begin with a lowercase letter (d:Help:Label#Capitalization). New function is almost same as "sentence" function except that "label" doesn't lowering the rest of text. If there are any questions or problems, feel free to report here. Thanks! --Was a bee (talk) 03:03, 17 September 2017 (UTC)

Some objection. A "label" has multiple options. Especially: it is "free" (as in: irrelevant, not defining). If this option wants to imply "page title as a wikilink label", then change the option (parameter) name. -DePiep (talk)
I've removed the label function as obselete in favour of ucfirst. --RexxS (talk) 15:16, 13 November 2018 (UTC)

ucfirst bug

There is an script error on articles like 999 (album) and Casual Viewin' USA, whith an error on line 35, which originates on line 34. "%a" on line 34 did not match numbers after the pipe in my test, although it does find an letter after the pipe. As both of these articles have an number after the pipe, they both give an script error. The script needs to deal with the possibility of an number after an pipe.--Snaevar (talk) 23:13, 9 October 2019 (UTC)

@Snaevar: I noticed many articles with that problem and I believe I have just fixed the module. Johnuniq (talk) 09:11, 10 October 2019 (UTC)

ucfirst bug, part 2

E.g. {{#invoke:String2 | ucfirst |Đorđe BalaÅ”ević chronology }} returns ĐOrđe BalaÅ”ević chronology, as if the function does not realize Đ is a letter and is capitalizing O instead. Note {{ucfirst:Đorđe BalaÅ”ević chronology}} returns Đorđe BalaÅ”ević chronology, as it should. Oddly, {{#invoke:String2 | ucfirst |đorđe BalaÅ”ević chronology }} works correctly (i.e. Đorđe BalaÅ”ević chronology is returned). {{Infobox album}} chronology is affected, although these kinds of errors seem to be very rare. GregorB (talk) 18:24, 24 July 2020 (UTC)

@GregorB: Almost all of the time, the standard Lua string library calls manage to cope although they only deal with single-byte character codes. Once in a while an application needs to work with UTF-8, and this is one of those cases. I've updated the ucfirst call to use the mw.ustring library which handles UTF-8 characters properly. Now we should get:
  • {{#invoke:String2 | ucfirst |Đorđe BalaÅ”ević chronology }} → Đorđe BalaÅ”ević chronology
  • {{#invoke:String2 | ucfirst |đorđe BalaÅ”ević chronology }} → Đorđe BalaÅ”ević chronology
Thanks for spotting that, and please let me know if you find any more issues. Cheers --RexxS (talk) 19:24, 24 July 2020 (UTC)
That was super quick, thanks! GregorB (talk) 19:50, 24 July 2020 (UTC)

New function "findlast" added

Function findlast finds the last item in a list. The first unnamed parameter is the list. The second, optional unnamed parameter is the list separator (default = comma space). It returns the whole list if the separator is not found.

The list is trimmed of leading and trailing whitespace; the separator is not (so that leading or trailing spaces can be included).

One issue is that using Lua special pattern characters as the separator will probably cause problems.

Examples:

  • Normal usage: {{#invoke:String2 |findlast | 5, 932, 992,532, 6,074,702, 6,145,291}} → 6,145,291
  • Separator not found: {{#invoke:String2 |findlast | 5, 932, 992,532, 6,074,702, 6,145,291 |;}} → 5, 932, 992,532, 6,074,702, 6,145,291
  • One item list: {{#invoke:String2 |findlast | 6,074,702 }} → 6,074,702
  • List missing{{#invoke:String2 |findlast |}} →
  • Space as separator: {{#invoke:String2 |findlast | 5 932 992,532 6,074,702 6,145,291 }} → 5 932 992,532 6,074,702 6,145,291

Any bug reports welcome. --RexxS (talk) 20:33, 19 November 2020 (UTC)

Added matchAny function

I have added a matchAny function to the sandbox; it takes any number of patterns and returns the index of the first which matches, if any. Demo usage at Template:Infobox animanga/Header/sandbox. Comments welcome. (I'm a new template editor so I can make this change myself if no objections.) User:GKFXtalk 19:17, 8 April 2021 (UTC)

I'm a bit fuzzy at the moment and should not be relied on but the code looks good. I don't understand p._getParameters (please don't explain it) but my guess is that matchAll requires source=input. However, the example usage in the comment does not show that. Johnuniq (talk) 00:59, 9 April 2021 (UTC)
Good thing you pointed out p._getParameters, I was using it wrong. Fixed the docs also. User:GKFXtalk 09:56, 9 April 2021 (UTC)