Difference between revisions of "Template:LSL Function/negative index"
Jump to navigation
Jump to search
m |
m |
||
(9 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<noinclude> | {{LSL Injection Test}}<noinclude> | ||
Format: | Format: | ||
<nowiki>{{LSL Function/negative index|boolean|p1|p2|p3}}</nowiki><br/> | <nowiki>{{LSL Function/negative index|boolean|p1|p2|p3}}</nowiki><br/> | ||
Line 8: | Line 8: | ||
{{#vardefine:ni_nc|}} | {{#vardefine:ni_nc|}} | ||
{{#vardefine:ni_p1|number}} | {{#vardefine:ni_p1|number}} | ||
{{#vardefine:ni_p2|p2}} | |||
{{#vardefine:ni_p3|p3}}--> | <!--{{#vardefine:ni_p3|p3}}--> | ||
</noinclude>{{#if: | </noinclude>{{#if: | ||
Line 17: | Line 17: | ||
{{#vardefine:t|{{#ifeq:{{{1|{{#var:ni_mode}}}}}|true|{{#switch:{{#var:ni_c}}|3|2=LSL_Function/negative_index/range|1=LSL_Function/negative_index/single}}}}}} | {{#vardefine:t|{{#ifeq:{{{1|{{#var:ni_mode}}}}}|true|{{#switch:{{#var:ni_c}}|3|2=LSL_Function/negative_index/range|1=LSL_Function/negative_index/single}}}}}} | ||
{{{{#var:t}}|{{{2|{{#var:ni_p1}}}}}|{{{3|{{#var:ni_p2}}}}}|{{{4|{{#var:ni_p3}}}}}}} | {{{{#var:t}}|{{{2|{{#var:ni_p1}}}}}|{{{3|{{#var:ni_p2}}}}}|{{{4|{{#var:ni_p3}}}}}|noExclude={{{noExclude|}}}}} | ||
{{#if:{{{noSpec|}}}|| | |||
{{#vardefine:spec|{{#var:spec}} | {{#vardefine:spec|{{#var:spec}} | ||
{{#if:{{#var:t}}| | {{#if:{{#var:t}}| | ||
Line 28: | Line 29: | ||
{{!}}- | {{!}}- | ||
{{!}} First | {{!}} First | ||
{{!}} 0 | {{!}} <code>0</code> | ||
{{!}} -length | {{!}} <code>-{{{length|length}}}</code> | ||
{{!}}- | {{!}}- | ||
{{!}} Last | {{!}} Last | ||
{{!}} length - 1 | {{!}} <code>{{{length|length}}} - 1</code> | ||
{{!}} -1 | {{!}} <code>-1</code> | ||
{{!}}} | {{!}}} | ||
=== Indexes === | === Indexes === | ||
<div style="display:table;"><div style="display:block;"> | <div style="display:table;"><div style="display:block;"> | ||
*Positive indexes count from the beginning, the first item being indexed as | *Positive indexes count from the beginning, the first item being indexed as <code>0</code>, the last as <code>({{{length|length}}} - 1)</code>. | ||
</div></div> | </div></div> | ||
<div style="display:table;"><div style="display:block;"> | <div style="display:table;"><div style="display:block;"> | ||
*Negative indexes count from the far end, the first item being indexed as | *Negative indexes count from the far end, the first item being indexed as <code>-{{{length|length}}}</code>, the last as <code>-1</code>. | ||
</div></div> | </div></div> | ||
}} | |||
}} | }} | ||
}} | }} | ||
Line 51: | Line 53: | ||
{{#vardefineecho:ni_ps|{{#switch:{{#var:ni_c}} | {{#vardefineecho:ni_ps|{{#switch:{{#var:ni_c}} | ||
|0=This function | |0=This function | ||
|1= | |1={{LSLP|{{{2}}}}} | ||
|2= | |2={{LSLP|{{{2}}}}} & {{LSLP|{{{3}}}}} | ||
|3= | |3={{LSLP|{{{2}}}}}, {{LSLP|{{{3}}}}} & {{LSLP|{{{4}}}}} | ||
}}}} {{#if:{{#var:t}}| support{{#ifexpr:{{#var:ni_c}}>1||s}}| ''do{{#ifexpr:{{#var:ni_c}}>1||es}} not'' support }} {{LSLGC|Negative_Index{{#var:lang}}|negative indexes}}. | }}}} {{#if:{{#var:t}}| support{{#ifexpr:{{#var:ni_c}}>1||s}}| ''do{{#ifexpr:{{#var:ni_c}}>1||es}} not'' support }} {{LSLGC|Negative_Index{{#var:lang}}|negative indexes}}.{{PBR}} | ||
}} | }} | ||
{{#vardefine:footer|{{#var:footer}} | {{#vardefine:footer|{{#var:footer}} | ||
{{#if:{{#var:t}}|{{#ifeq:{{NAMESPACE}}|Template||{{#if:{{#var:self}}{{{self|}}}||{{LSLC|Negative Index{{#var:lang}}}}}}}}}}}} | {{#if:{{#var:t}}|{{#ifeq:{{NAMESPACE}}|Template||{{#if:{{#var:self}}{{{self|}}}{{#pos:{{#var:moded}}|r}}{{#pos:{{#var:moded}}|u}}||{{LSLC|Negative Index{{#var:lang}}}}}}}}| | ||
{{#if:{{#var:self}}{{{self|}}}{{#pos:{{#var:moded}}|r}}{{#pos:{{#var:moded}}|u}}||{{LSLC|Positive_Index_Only{{#var:lang}}}}}} | |||
}}}} | |||
{{#vardefine:caveats|{{#var:caveats}} | {{#vardefine:caveats|{{#var:caveats}} | ||
{{#if:{{{nc|{{#var:ni_nc}}}}}|| | {{#if:{{{nc|{{#var:ni_nc}}}}}|| | ||
* If {{#switch:{{#var:ni_c}} | * If {{#switch:{{#var:ni_c}} | ||
|3=either | |3=either {{LSLP|{{{2}}}}}, {{LSLP|{{{3}}}}} or {{LSLP|{{{4}}}}} are | ||
|2=either | |2=either {{LSLP|{{{2}}}}} or {{LSLP|{{{3}}}}} are | ||
|1= | |1={{LSLP|{{{2}}}}} is}} out of bounds {{#if:{{{oob-return|}}}|this function returns {{{oob-return|}}} and}} the script continues to execute without an error message. | ||
{{#if:{{#var:t}}|{{#ifexpr:{{#var:ni_c}}>1|{{#if:{{{noExclude|}}}|* {{LSLP|{{{2}}}}} & {{LSLP|{{{3}}}}} will not form an [[#exclusion_range|exclusion range]] when {{LSLP|{{{2}}}}} is past {{LSLP|{{{3}}}}} (Approximately: {{LSLP|{{{2}}}}} > {{LSLP|{{{3}}}}}), instead it will act as if {{LSLP|{{{2}}}}} was zero & {{LSLP|{{{3}}}}} was -1.|* {{LSLP|{{{2}}}}} & {{LSLP|{{{3}}}}} will form an [[#exclusion_range|exclusion range]] when {{LSLP|{{{2}}}}} is past {{LSLP|{{{3}}}}} (Approximately: {{LSLP|{{{2}}}}} > {{LSLP|{{{3}}}}}). }}}}}} | |||
}}}} | }}}} | ||
Latest revision as of 16:47, 1 May 2016
Format:
{{LSL Function/negative index|boolean|p1|p2|p3}}
Exclude p1, p2, or p3 if not used.
Debugging
#var | value | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
header_footnote |
{{{2}}} & {{{3}}} support negative indexes. | ||||||||||
spec |
Indexes
| ||||||||||
caveats |
| ||||||||||
notes |
Ranges & IndexesThe easiest way to explain how ranges work is to make all indexes positive. Negative indexes are just a way of counting from the tail end instead of the beginning, all negative indexes have a corresponding equivalent positive index (assuming they are in range). Positive indexes past length (after the last index), or negative indexes past the beginning (before the first index) are valid and the effects are predictable and reliable: the entries are treated as if they were there but were removed just before output.
See negative indexes for more information. | ||||||||||
constants_nb | |||||||||||
also_articles |
| ||||||||||
footer |