ReadStream.st
author Claus Gittinger <cg@exept.de>
Fri, 05 Mar 2004 21:00:26 +0100
changeset 8098 8d1d5cd8529b
parent 7483 471b86450ede
child 8140 7cc7ac5f29ca
permissions -rw-r--r--
nextByte should (at least) return integer when reading from a string-stream (should it check for single-byte string as well ?)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1988 by Claus Gittinger
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
5810
3de0efaab65c checkin from browser
frank
parents: 5310
diff changeset
    13
"{ Package: 'stx:libbasic' }"
3de0efaab65c checkin from browser
frank
parents: 5310
diff changeset
    14
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    15
PositionableStream subclass:#ReadStream
970
3b59c9b38dbb ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
    16
	instanceVariableNames:''
3b59c9b38dbb ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
    17
	classVariableNames:''
3b59c9b38dbb ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
    18
	poolDictionaries:''
3b59c9b38dbb ST80 compatibility: generate signal at end of stream when instance variable
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
    19
	category:'Streams'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
2162
7e1601f633b6 ff is a separator too (in #skipSeparators*)
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
    22
!ReadStream class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 59
diff changeset
    23
81dacba7a63a *** empty log message ***
claus
parents: 59
diff changeset
    24
copyright
81dacba7a63a *** empty log message ***
claus
parents: 59
diff changeset
    25
"
81dacba7a63a *** empty log message ***
claus
parents: 59
diff changeset
    26
 COPYRIGHT (c) 1988 by Claus Gittinger
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
    27
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    28
88
81dacba7a63a *** empty log message ***
claus
parents: 59
diff changeset
    29
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 59
diff changeset
    30
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 59
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 59
diff changeset
    32
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 59
diff changeset
    33
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 59
diff changeset
    34
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 59
diff changeset
    35
"
81dacba7a63a *** empty log message ***
claus
parents: 59
diff changeset
    36
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    37
88
81dacba7a63a *** empty log message ***
claus
parents: 59
diff changeset
    38
documentation
81dacba7a63a *** empty log message ***
claus
parents: 59
diff changeset
    39
"
81dacba7a63a *** empty log message ***
claus
parents: 59
diff changeset
    40
    ReadStream defines protocol for reading streamwise over collections. 
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    41
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    42
    [author:]
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
    43
	Claus Gittinger
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1138
diff changeset
    44
88
81dacba7a63a *** empty log message ***
claus
parents: 59
diff changeset
    45
"
81dacba7a63a *** empty log message ***
claus
parents: 59
diff changeset
    46
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    47
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
    48
!ReadStream methodsFor:'converting'!
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
    49
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
    50
readStream
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
    51
    "return a readStream from the receiver. Since this is already
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
    52
     a readStream, return self."
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
    53
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
    54
    ^ self
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
    55
! !
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
    56
1400
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    57
!ReadStream methodsFor:'emphasis'!
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    58
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    59
emphasis
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    60
    "return the emphasis of the current (i.e. next returned by #next)
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    61
     element. Streams on a string will return nil for all elements.
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    62
     Streams on collections which nothing at all about emphasises, 
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    63
     will report an error."
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    64
7114
acc13967229e position fixes
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
    65
    ^ collection emphasisAt:(position - ZeroPosition + 1).
1400
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    66
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    67
    "
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    68
     |t s|
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    69
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    70
     t := 'hello world' asText
7114
acc13967229e position fixes
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
    71
                emphasizeFrom:1 to:5 with:#bold;
acc13967229e position fixes
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
    72
                emphasizeFrom:7 to:11 with:#italic.
1400
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    73
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    74
     s := t readStream.
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    75
     [s atEnd] whileFalse:[
7114
acc13967229e position fixes
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
    76
        Transcript show:(s emphasis); show:' '.
acc13967229e position fixes
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
    77
        Transcript show:''''; show:(s next); showCR:''''.
1400
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    78
     ].
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    79
    "
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    80
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    81
    "Modified: 15.5.1996 / 17:30:33 / cg"
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    82
! !
0ee12d945849 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    83
345
claus
parents: 329
diff changeset
    84
!ReadStream methodsFor:'queries'!
claus
parents: 329
diff changeset
    85
5310
b943d0eae029 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4826
diff changeset
    86
copyFrom:beginning to:end
b943d0eae029 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4826
diff changeset
    87
    ^ collection copyFrom:beginning to:end
b943d0eae029 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4826
diff changeset
    88
!
b943d0eae029 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4826
diff changeset
    89
345
claus
parents: 329
diff changeset
    90
isReadable
2997
5254aeab421d comments
Claus Gittinger <cg@exept.de>
parents: 2446
diff changeset
    91
    "return true, if reading is supported by the recevier.
5254aeab421d comments
Claus Gittinger <cg@exept.de>
parents: 2446
diff changeset
    92
     Here, true is always returned."
5254aeab421d comments
Claus Gittinger <cg@exept.de>
parents: 2446
diff changeset
    93
345
claus
parents: 329
diff changeset
    94
    ^ true
2997
5254aeab421d comments
Claus Gittinger <cg@exept.de>
parents: 2446
diff changeset
    95
5254aeab421d comments
Claus Gittinger <cg@exept.de>
parents: 2446
diff changeset
    96
    "Modified: 4.10.1997 / 17:59:21 / cg"
1665
928e9a308cea added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
    97
!
928e9a308cea added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
    98
6315
11b585e578f5 Define #isWritable
Stefan Vogel <sv@exept.de>
parents: 6011
diff changeset
    99
isWritable
11b585e578f5 Define #isWritable
Stefan Vogel <sv@exept.de>
parents: 6011
diff changeset
   100
    "return true, if writing is supported by the recevier.
11b585e578f5 Define #isWritable
Stefan Vogel <sv@exept.de>
parents: 6011
diff changeset
   101
     This has to be redefined in concrete subclasses."
11b585e578f5 Define #isWritable
Stefan Vogel <sv@exept.de>
parents: 6011
diff changeset
   102
11b585e578f5 Define #isWritable
Stefan Vogel <sv@exept.de>
parents: 6011
diff changeset
   103
    ^ false
11b585e578f5 Define #isWritable
Stefan Vogel <sv@exept.de>
parents: 6011
diff changeset
   104
!
11b585e578f5 Define #isWritable
Stefan Vogel <sv@exept.de>
parents: 6011
diff changeset
   105
1665
928e9a308cea added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
   106
size
2997
5254aeab421d comments
Claus Gittinger <cg@exept.de>
parents: 2446
diff changeset
   107
    "return the number of elements in the streamed collection."
5254aeab421d comments
Claus Gittinger <cg@exept.de>
parents: 2446
diff changeset
   108
1665
928e9a308cea added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
   109
    ^ collection size
928e9a308cea added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
   110
928e9a308cea added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
   111
    "Created: 13.9.1996 / 18:14:35 / cg"
2997
5254aeab421d comments
Claus Gittinger <cg@exept.de>
parents: 2446
diff changeset
   112
    "Modified: 4.10.1997 / 17:59:45 / cg"
345
claus
parents: 329
diff changeset
   113
! !
claus
parents: 329
diff changeset
   114
59
4a86aad06603 *** empty log message ***
claus
parents: 13
diff changeset
   115
!ReadStream methodsFor:'reading'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   116
a27a279701f8 Initial revision
claus
parents:
diff changeset
   117
next
a27a279701f8 Initial revision
claus
parents:
diff changeset
   118
    "return the next element; advance read pointer.
2
claus
parents: 1
diff changeset
   119
     return nil, if there is no next element.
345
claus
parents: 329
diff changeset
   120
     - tuned for a bit more speed on String/ByteArray/Array-Streams"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   121
a27a279701f8 Initial revision
claus
parents:
diff changeset
   122
    |ret|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   123
a27a279701f8 Initial revision
claus
parents:
diff changeset
   124
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   125
a27a279701f8 Initial revision
claus
parents:
diff changeset
   126
    REGISTER int pos;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   127
    unsigned ch;
252
   128
    OBJ coll, p, l;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   129
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   130
    coll = __INST(collection);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   131
    p = __INST(position);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   132
    l = __INST(readLimit);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   133
252
   134
    if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) {
   135
8098
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   136
        pos = __intVal(p);
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   137
        /* make 1-based */
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   138
        pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   139
        if (pos > 0 && pos <= __intVal(l)) {
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   140
            OBJ cls;
59
4a86aad06603 *** empty log message ***
claus
parents: 13
diff changeset
   141
8098
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   142
            cls = __qClass(coll);
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   143
            if (cls == @global(String)) {
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   144
                if (pos <= __stringSize(coll)) {
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   145
                    __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1);
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   146
                    ch = __stringVal(coll)[pos-1];
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   147
                    RETURN ( __MKCHARACTER(ch) );
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   148
                }
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   149
            } else if (cls == @global(ByteArray)) {
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   150
                if (pos <= __byteArraySize(coll)) {
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   151
                    __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1);
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   152
                    ch = __ByteArrayInstPtr(coll)->ba_element[pos-1];
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   153
                    RETURN ( __MKSMALLINT(ch) );
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   154
                }
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   155
            } else if (cls == @global(Unicode16String)) {
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   156
                if (pos <= __unicode16StringSize(coll)) {
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   157
                    __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1);
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   158
                    ch = __Unicode16StringInstPtr(coll)->s_element[pos-1];
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   159
                    RETURN ( __MKUCHARACTER(ch) );
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   160
                }
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   161
            } else if (cls == @global(Array)) {
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   162
                if (pos <= __arraySize(coll)) {
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   163
                    __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1);
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   164
                    RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]);
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   165
                }
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   166
            }
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   167
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   168
    }
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   169
%}.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   170
    ((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEnd].
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   171
    ret := collection at:(position + 1 - ZeroPosition).
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   172
    position := position + 1.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   173
    ^ ret
a27a279701f8 Initial revision
claus
parents:
diff changeset
   174
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   175
252
   176
nextAlphaNumericWord
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   177
    "read the next word (i.e. up to non letter-or-digit).
a27a279701f8 Initial revision
claus
parents:
diff changeset
   178
     return a string containing those characters.
3112
ccf7121ddae8 nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents: 2997
diff changeset
   179
     Skips any non-alphanumeric chars first.
59
4a86aad06603 *** empty log message ***
claus
parents: 13
diff changeset
   180
     - tuned for speed on String-Streams for faster scanning"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   181
%{
a27a279701f8 Initial revision
claus
parents:
diff changeset
   182
    /* speedup, if collection is a string */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   183
a27a279701f8 Initial revision
claus
parents:
diff changeset
   184
    int pos, limit, sz;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   185
    int len;
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   186
    char buffer[256];
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   187
    REGISTER unsigned char *cp;
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   188
    REGISTER unsigned ch;
252
   189
    OBJ coll, p, l;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   190
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   191
    coll = __INST(collection);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   192
    p = __INST(position);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   193
    l = __INST(readLimit);
252
   194
    
   195
    if (__isString(coll) && __bothSmallInteger(p, l)) {
   196
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   197
	pos = __intVal(p);
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   198
	/* make 1-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   199
	pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   200
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   201
	limit = __intVal(l);
329
claus
parents: 252
diff changeset
   202
	sz = __qSize(coll) - OHDR_SIZE;
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   203
	if (sz < limit)
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   204
	    limit = sz; 
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   205
	cp = __stringVal(coll) + pos - 1;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   206
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   207
	for (;;) {
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   208
	    if (pos > limit) break;
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   209
	    ch = *cp;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   210
3112
ccf7121ddae8 nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents: 2997
diff changeset
   211
	    if (((ch >= 'a') && (ch <= 'z')) ||
ccf7121ddae8 nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents: 2997
diff changeset
   212
		((ch >= 'A') && (ch <= 'Z')) ||
ccf7121ddae8 nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents: 2997
diff changeset
   213
		((ch >= '0') && (ch <= '9')))
ccf7121ddae8 nextAlphaNumericWord changed
Claus Gittinger <cg@exept.de>
parents: 2997
diff changeset
   214
		break;
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   215
	    cp++;
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   216
	    pos++;
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   217
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   218
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   219
	len = 0;
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   220
	for (;;) {
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   221
	    if (pos > limit) break;
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   222
	    ch = *cp & 0xFF;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   223
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   224
	    if (! (((ch >= 'a') && (ch <= 'z')) ||
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   225
		   ((ch >= 'A') && (ch <= 'Z')) ||
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   226
		   ((ch >= '0') && (ch <= '9'))))
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   227
		break;
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   228
	    buffer[len++] = ch;
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   229
	    if (len >= (sizeof(buffer)-1)) {
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   230
		/* emergency */
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   231
		break;
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   232
	    }
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   233
	    pos++;
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   234
	    cp++;
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   235
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   236
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   237
	/* make ZeroPosition-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   238
	pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition));
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   239
	__INST(position) = __MKSMALLINT(pos);
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   240
	buffer[len] = '\0';
1688
8a42db1eea60 removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents: 1665
diff changeset
   241
	RETURN ( (len != 0) ? __MKSTRING_L(buffer, len) : nil );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   242
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
   243
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
   244
.
252
   245
    ^ super nextAlphaNumericWord
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   246
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   247
1665
928e9a308cea added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
   248
nextByte
4826
ff30434f0feb #nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents: 4522
diff changeset
   249
    "return the next element; advance read pointer.
ff30434f0feb #nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents: 4522
diff changeset
   250
     return nil, if there is no next element.
ff30434f0feb #nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents: 4522
diff changeset
   251
     - tuned for a bit more speed on String/ByteArray/Array-Streams"
1665
928e9a308cea added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
   252
928e9a308cea added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
   253
    |ret|
928e9a308cea added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
   254
4826
ff30434f0feb #nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents: 4522
diff changeset
   255
%{  /* NOCONTEXT */
ff30434f0feb #nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents: 4522
diff changeset
   256
ff30434f0feb #nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents: 4522
diff changeset
   257
    REGISTER int pos;
ff30434f0feb #nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents: 4522
diff changeset
   258
    unsigned ch;
ff30434f0feb #nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents: 4522
diff changeset
   259
    OBJ coll, p, l;
ff30434f0feb #nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents: 4522
diff changeset
   260
ff30434f0feb #nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents: 4522
diff changeset
   261
    coll = __INST(collection);
ff30434f0feb #nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents: 4522
diff changeset
   262
    p = __INST(position);
ff30434f0feb #nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents: 4522
diff changeset
   263
    l = __INST(readLimit);
ff30434f0feb #nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents: 4522
diff changeset
   264
ff30434f0feb #nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents: 4522
diff changeset
   265
    if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) {
ff30434f0feb #nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents: 4522
diff changeset
   266
8098
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   267
        pos = __intVal(p);
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   268
        /* make 1-based */
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   269
        pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   270
        if (pos > 0 && pos <= __intVal(l)) {
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   271
            OBJ cls;
4826
ff30434f0feb #nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents: 4522
diff changeset
   272
8098
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   273
            cls = __qClass(coll);
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   274
            if (cls == @global(String)) {
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   275
                if (pos <= __stringSize(coll)) {
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   276
                    __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1);
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   277
                    ch = __stringVal(coll)[pos-1];
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   278
                    RETURN ( __MKSMALLINT(ch) );
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   279
                }
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   280
            } else if (cls == @global(ByteArray)) {
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   281
                if (pos <= __byteArraySize(coll)) {
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   282
                    __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1);
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   283
                    ch = __ByteArrayInstPtr(coll)->ba_element[pos-1];
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   284
                    RETURN ( __MKSMALLINT(ch) );
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   285
                }
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   286
            } else if (cls == @global(Array)) {
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   287
                if (pos <= __arraySize(coll)) {
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   288
                    __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1);
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   289
                    RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]);
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   290
                }
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   291
            }
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   292
        }
