Template talk:Str sub long

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

This is the discussion/talk page for: Template:Str sub long.

Created[edit]

The Template:Str_sub_long was created by long-term user Rich Farmbrough on 14 October 2009 to extract a substring, from a string of characters, for a specified character position and length, up to a maximum of 100 characters. -Wikid77 (talk) 20:45, 29 July 2010 (UTC)[reply]

Optimization for fast exit[edit]

29-July-2010: This template could be modified to skip checking for characters 11-100, by simply adding an if-expression (for length < 11) after the handling of character 10, to skip the remaining 90 characters. By definition, the runtime would then be 10x times faster for short strings of 1-10 characters. Since January 2008, the MediaWiki software has been using a recursive-descent parser, which skips over the false-condition logic when processing if-expressions (and switches) in the wiki markup language. As of 29 July 2010, this template was used in over 4,640 articles or pages. Because the MediaWiki parser (of July 2010) limits the nesting of if-expressions to 40 levels deep, the processing for a max of 100 characters has been handled by running all 100 consecutive if-expressions, even for a short string of 5 characters.

Skipping, to the end, after character 10 would increase the nesting by only 1 level. Another skip could be made after character 20 (skipping characters 21-100) to run 5x times faster (for strings of 11-20 long). The 2 added if-expressions would increase the logic nesting to only 3 of 40 levels deep. The optimized version should be developed in Template:Str_sub_long/sandbox for review. -Wikid77 (talk) 20:45, 29 July 2010 (UTC)[reply]

It seems that most of the work is in calling Template:Str index any for each character of the substring. That would not change. Also, it is not clear whether you mean character 10 of the whole string or of the substring. In the first case it is not sure that such a short string is very common. In the second case it is not clear what logic you suggest.--Patrick (talk) 22:06, 29 July 2010 (UTC)[reply]
To answer the last question myself, perhaps e.g. {{str index any|{{{1}}}|7}}}} can be replaced by {{str index any|{{{1}}}|{{#expr:{{{2|0}}} + 7}}

it doesn't return two dots[edit]

Does any one know why {{Str sub long|Fusão/Central de fusões/Anexo:Página a ser fundida 2; Anexo:Página a ser fundida|24|29}} don't return "Anexo:Página a ser fundida 2" and ommits ":" ? thanks!OTAVIO1981 (talk) 22:50, 9 November 2012 (UTC)[reply]