మూస:Xifnoteq/doc

వికీపీడియా నుండి
Jump to navigation Jump to search

The Template:Xifnoteq provides a quick, extended if-not-equal function, as a reverse check, beyond the parser function #ifeq.

Usage:  {{xifnoteq|a|b|<then>|<else>}}
{{xifnoteq|{{{1|27}}}|26 |{1} is not 26|is 26}}   →   {1} is not 26

Parameters:

  • {1} - the 1st value to compare
  • {2} - the 2nd value to compare to 1st
  • {3} - result when not equal (as then-part of if)
  • {4} - result when equal (as else-part of if)

For small results, the processing speed will be very similar to #ifeq (see below: Performance and resources).

Some examples help to show the extended capability to handle cases such as a leading colon or leading-pound sign which might trigger indented numbering when used in #ifeq:

  • {{xifnoteq|{{{num|2}}}|2.0 |not 2.0|same as 2.0}} → same as 2.0
  • "{{xifnoteq|{{{colorset|no}}}|yes|{{{color|#f8eaba}}} }}" → "#f8eaba "
  • "{{#ifeq:{{{colorset|yes}}}|yes|{{{color|#f8eaba}}} }}" → "
  1. f8eaba"
  • {{xifnoteq|{{{colonset|empty}}}|colon|{{{mark|:val}}} }} → :val
  • {{#ifeq:{{{colonset|colon}}}|colon|{{{mark|:val}}} }} →
val

Because a leading pound# (hash mark) can trigger auto-indentation as a numbered list, {{xifnoteq}} treats a leading "#" (or colon ":" or asterisk "*" or semicolon ";") as being typical data, rather than indentation markup codes. As other problems arise with #ifeq, then this template can be modified to overcome those glitches and continue to work in a predictable manner.

The coding inside Template:Xifnoteq has been optimized to use only 2 levels of expansion nesting (see "m:Help:Expansion depth"), and runs very fast.

Limitations

[మార్చు]

The Template:Xifnoteq has the following limitations: it requires special coding for equal-sign "="; it performs numeric comparison unless {1} and {2} are not numbers.

As typical with #ifeq, the 2 values are compared numerically (where "2" equals "2.0") unless the values are not numbers:

  • {{xifnoteq| +2.00000 |2 |not 2|same as 2}} → same as 2

The numeric comparison can be avoided by putting a letter such as "z" in front of both values to compare: {{xifnoteq|z{{{1}}}|z{{{2}}}|...}} to force an alphanumeric comparison.

Because Template:Xifnoteq processes the then-clause and else-clause as template parameters, they cannot contain a simple equal-sign as in "x=x" so use either an unnamed parameter "x{{{|=}}}x" or "x{{=}}x" or set parameters by both number 3 and 4: "3=not =x" (then-clause) plus "4=x=x" (else-clause).

  • {{xifnoteq|x|x|not x|x{{{|=}}}x}} → x=x
  • {{xifnoteq|x|x|3=not =x|4=x=x}} → x=x
  • {{#ifeq:x|x|x=x|not x}} → x=x

Note how the parser function #ifeq allows the simple equal-sign "x=x" whereas xifnoteq needs both "3=not =x" and "4=x=x" to allow an equal-sign in parameter 3. For those reasons, using an unnamed parameter "x{{{|=}}}x" is often the easiest method.

Performance and resources

[మార్చు]

The Template:Xifnoteq is designed to run very quickly, with minimal expansion nesting (as 2 levels) and format concise results similar to #ifeq. However, unlike #ifeq, both the then-clause and else-clause will be expanded before the comparison is made. Also, unlike #ifeq, the intermediate expansion sizes of both the then-clause and else-clause are both counted, and counted double, against the resource post-expand size (of 2,000 kb conditional text). If the then-cause and else-clause are roughly equal in size, the post-expand size would be 4x times that size. However, only the actual choice of then-clause or else-clause is formatted into the final page; the post-expand size is just an intermediate limit for the MediaWiki preprocessor.

During intermediate processing, Template:Xifnoteq requires the formatting of both the then-part and else-part, before choosing between the 2 sets of formatted results. In most cases, there is no significant speed delay because hundreds of templates can be processed very quickly before choosing between 2 if-else branches.

The method for allowing spaces in if-logic, in January 2011, used 2 nowiki-slash tags "<nowiki/>" around the then-clause and else-clause: {{#ifeq:x|x|<nowiki/> yes <nowiki/>}} → " yes ".


"https://te.wikipedia.org/w/index.php?title=మూస:Xifnoteq/doc&oldid=765281" నుండి వెలికితీశారు