4826
ff30434f0feb #nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents: 4522
diff changeset
   293
    }
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   294
%}.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   295
    ((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEnd].
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   296
    ret := collection at:(position + 1 -ZeroPosition).
4826
ff30434f0feb #nextByte does return an integer, even when operating on a
Claus Gittinger <cg@exept.de>
parents: 4522
diff changeset
   297
    position := position + 1.
8098
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   298
    ^ ret asInteger
1665
928e9a308cea added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
   299
!
928e9a308cea added ExternalStream compatibility protocol
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
   300
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   301
nextDecimalInteger
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   302
    "read the next integer in radix 10. dont skip whitespace.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   303
     - tuned for speed on String-Streams for faster scanning"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   304
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   305
    |value nextOne|
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   306
%{
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   307
    int pos, limit, sz;
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   308
    REGISTER unsigned char *cp;
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   309
    REGISTER unsigned ch;
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   310
    int val = 0;
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   311
    OBJ coll, p, l;
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   312
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   313
    coll = __INST(collection);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   314
    p = __INST(position);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   315
    l = __INST(readLimit);
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   316
    
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   317
    if (__isString(coll) && __bothSmallInteger(p, l)) {
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   318
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   319
	pos = __intVal(p);
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   320
	/* make 1-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   321
	pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   322
	limit = __intVal(l);
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   323
	sz = __qSize(coll) - OHDR_SIZE;
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   324
	if (sz < limit)
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   325
	    limit = sz; 
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   326
	cp = __stringVal(coll) + pos - 1;
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   327
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   328
	for (;;) {
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   329
	    if (pos > limit) break;
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   330
	    ch = *cp;
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   331
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   332
	    if ((ch < '0') || (ch > '9')) break;
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   333
	    val = val * 10 + (ch - '0');
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   334
	    pos++;
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   335
	    if (val > (_MAX_INT / 10)) goto oops;
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   336
	    cp++;
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   337
	}
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   338
	/* make ZeroPosition-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   339
	pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition));
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   340
	__INST(position) = __MKSMALLINT(pos);
4271
d1878c9dc428 oops - return instead of RETURN macro
Claus Gittinger <cg@exept.de>
parents: 3316
diff changeset
   341
	RETURN (__MKSMALLINT(val));
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   342
    }
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   343
oops:
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   344
    value = __MKSMALLINT(val);
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   345
%}
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   346
.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   347
    "fall-back for non-string streams - we have to continue where
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   348
     above primitive left off, in case of a large integer ...
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   349
     (instead of doing a super nextDecimalInteger)"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   350
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   351
    nextOne := self peek.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   352
    [nextOne notNil and:[nextOne isDigitRadix:10]] whileTrue:[
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   353
	value = (value * 10) + nextOne digitValue.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   354
	nextOne := self nextPeek
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   355
    ].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   356
    ^ value
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   357
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   358
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   359
nextPeek
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   360
    "advance read pointer return the peek element.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   361
     this is equivalent to (self next; peek).
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   362
     - tuned for speed on String-Streams for faster scanning"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   363
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   364
%{  /* NOCONTEXT */
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   365
    OBJ coll, l, p;
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   366
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   367
    coll = __INST(collection);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   368
    p = __INST(position);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   369
    l = __INST(readLimit);
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   370
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   371
    if (__isString(coll) && __bothSmallInteger(p, l)) {
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   372
	REGISTER int pos;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   373
	unsigned ch;
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   374
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   375
	pos = __intVal(p);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   376
	/* make 1-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   377
	pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   378
	if ((pos > 0) && (pos < __intVal(l)) && (pos < __stringSize(coll))) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   379
	    pos = pos + 1;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   380
	    ch = __stringVal(coll)[pos-1];
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   381
	    /* make ZeroPosition-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   382
	    pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition));
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   383
	    __INST(position) = __MKSMALLINT(pos);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   384
	    RETURN ( __MKCHARACTER(ch) );
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   385
	}
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   386
    }
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   387
%}.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   388
    ((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEnd].
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   389
    position := position + 1.
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   390
    ((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEnd].
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   391
    ^ collection at:(position + 1 - ZeroPosition)
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   392
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   393
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   394
nextSymbol
a27a279701f8 Initial revision
claus
parents:
diff changeset
   395
    "read the next selector-symbol (i.e. up to non letter-or-digit).
a27a279701f8 Initial revision
claus
parents:
diff changeset
   396
     return a string containing those characters.
59
4a86aad06603 *** empty log message ***
claus
parents: 13
diff changeset
   397
     - tuned for speed on String-Streams for faster scanning"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   398
%{
a27a279701f8 Initial revision
claus
parents:
diff changeset
   399
    int pos, limit, sz;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   400
    int len;
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   401
    char buffer[256];
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   402
    REGISTER unsigned char *cp;
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   403
    REGISTER unsigned ch;
252
   404
    OBJ coll, p, l;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   405
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   406
    coll = __INST(collection);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   407
    p = __INST(position);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   408
    l = __INST(readLimit);
252
   409
   410
    if (__isString(coll) && __bothSmallInteger(p, l)) {
   411
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   412
	pos = __intVal(p);
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   413
	/* make 1-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   414
	pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   415
	limit = __intVal(l);
329
claus
parents: 252
diff changeset
   416
	sz = __qSize(coll) - OHDR_SIZE;
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   417
	if (sz < limit)
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   418
	    limit = sz; 
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   419
	cp = __stringVal(coll) + pos - 1;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   420
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   421
	len = 0;
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   422
	for (;;) {
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   423
	    if (pos > limit) break;
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   424
	    ch = *cp;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   425
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   426
	    if (! (((ch >= 'a') && (ch <= 'z')) ||
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   427
		   ((ch >= 'A') && (ch <= 'Z')) ||
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   428
		   ((ch >= '0') && (ch <= '9')) ||
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   429
		   (ch == ':')))
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   430
		break;
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   431
	    buffer[len++] = ch;
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   432
	    if (len >= (sizeof(buffer)-1)) {
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   433
		/* emergency */
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   434
		break;
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   435
	    }
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   436
	    pos++;
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   437
	    cp++;
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   438
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   439
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   440
	/* make ZeroPosition-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   441
	pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition));
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   442
	__INST(position) = __MKSMALLINT(pos);
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   443
	buffer[len] = '\0';
1688
8a42db1eea60 removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents: 1665
diff changeset
   444
	RETURN ( (len != 0) ? __MKSTRING_L(buffer, len) : nil );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   445
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
   446
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
   447
.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   448
    ^ super nextSymbol
a27a279701f8 Initial revision
claus
parents:
diff changeset
   449
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   450
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   451
peek
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   452
    "return the next element; do NOT advance read pointer.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   453
     return nil, if there is no next element.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   454
     - tuned for a bit more speed on String/ByteArray/Array-Streams"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   455
a27a279701f8 Initial revision
claus
parents:
diff changeset
   456
%{  /* NOCONTEXT */
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   457
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   458
    REGISTER int pos;
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   459
    unsigned ch;
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   460
    OBJ coll;
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   461
    OBJ cls, p, l;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   462
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   463
    coll = __INST(collection);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   464
    p = __INST(position);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   465
    l = __INST(readLimit);
252
   466
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   467
    if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) {
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   468
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   469
	pos = __intVal(p);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   470
	/* make 1-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   471
	pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   472
	if (pos <= __intVal(l) && pos > 0) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   473
	    cls = __qClass(coll);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   474
	    if (cls == @global(String)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   475
		if (pos <= __stringSize(coll)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   476
		    ch = __stringVal(coll)[pos-1];
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   477
		    RETURN ( __MKCHARACTER(ch) );
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   478
		}
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   479
	    } else if (cls == @global(ByteArray)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   480
		if (pos <= __byteArraySize(coll)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   481
		    ch = __ByteArrayInstPtr(coll)->ba_element[pos-1];
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   482
		    RETURN ( __MKSMALLINT(ch) );
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   483
		}
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   484
	    } else if (cls == @global(Array)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   485
		if (pos <= __arraySize(coll)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   486
		    RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   487
		}
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   488
	    }
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   489
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   490
    }
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   491
%}.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   492
    ((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ self pastEnd].
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   493
    ^ collection at:(position + 1 - ZeroPosition)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   494
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   495
3316
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   496
peekOrNil
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   497
    "return the next element; do NOT advance read pointer.
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   498
     return nil, if there is no next element.
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   499
     This is much like #peek -
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   500
     However, unlike #peek, this does not raise an atEnd-query signal - even
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   501
     if handled. Instead, nil is returned immediately."
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   502
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   503
%{  /* NOCONTEXT */
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   504
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   505
    REGISTER int pos;
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   506
    unsigned ch;
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   507
    OBJ coll;
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   508
    OBJ cls, p, l;
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   509
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   510
    coll = __INST(collection);
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   511
    p = __INST(position);
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   512
    l = __INST(readLimit);
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   513
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   514
    if (__isNonNilObject(coll) && __bothSmallInteger(p, l)) {
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   515
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   516
	pos = __intVal(p);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   517
	/* make 1-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   518
	pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   519
	if (pos <= __intVal(l) && pos > 0) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   520
	    cls = __qClass(coll);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   521
	    if (cls == @global(String)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   522
		if (pos <= __stringSize(coll)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   523
		    ch = __stringVal(coll)[pos-1];
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   524
		    RETURN ( __MKCHARACTER(ch) );
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   525
		}
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   526
		RETURN ( nil );
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   527
	    } else if (cls == @global(ByteArray)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   528
		if (pos <= __byteArraySize(coll)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   529
		    ch = __ByteArrayInstPtr(coll)->ba_element[pos-1];
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   530
		    RETURN ( __MKSMALLINT(ch) );
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   531
		}
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   532
		RETURN ( nil );
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   533
	    } else if (cls == @global(Array)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   534
		if (pos <= __arraySize(coll)) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   535
		    RETURN ( __ArrayInstPtr(coll)->a_element[pos-1]);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   536
		}
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   537
		RETURN ( nil );
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   538
	    }
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   539
	}
3316
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   540
    }
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   541
%}.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   542
    ((position + 1 - ZeroPosition) > readLimit) ifTrue:[^ nil].
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   543
    ^ collection at:(position + 1 - ZeroPosition)
3316
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   544
!
ba0a4305f900 added #peekOrNil
Claus Gittinger <cg@exept.de>
parents: 3112
diff changeset
   545
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   546
skipSeparators
a27a279701f8 Initial revision
claus
parents:
diff changeset
   547
    "skip all whitespace; next will return next non-white-space element.
59
4a86aad06603 *** empty log message ***
claus
parents: 13
diff changeset
   548
     Return the peeked character or nil, if the end-of-stream was reached.
2
claus
parents: 1
diff changeset
   549
     - reimplemented for speed on String-Streams for faster scanning"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   550
a27a279701f8 Initial revision
claus
parents:
diff changeset
   551
%{  /* NOCONTEXT */
252
   552
    OBJ coll, p, l;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   553
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   554
    coll = __INST(collection);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   555
    p = __INST(position);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   556
    l = __INST(readLimit);
252
   557
   558
    if (__isString(coll) && __bothSmallInteger(p, l)) {
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   559
	REGISTER unsigned char *chars;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   560
	REGISTER unsigned ch;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   561
	REGISTER int pos;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   562
	int limit;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   563
	int sz;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   564
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   565
	pos = __intVal(p);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   566
	/* make 1-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   567
	pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   568
	if (pos <= 0) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   569
	    RETURN ( nil );
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   570
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   571
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   572
	limit = __intVal(l);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   573
	sz = __qSize(coll) - OHDR_SIZE;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   574
	if (limit > sz) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   575
	    limit = sz;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   576
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   577
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   578
	chars = (unsigned char *)(__stringVal(coll) + pos - 1);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   579
	while (pos <= limit) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   580
	    pos++;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   581
	    ch = *chars++;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   582
	    if ((ch > 0x20)
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   583
	     || ((ch != ' ')
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   584
		 && (ch != '\t')
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   585
		 && (ch != '\r')
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   586
		 && (ch != '\n')
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   587
		 && (ch != '\f')
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   588
		 && (ch != 0x0B))) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   589
		/* make ZeroPosition-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   590
		pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition));
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   591
		__INST(position) = __MKSMALLINT(pos-1);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   592
		RETURN ( __MKCHARACTER(ch) );
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   593
	    }
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   594
	}
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   595
	/* make ZeroPosition-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   596
	pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition));
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   597
	__INST(position) = __MKSMALLINT(pos);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   598
	RETURN ( nil );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   599
    }
1406
fd7eed0e648f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1400
diff changeset
   600
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   601
    ^ super skipSeparators
1406
fd7eed0e648f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1400
diff changeset
   602
fd7eed0e648f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1400
diff changeset
   603
    "
fd7eed0e648f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1400
diff changeset
   604
     |s|
fd7eed0e648f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1400
diff changeset
   605
fd7eed0e648f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1400
diff changeset
   606
     s := '     hello     world    ' readStream.
fd7eed0e648f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1400
diff changeset
   607
     s skipSeparators.
fd7eed0e648f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1400
diff changeset
   608
     s next.
fd7eed0e648f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1400
diff changeset
   609
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   610
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   611
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   612
skipSeparatorsExceptCR
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   613
    "skip all whitespace except newlines;
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   614
     next will return next non-white-space element.
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   615
     - reimplemented for speed on String-Streams for faster scanning"
40ca7cc6fb9c *** empty log message ***
claus
parents: 93
diff changeset
   616
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   617
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   618
252
   619
    OBJ coll, p, l;
   620
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   621
    coll = __INST(collection);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   622
    p = __INST(position);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   623
    l = __INST(readLimit);
252
   624
   625
    if (__isString(coll) && __bothSmallInteger(p, l)) {
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   626
	REGISTER unsigned char *chars;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   627
	REGISTER unsigned ch;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   628
	REGISTER int pos;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   629
	int limit;
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   630
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   631
	pos = __intVal(p);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   632
	/* make 1-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   633
	pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   634
	if (pos <= 0) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   635
	    RETURN ( nil );
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   636
	}
2162
7e1601f633b6 ff is a separator too (in #skipSeparators*)
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   637
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   638
	limit = __intVal(l);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   639
	if (limit > (__qSize(coll) - OHDR_SIZE))
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   640
	    limit = __qSize(coll) - OHDR_SIZE;
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   641
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   642
	chars = (unsigned char *)(__stringVal(coll) + pos - 1);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   643
	while (pos <= limit) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   644
	    ch = *chars++;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   645
	    if (((int)ch > 0x20)
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   646
	     || (
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   647
		 (ch != ' ') 
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   648
		 && (ch != '\t')
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   649
		 && (ch != '\f')
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   650
		 && (ch != '\b')
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   651
		 && (ch != 0x0B))) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   652
		/* make ZeroPosition-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   653
		pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition));
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   654
		__INST(position) = __MKSMALLINT(pos);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   655
		RETURN ( __MKCHARACTER(ch) );
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   656
	    }
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   657
	    pos++;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   658
	}
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   659
	/* make ZeroPosition-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   660
	pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition));
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   661
	__INST(position) = __MKSMALLINT(pos);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   662
	RETURN ( nil );
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   663
    }
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   664
%}
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   665
.
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   666
    ^ super skipSeparatorsExceptCR
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   667
!
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   668
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   669
skipThrough:anObject
6011
3b91d7834ca5 fixed: skipThrough dod not position atEnd if the element was not found.
Claus Gittinger <cg@exept.de>
parents: 5810
diff changeset
   670
    "skip all objects up-to and including anObject.
3b91d7834ca5 fixed: skipThrough dod not position atEnd if the element was not found.
Claus Gittinger <cg@exept.de>
parents: 5810
diff changeset
   671
     Return the receiver if skip was successful, 
3b91d7834ca5 fixed: skipThrough dod not position atEnd if the element was not found.
Claus Gittinger <cg@exept.de>
parents: 5810
diff changeset
   672
     otherwise (i.e. if not found) return nil and leave the stream positioned at the end.
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   673
     On success, the next read operation will return the element after anObject.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   674
     - reimplemented for speed on String-Streams for faster scanning"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   675
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   676
%{  /* NOCONTEXT */
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   677
    OBJ coll, p, l;
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   678
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   679
    coll = __INST(collection);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   680
    p = __INST(position);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 970
diff changeset
   681
    l = __INST(readLimit);
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   682
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   683
    if (__isString(coll)
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   684
     && __isCharacter(anObject)
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   685
     && __bothSmallInteger(p, l)) {
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   686
	REGISTER unsigned char *chars;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   687
	REGISTER int pos, limit;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   688
	unsigned ch;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   689
	int sz;
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   690
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   691
	pos = __intVal(p);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   692
	/* make 1-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   693
	pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   694
	if (pos <= 0) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   695
	    RETURN ( nil );
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   696
	}
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   697
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   698
	limit = __intVal(l);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   699
	sz = __stringSize(coll);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   700
	if (limit > sz) limit = sz;
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   701
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   702
	chars = (unsigned char *)(__stringVal(coll) + pos - 1);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   703
	ch = __intVal(_characterVal(anObject)) & 0xFF;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   704
	while (pos < limit) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   705
	    if (*chars == ch) {
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   706
		ch = *++chars;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   707
		pos++;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   708
		/* make ZeroPosition-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   709
		pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition));
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   710
		__INST(position) = __MKSMALLINT(pos);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   711
		RETURN ( self );
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   712
	    }
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   713
	    chars++;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   714
	    pos++;
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   715
	}
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   716
	/* make ZeroPosition-based */
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   717
	pos = pos - 1 + __intVal( @global(PositionableStream:ZeroPosition));
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   718
	__INST(position) = __MKSMALLINT(pos+1);
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6814
diff changeset
   719
	RETURN ( nil );
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   720
    }
6011
3b91d7834ca5 fixed: skipThrough dod not position atEnd if the element was not found.
Claus Gittinger <cg@exept.de>
parents: 5810
diff changeset
   721
%}.
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   722
    ^ super skipThrough:anObject
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   723
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   724
59
4a86aad06603 *** empty log message ***
claus
parents: 13
diff changeset
   725
!ReadStream methodsFor:'writing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   726
a27a279701f8 Initial revision
claus
parents:
diff changeset
   727
nextPut:anElement
10
claus
parents: 5
diff changeset
   728
    "catch write access to readstreams - report an error"
claus
parents: 5
diff changeset
   729
claus
parents: 5
diff changeset
   730
    self shouldNotImplement
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   731
! !
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
   732
2162
7e1601f633b6 ff is a separator too (in #skipSeparators*)
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   733
!ReadStream class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   734
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   735
version
8098
8d1d5cd8529b nextByte should (at least) return integer when reading from a string-stream
Claus Gittinger <cg@exept.de>
parents: 7483
diff changeset
   736
    ^ '$Header: /cvs/stx/stx/libbasic/ReadStream.st,v 1.49 2004-03-05 20:00:26 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   737
! !