AtEnd (StringTokenizer function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
Line 20: Line 20:
==Usage notes==
==Usage notes==
<ul>
<ul>
<li>The current tokenizing position may be after the last token but
<li>It is illegal to scan for a token past the <var>CurrentToken</var> if <var>AtEnd</var> is true.
<li>For <var>Spaces</var> tokenization, a token remains if there are any non-<var>Spaces</var> characters remaining at or
after <var>NextPosition</var>.
<li>For <var>Separators</var> tokenization, a token remains if either:
<ul>
<li><var>NextPosition</var> is less than or equal to the length of the <var>String</var>.
<li>Either a token has not been located in the <var>String</var>, or
the last method which located a token found a separator at the end of the <var>String</var>.
</ul>
<li><var>NextPosition</var> may be after the last token but
not necessarily at the end of the token string.
not necessarily at the end of the token string.
In the following code sequence, the return from <var>AtEnd</var> is <code>True</code>
In the following code sequence, the return from <var>AtEnd</var> is <code>true</code>
and the position is not at the end of the string:
and the position is not at the end of the string:
<p class="code">%tok:string = 'example     '
<p class="code">%tok = 'example   ':stringTokenizer
%tok:nextPosition = 10
%tok:nextPosition = 8
%tok:atEnd
printText {~=%tok:atEnd}
</p>
</p>
<li><var>[[NotAtEnd (StringTokenizer function)|NotAtEnd]]</var> is the reverse of <var>AtEnd</var>:
<li><var>[[NotAtEnd (StringTokenizer function)|NotAtEnd]]</var> is the reverse of <var>AtEnd</var>:
it returns a value of <code>False</code>
it returns <code>true</code>
if the current tokenizing position is at the end of the string.
if any tokens remain starting with <var>NextToken</var>.
</ul>
</ul>
==Examples==
==Examples==



Revision as of 19:34, 26 October 2012

Is current tokenizing position at the end of the string? (StringTokenizer class)


This method returns a Boolean value that indicates whether any tokens remain starting from NextPosition.

Syntax

%boolean = stringTokenizer:AtEnd

Syntax terms

%boolean An enumeration object of type Boolean to contain the returned value of AtEnd. For more information about Boolean enumerations, see "Using Boolean Enumerations".
stringTokenizer A stringTokenizer object.

Usage notes

  • It is illegal to scan for a token past the CurrentToken if AtEnd is true.
  • For Spaces tokenization, a token remains if there are any non-Spaces characters remaining at or after NextPosition.
  • For Separators tokenization, a token remains if either:
    • NextPosition is less than or equal to the length of the String.
    • Either a token has not been located in the String, or the last method which located a token found a separator at the end of the String.
  • NextPosition may be after the last token but not necessarily at the end of the token string. In the following code sequence, the return from AtEnd is true and the position is not at the end of the string:

    %tok = 'example ':stringTokenizer %tok:nextPosition = 8 printText {~=%tok:atEnd}

  • NotAtEnd is the reverse of AtEnd: it returns true if any tokens remain starting with NextToken.

Examples

The following request selects the string's tokens one after another until the end of the string is detected:

begin %tok is object stringtokenizer %tok = new %tok:string = 'Content-Type: text/plain; charset="US-ASCII"' repeat while not %tok:atEnd printText {~} is {%tok:nextToken} end repeat end

The result is:

%tok:nextToken is Content-Type: %tok:nextToken is text/plain; %tok:nextToken is charset="US-ASCII"

See also