CompressSpaces (StringTokenizer property): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(One intermediate revision by the same user not shown)
Line 21: Line 21:
==Usage notes==
==Usage notes==
<ul>
<ul>
<li>If multiple whitespace
<li>If multiple whitespace characters are defined, the first character in the <var>Spaces</var> string is the character to which <var>CompressSpaces</var> compresses intermediate whitespace. For example, if <code>Spaces='X '</code>, the token
characters are defined, the first character in the <var>Spaces</var> string is the character to which <var>CompressSpaces</var> compresses intermediate whitespace. For example, if <code>Spaces='X '</code>, the token
<code>foot  ball</code> will compress to <code>footXball</code>.
<code>'foot  ball'</code> will compress to <code>'footXball'</code>.
 
<li><var>CompressSpaces</var> affects
<li><var>CompressSpaces</var> affects
processing only when one or more <var>Separators</var> characters are set, because otherwise a
processing only when one or more <var>[[Separators (StringTokenizer property)|Separators]]</var> characters are set, because otherwise a token cannot contain internal whitespace.
token cannot contain internal whitespace.
 
<li><var>CompressSpaces</var> does not compress quoted data that contains whitespace.  
<li><var>CompressSpaces</var> does not compress quoted data that contains whitespace.  
</ul>
</ul>
Line 33: Line 33:
==Examples==
==Examples==
Consider the following <code>%toke</code> <var>StringTokenizer</var> string, defined with a blank as the whitespace character and with comma as a non-token [[#The Separators method|separator]] character:
Consider the following <code>%toke</code> <var>StringTokenizer</var> string, defined with a blank as the whitespace character and with comma as a non-token [[#The Separators method|separator]] character:
<p class="output">     this,    is  a  compression  , example
<p class="output">     this,    is  a  compression  , example
</p>
</p>
Without compression, repeated calls of <code>%toke:NextToken</code> strip the leading and trailing whitespace and select the following tokens:
Without compression, repeated calls of <code>%toke:NextToken</code> strip the leading and trailing whitespace and select the following tokens:
<p class="output"> this
<p class="output">this
is  a  compression
is  a  compression
example
example
</p>
</p>
Without compression, that is, with <var>CompressSpaces</var> set to <var>True</var>, the result is:
Without compression, that is, with <var>CompressSpaces</var> set to <var>True</var>, the result is:
<p class="output"> this
<p class="output">this
is a compression
is a compression
example
example
</p>
</p>


==See also==
==See also==
{{Template:StringTokenizer:CompressSpaces footer}}
{{Template:StringTokenizer:CompressSpaces footer}}

Latest revision as of 16:49, 15 November 2012

Compress intra-token spaces (StringTokenizer class)

[Introduced in Sirius Mods 7.8]


CompressSpaces compresses a token's intermediate whitespace to a single whitespace character.

Syntax

%currentBoolean = stringTokenizer:CompressSpaces stringTokenizer:CompressSpaces = newBoolean

Syntax terms

%currentBoolean An enumeration object of type Boolean to contain the value of CompressSpaces. The default value for a new tokenizer instance is False.
stringTokenizer A StringTokenizer object variable.
newBoolean A Boolean enumeration value.

Usage notes

  • If multiple whitespace characters are defined, the first character in the Spaces string is the character to which CompressSpaces compresses intermediate whitespace. For example, if Spaces='X ', the token foot ball will compress to footXball.
  • CompressSpaces affects processing only when one or more Separators characters are set, because otherwise a token cannot contain internal whitespace.
  • CompressSpaces does not compress quoted data that contains whitespace.


Examples

Consider the following %toke StringTokenizer string, defined with a blank as the whitespace character and with comma as a non-token separator character:

this, is a compression , example

Without compression, repeated calls of %toke:NextToken strip the leading and trailing whitespace and select the following tokens:

this is a compression example

Without compression, that is, with CompressSpaces set to True, the result is:

this is a compression example

See also