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