NextToken (StringTokenizer function): Difference between revisions
m (1 revision) |
m (1 revision) |
||
Line 7: | Line 7: | ||
When the next token is determined, | When the next token is determined, | ||
NextToken advances the tokenizing position | <var>NextToken</var> advances the tokenizing position | ||
to the position following that token, then returns the token value. | to the position following that token, then returns the token value. | ||
The delimiters that are involved in determining the tokens | The delimiters that are involved in determining the tokens | ||
are set initially by the [[New (StringTokenizer constructor)|New]] method | are set initially by the [[New (StringTokenizer constructor)|New]] method | ||
that instantiates the StringTokenizer object. | that instantiates the <var>StringTokenizer</var> object. | ||
The delimiters can be modified by the [[Spaces (StringTokenizer property)|Spaces]], | The delimiters can be modified by the [[Spaces (StringTokenizer property)|Spaces]], | ||
[[Quotes (StringTokenizer property)|Quotes]], and [[TokenChars (StringTokenizer property)|TokenChars]] properties. | [[Quotes (StringTokenizer property)|Quotes]], and [[TokenChars (StringTokenizer property)|TokenChars]] properties. | ||
Line 22: | Line 22: | ||
<td>A string variable to receive the value of the current token. </td></tr> | <td>A string variable to receive the value of the current token. </td></tr> | ||
<tr><th>%tok</th> | <tr><th>%tok</th> | ||
<td>A StringTokenizer object variable. </td></tr> | <td>A <var>StringTokenizer</var> object variable. </td></tr> | ||
<tr><th>Skip= num</th> | <tr><th>Skip= num</th> | ||
<td>This name required numeric argument specifies a number of tokens to skip before returning the next token. The value of ''num'' must be greater than 0, and it must be be less than the number of tokens remaining in the tokenizer string. For an example, see item [[??]] refid=skipxmp.. | <td>This name required numeric argument specifies a number of tokens to skip before returning the next token. The value of ''num'' must be greater than 0, and it must be be less than the number of tokens remaining in the tokenizer string. For an example, see item [[??]] refid=skipxmp.. | ||
Line 30: | Line 30: | ||
<ul> | <ul> | ||
<li>If the value of [[AtEnd (StringTokenizer function)|AtEnd]] is <tt>True</tt>, | <li>If the value of [[AtEnd (StringTokenizer function)|AtEnd]] is <tt>True</tt>, | ||
issuing NextToken is invalid and cancels the request. | issuing <var>NextToken</var> is invalid and cancels the request. | ||
<li>For a new StringTokenizer instance, issuing NextToken, | <li>For a new <var>StringTokenizer</var> instance, issuing <var>NextToken</var>, | ||
[[FindToken (StringTokenizer function)|FindToken]], or [[SkipTokens (StringTokenizer subroutine)|SkipTokens]] is | [[FindToken (StringTokenizer function)|FindToken]], or [[SkipTokens (StringTokenizer subroutine)|SkipTokens]] is | ||
required before [[CurrentToken (StringTokenizer function)|CurrentToken]] may be issued without error. | required before [[CurrentToken (StringTokenizer function)|CurrentToken]] may be issued without error. | ||
<li>The NextPosition [[NextPosition (StringTokenizer property)|NextPosition]] returns the position of | <li>The NextPosition [[NextPosition (StringTokenizer property)|NextPosition]] returns the position of | ||
the character after the NextToken value. | the character after the <var>NextToken</var> value. | ||
Conversely, the determination of the NextToken value always starts at the | Conversely, the determination of the <var>NextToken</var> value always starts at the | ||
position given by NextPosition. | position given by NextPosition. | ||
If you reset NextPosition, the value returned by your next NextToken call | If you reset NextPosition, the value returned by your next <var>NextToken</var> call | ||
will be based on the new NextPosition value. | will be based on the new NextPosition value. | ||
<li>The FindToken and [[PeekToken (StringTokenizer function)|PeekToken]] | <li>The FindToken and [[PeekToken (StringTokenizer function)|PeekToken]] | ||
functions also return the next token. | functions also return the next token. | ||
Like NextToken, FindToken | Like <var>NextToken</var>, FindToken | ||
advances the tokenizing position to the position following that token. | advances the tokenizing position to the position following that token. | ||
PeekToken, however, does not advance the tokenizing position. | PeekToken, however, does not advance the tokenizing position. |
Revision as of 21:47, 6 February 2011
Next token forward in current tokenizer string (StringTokenizer class)
This method returns the string value of
the next token forward in the current tokenizer string.
The next token parsing begins from the tokenizing position,
which is the value returned by NextPosition.
When the next token is determined, NextToken advances the tokenizing position to the position following that token, then returns the token value.
The delimiters that are involved in determining the tokens are set initially by the New method that instantiates the StringTokenizer object. The delimiters can be modified by the Spaces, Quotes, and TokenChars properties.
Syntax
[%string =] stringTokenizer:NextToken[( [Skip= number], [Default= string])] Throws MismatchedQuote, OutOfBounds
Syntax terms
%string | A string variable to receive the value of the current token. |
---|---|
%tok | A StringTokenizer object variable. |
Skip= num | This name required numeric argument specifies a number of tokens to skip before returning the next token. The value of num must be greater than 0, and it must be be less than the number of tokens remaining in the tokenizer string. For an example, see item ?? refid=skipxmp.. The Skip parameter is available as of version 7.7 of the Sirius Mods. |
Usage notes
- If the value of AtEnd is True, issuing NextToken is invalid and cancels the request.
- For a new StringTokenizer instance, issuing NextToken, FindToken, or SkipTokens is required before CurrentToken may be issued without error.
- The NextPosition NextPosition returns the position of the character after the NextToken value. Conversely, the determination of the NextToken value always starts at the position given by NextPosition. If you reset NextPosition, the value returned by your next NextToken call will be based on the new NextPosition value.
- The FindToken and PeekToken functions also return the next token. Like NextToken, FindToken advances the tokenizing position to the position following that token. PeekToken, however, does not advance the tokenizing position.
Examples
- In the following request fragment, the printText statements display,
respectively, example, of, and nextToken.
%tok is object stringTokenizer %tok = new %tok:string = 'example of nextToken' printText {%tok:nextToken} printText {%tok:nextToken} printText {%tok:nextToken}
- The following request fragment shows the effect of the Skip parameter:
%tok:string = ' * 0 * 1 * 2 * 3 * 4 * 5 * 6 * 7' repeat while %tok:notAtEnd printtext {~} = '{%tok:nextToken(skip=1)}' end repeat
The result is:
%tok:nextToken(skip=1) = '0' %tok:nextToken(skip=1) = '1' %tok:nextToken(skip=1) = '2' %tok:nextToken(skip=1) = '3' %tok:nextToken(skip=1) = '4' %tok:nextToken(skip=1) = '5' %tok:nextToken(skip=1) = '6' %tok:nextToken(skip=1) = '7'