NextPosition (StringTokenizer property): Difference between revisions

From m204wiki
Jump to navigation Jump to search
 
(11 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Template:StringTokenizer:NextPosition subtitle}}
{{Template:StringTokenizer:NextPosition subtitle}}


This readWrite property returns
This [[Classes and Objects#readWrite|readWrite]] property returns
or sets the tokenizing position, the position of the character
or sets the tokenizing position, the position of the character
from which the parsing of the next token begins.
from which the parsing of the next token begins.
Its initial value is 1.
Its initial value is 1.
Unless you explicitly set it otherwise, the tokenizing position is
the position that follows the (last) character in the value returned by the
most recent call of [[NextToken (StringTokenizer function)|NextToken]],
[[FindToken (StringTokenizer function)|FindToken]], or [[NextChar (StringTokenizer function)|NextChar]].


Well, not exactly. [[??]] For example, SkipTokens & PreviousChar affect it, and if token is quoted (& all else defaults), it's position after quote.
The tokenizing position depends on the methods that precede it.
Each call of <var>[[NextToken (StringTokenizer function)|NextToken]]</var>,
<var>[[FindToken (StringTokenizer function)|FindToken]]</var>, or <var>[[NextChar (StringTokenizer function)|NextChar]]</var>, for example, moves the tokenizing position to
the position that follows the (last) character in the value returned by these methods. <var>[[PreviousChar (StringTokenizer function)|PreviousChar]]</var> moves the tokenizing position to the preceding character, and <var>[[SkipTokens (StringTokenizer subroutine)|SkipTokens]]</var> moves the tokenizing position to follow the last character in the last token to which it advances. If a token is quoted, the tokenizing position (in all-default situations) follows the ending quote character.
 
==Syntax==
==Syntax==
{{Template:StringTokenizer:NextPosition syntax}}
{{Template:StringTokenizer:NextPosition syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%currentNumber</th>
<tr><th>%currentNumber</th>
<td>A numeric variable to contain the value of the current tokenizing position.</td></tr>
<td>A numeric variable to contain the value of the current tokenizing position.</td></tr>
<tr><th>stringTokenizer</th>
<tr><th>stringTokenizer</th>
<td>A <var>stringTokenizer</var> object expression.</td></tr>
<td>A <var>stringTokenizer</var> object expression.</td></tr>
<tr><th>newNumber</th>
<tr><th>newNumber</th>
<td>The numeric value to assign to <var class="term">stringTokenizer</var>'s <var>NextPosition</var> property.</td></tr>
<td>The numeric value to assign to <var class="term">stringTokenizer</var>'s <var>NextPosition</var> property.</td></tr>
Line 29: Line 32:
Setting <var>NextPosition</var> does not change <var>CurrentTokenPosition</var>.
Setting <var>NextPosition</var> does not change <var>CurrentTokenPosition</var>.
<li>To advance the current token position a single character, you can use
<li>To advance the current token position a single character, you can use
[[NextChar (StringTokenizer function)|NextChar]].
<var>NextChar</var>.
If a NextChar function call immediately follows a <var>NextPosition</var> call,
If a <var>NextChar</var> function call immediately follows a <var>NextPosition</var> call,
NextChar identifies the character whose position is the value of <var>NextPosition</var>.
<var>NextChar</var> identifies the character whose position is the value of <var>NextPosition</var>.
<li>If you reset <var>NextPosition</var>, the value returned by your next NextToken,
<li>If you reset <var>NextPosition</var>, the value returned by your next <var>NextToken</var>,
FindToken, [[SkipTokens (StringTokenizer subroutine)|SkipTokens]], or NextChar call will be based on the reset <var>NextPosition</var> value.
<var>FindToken</var>, <var>SkipTokens</var>, or <var>NextChar</var> call will be based on the reset <var>NextPosition</var> value.


The <var>NextPosition</var> value is entirely independent from the CurrentTokenPosition value,
The <var>NextPosition</var> value is entirely independent from the <var>CurrentTokenPosition</var> value,
and vice versa.
and vice versa.
Both properties can be set to arbitrary locations in the tokenization string.
Both properties can be set to arbitrary locations in the tokenization string.
Line 41: Line 44:


==Examples==
==Examples==
 
In the following request fragment, <var>NextToken</var> calls retrieve the first three
In the following request fragment, NextToken calls retrieve the first three
tokens in the string, then <var>NextPosition</var> is explicitly set back to the second
tokens in the string, then <var>NextPosition</var> is explicitly set back to the second
character in the string, from which the next token is determined:
character in the string, from which the next token is determined:
Line 48: Line 50:
%tok = new
%tok = new
%tok:string = 'This is the nextPosition example.'
%tok:string = 'This is the nextPosition example.'
printText {~} is {%tok:nextToken}
[[Targeted Text statements#AuditText, PrintText, and TraceText|PrintText]] {~} is {%tok:nextToken}
printText {~} is {%tok:nextToken}
printText {~} is {%tok:nextToken}
printText {~} is {%tok:nextToken}
printText {~} is {%tok:nextToken}
Line 65: Line 67:
%tok:nextPosition is 5
%tok:nextPosition is 5
</p>
</p>
==See also==
==See also==
{{Template:StringTokenizer:NextPosition footer}}
{{Template:StringTokenizer:NextPosition footer}}

Latest revision as of 20:31, 15 November 2012

Position of character at current tokenizing position (StringTokenizer class)


This readWrite property returns or sets the tokenizing position, the position of the character from which the parsing of the next token begins. Its initial value is 1.

The tokenizing position depends on the methods that precede it. Each call of NextToken, FindToken, or NextChar, for example, moves the tokenizing position to the position that follows the (last) character in the value returned by these methods. PreviousChar moves the tokenizing position to the preceding character, and SkipTokens moves the tokenizing position to follow the last character in the last token to which it advances. If a token is quoted, the tokenizing position (in all-default situations) follows the ending quote character.

Syntax

%currentNumber = stringTokenizer:NextPosition stringTokenizer:NextPosition = newNumber

Syntax terms

%currentNumber A numeric variable to contain the value of the current tokenizing position.
stringTokenizer A stringTokenizer object expression.
newNumber The numeric value to assign to stringTokenizer's NextPosition property.

Usage notes

  • The CurrentTokenPosition property returns the position of the initial character in the current token. Setting NextPosition does not change CurrentTokenPosition.
  • To advance the current token position a single character, you can use NextChar. If a NextChar function call immediately follows a NextPosition call, NextChar identifies the character whose position is the value of NextPosition.
  • If you reset NextPosition, the value returned by your next NextToken, FindToken, SkipTokens, or NextChar call will be based on the reset NextPosition value. The NextPosition value is entirely independent from the CurrentTokenPosition value, and vice versa. Both properties can be set to arbitrary locations in the tokenization string.

Examples

In the following request fragment, NextToken calls retrieve the first three tokens in the string, then NextPosition is explicitly set back to the second character in the string, from which the next token is determined:

%tok is object stringTokenizer %tok = new %tok:string = 'This is the nextPosition example.' PrintText {~} is {%tok:nextToken} printText {~} is {%tok:nextToken} printText {~} is {%tok:nextToken} printText {~} is {%tok:nextPosition} %tok:nextPosition = 2 printText {~} is {%tok:nextToken} printText {~} is {%tok:nextPosition}

The result is:

%tok:nextToken is This %tok:nextToken is is %tok:nextToken is the %tok:nextPosition is 12 %tok:nextToken is his %tok:nextPosition is 5

See also