$Ent: Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
{{DISPLAYTITLE:$Ent}}
{{DISPLAYTITLE:$Ent}}
<span class="pageSubtitle"><section begin="desc" />Do character entity substitution<section end="desc" /></span>
<span class="pageSubtitle">Do character entity substitution</span>


<p class="warning">Most Sirius $functions have been deprecated in favor of Object Oriented methods. There is no OO equivalent for the $Ent function.</p>
<p class="warning">Most Sirius $functions have been deprecated in favor of Object Oriented methods. There is no OO equivalent for the $Ent function.</p>
Line 15: Line 15:
</p>
</p>
<p class="caption">%RESULT is set to the value of '''string''' with character entity substitution performed.</p>
<p class="caption">%RESULT is set to the value of '''string''' with character entity substitution performed.</p>
Character entity substitution replaces characters that have special meaning to an HTML or XML processor with their character entity representation. For example, the "<" is represented as the "&lt;" character entity. A default character entity substitution table is provided that does the basic required character entity mappings for HTML and XML of "&amp." to "&amp.amp;", "<" to "&lt;" and the double quote character to "&quot;". The active character entity substitution table can be modified with $Ent_Tab [[$Ent_Tab]].
Character entity substitution replaces characters that have special meaning to an HTML or XML processor with their character entity representation. For example, the "<" is represented as the "&amp;lt;" character entity. A default character entity substitution table is provided that does the basic required character entity mappings for HTML and XML of "&amp;amp." to "&amp;amp.amp;", "<" to "&amp;lt;" and the double quote character to "&amp;quot;". The active character entity substitution table can be modified with $Ent_Tab [[$Ent_Tab]].
The following code
The following code
<p class="code"> PRINT $Ent('This is < "fun"')
<p class="code"> PRINT $Ent('This is < "fun"')
</p>
</p>
would print <tt>This is &lt; &quot;fun&quot;</tt> if the default character entity substitution tables are in effect.  
would print <tt>This is &amp;lt; &amp;quot;fun&amp;quot;</tt> if the default character entity substitution tables are in effect.  


Since character entity substitution always produces a string greater than or equal to the length of the input string, it is quite possible that a $Ent call will produce a string that is truncated at 255 bytes. If this is a concern, and the $Ent call is in a PRINT statement or is assigned to a variable that is ultimately PRINT'ed, it is almost certainly better to have the character entity substitution occur at either of the following places, because in these cases the result of the character entity translation is not truncated at 255 bytes:
Since character entity substitution always produces a string greater than or equal to the length of the input string, it is quite possible that a $Ent call will produce a string that is truncated at 255 bytes. If this is a concern, and the $Ent call is in a PRINT statement or is assigned to a variable that is ultimately PRINT'ed, it is almost certainly better to have the character entity substitution occur at either of the following places, because in these cases the result of the character entity translation is not truncated at 255 bytes:
Line 25: Line 25:


<li>The PRINT statement, as a result of the $Ent_Print setting [[$Ent_Print]]  
<li>The PRINT statement, as a result of the $Ent_Print setting [[$Ent_Print]]  
<li>The HTML/TEXT statement, as a result of $ENT_PRINT, ENT_PRINT, or the <tt>&</tt> special character after an expression start string
<li>The HTML/TEXT statement, as a result of $ENT_PRINT, ENT_PRINT, or the <tt>&amp;</tt> special character after an expression start string
</ul>
</ul>
If this is not possible and truncation is a concern, another option is to break the string undergoing character entity substitution into pieces that are small enough that the resultant string cannot possibly be longer than 255 bytes. For the default substitution table, this would mean pieces no larger than 255/6 or 42 bytes, since the longest substitution string is "&quot;" which is 6 bytes long.  
If this is not possible and truncation is a concern, another option is to break the string undergoing character entity substitution into pieces that are small enough that the resultant string cannot possibly be longer than 255 bytes. For the default substitution table, this would mean pieces no larger than 255/6 or 42 bytes, since the longest substitution string is "&amp;quot;" which is 6 bytes long.  


This $function is new in Version 6.2 of the ''[[Sirius Mods]]''.
This $function is new in Version 6.2 of the ''[[Sirius Mods]]''.

Revision as of 21:21, 22 November 2011

Do character entity substitution

Most Sirius $functions have been deprecated in favor of Object Oriented methods. There is no OO equivalent for the $Ent function.

This function performs character entity substitution on an input string using the default character entity substitution table or one set by the most recent $Ent_Tab call $Ent_Tab.

$Ent accepts one argument and returns a string result.

The first argument is the string on which character entity translation is to be performed. This is an optional argument though the use of $Ent without this argument is somewhat silly as it simply returns a null.

Syntax

<section begin="syntax" /> %RESULT = $Ent(string) <section end="syntax" />

$Ent Function

%RESULT is set to the value of string with character entity substitution performed.

Character entity substitution replaces characters that have special meaning to an HTML or XML processor with their character entity representation. For example, the "<" is represented as the "&lt;" character entity. A default character entity substitution table is provided that does the basic required character entity mappings for HTML and XML of "&amp." to "&amp.amp;", "<" to "&lt;" and the double quote character to "&quot;". The active character entity substitution table can be modified with $Ent_Tab $Ent_Tab. The following code

PRINT $Ent('This is < "fun"')

would print This is &lt; &quot;fun&quot; if the default character entity substitution tables are in effect.

Since character entity substitution always produces a string greater than or equal to the length of the input string, it is quite possible that a $Ent call will produce a string that is truncated at 255 bytes. If this is a concern, and the $Ent call is in a PRINT statement or is assigned to a variable that is ultimately PRINT'ed, it is almost certainly better to have the character entity substitution occur at either of the following places, because in these cases the result of the character entity translation is not truncated at 255 bytes:

  • The PRINT statement, as a result of the $Ent_Print setting $Ent_Print
  • The HTML/TEXT statement, as a result of $ENT_PRINT, ENT_PRINT, or the & special character after an expression start string

If this is not possible and truncation is a concern, another option is to break the string undergoing character entity substitution into pieces that are small enough that the resultant string cannot possibly be longer than 255 bytes. For the default substitution table, this would mean pieces no larger than 255/6 or 42 bytes, since the longest substitution string is "&quot;" which is 6 bytes long.

This $function is new in Version 6.2 of the Sirius Mods.

Products authorizing $Ent