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