PeekToken (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, | ||
PeekToken does not advance the tokenizing position, | <var>PeekToken</var> does not advance the tokenizing position, | ||
which remains what it was when PeekToken was called. | which remains what it was when <var>PeekToken</var> was called. | ||
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> | ||
</table> | </table> | ||
==Usage notes== | ==Usage notes== | ||
<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 PeekToken is invalid and cancels the request. | issuing <var>PeekToken</var> is invalid and cancels the request. | ||
<li>The [[NextToken (StringTokenizer function)|NextToken]] and [[FindToken (StringTokenizer function)|FindToken]] | <li>The [[NextToken (StringTokenizer function)|NextToken]] and [[FindToken (StringTokenizer function)|FindToken]] | ||
functions return the next token and | functions return the next token and | ||
Line 36: | Line 36: | ||
After a successful execution of NextToken, FindToken, or SkipTokens, the token | After a successful execution of NextToken, FindToken, or SkipTokens, the token | ||
located becomes the current token. | located becomes the current token. | ||
This is not true for PeekToken: after it completes successfully, the token located | This is not true for <var>PeekToken</var>: after it completes successfully, the token located | ||
does ''not'' become the current token. | does ''not'' become the current token. | ||
</ul> | </ul> | ||
Line 43: | Line 43: | ||
The following sequence of printText statements display, | The following sequence of printText statements display, | ||
respectively, <tt>example</tt>, <tt>example</tt>, and <tt>example</tt>, | respectively, <tt>example</tt>, <tt>example</tt>, and <tt>example</tt>, | ||
showing that the tokenizing position does not move after PeekToken completes: | showing that the tokenizing position does not move after <var>PeekToken</var> completes: | ||
<pre> | <pre> | ||
%tok:string = 'example of peekToken' | %tok:string = 'example of peekToken' |
Revision as of 21:47, 6 February 2011
Value of next token in current tokenizer string, do not advance (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, PeekToken does not advance the tokenizing position, which remains what it was when PeekToken was called.
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:PeekToken Throws MismatchedQuote, OutOfBounds
Syntax terms
%string | A string variable to receive the value of the current token. |
---|---|
%tok | A StringTokenizer object variable. |
Usage notes
- If the value of AtEnd is True, issuing PeekToken is invalid and cancels the request.
- The NextToken and FindToken functions return the next token and advance the tokenizing position to the character or position following that token. SkipTokens similarly advances the tokenizing position, but it returns no value. After a successful execution of NextToken, FindToken, or SkipTokens, the token located becomes the current token. This is not true for PeekToken: after it completes successfully, the token located does not become the current token.
Examples
The following sequence of printText statements display, respectively, example, example, and example, showing that the tokenizing position does not move after PeekToken completes:
%tok:string = 'example of peekToken' printText {%tok:peekToken} printText {%tok:peekToken} printText {%tok:peekToken}