WriteStream.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 15 Jun 2009 20:55:05 +0100
branchjv
changeset 17711 39faaaf888b4
parent 11324 670872419b37
child 17728 bbc5fa73dfab
permissions -rw-r--r--
Added branch jv
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) 1989 by Claus Gittinger
252
claus
parents: 95
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
"
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
    12
"{ Package: 'stx:libbasic' }"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
    13
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    14
PositionableStream subclass:#WriteStream
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    15
	instanceVariableNames:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    16
	classVariableNames:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    17
	poolDictionaries:''
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    18
	category:'Streams'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
1965
4ca38574df3b Fix typo.
Stefan Vogel <sv@exept.de>
parents: 1584
diff changeset
    21
!WriteStream class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    22
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    23
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    25
 COPYRIGHT (c) 1989 by Claus Gittinger
252
claus
parents: 95
diff changeset
    26
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    27
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    28
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
68
59faa75185ba *** empty log message ***
claus
parents: 63
diff changeset
    37
documentation
59faa75185ba *** empty log message ***
claus
parents: 63
diff changeset
    38
"
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    39
    Streams for writing into.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    40
    WriteStreams are especially useful, if big strings are to be constructed
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    41
    from pieces - create a writeStream, add the pieces (with #nextPut or
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    42
    #nextPutAll) and finally fetch the concatenated string via #contents.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    43
    This is much better than constructing the big string by concatenating via
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    44
    the comma (,) operator, since less intermediate garbage objects are created.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    45
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    46
    This implementation currently DOES change the 
261
afdf1e7184ad *** empty log message ***
claus
parents: 260
diff changeset
    47
    identity if the streamed-upon collection IF it cannot grow easily. 
afdf1e7184ad *** empty log message ***
claus
parents: 260
diff changeset
    48
    Collections which cannot grow easily are for example: Array, ByteArray and String.
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    49
    Thus it is slightly incompatible to ST-80 since 'aStream contents' does 
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    50
    not always return the original collection. This may change.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    51
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1136
diff changeset
    52
    [author:]
10281
47dd93edcfa5 comment
Claus Gittinger <cg@exept.de>
parents: 10070
diff changeset
    53
        Claus Gittinger
47dd93edcfa5 comment
Claus Gittinger <cg@exept.de>
parents: 10070
diff changeset
    54
47dd93edcfa5 comment
Claus Gittinger <cg@exept.de>
parents: 10070
diff changeset
    55
    [see also:]
47dd93edcfa5 comment
Claus Gittinger <cg@exept.de>
parents: 10070
diff changeset
    56
        CharacterWriteStream (if streaming for a unicode string)
68
59faa75185ba *** empty log message ***
claus
parents: 63
diff changeset
    57
"
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    58
!
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    59
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    60
examples
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    61
"
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
    62
								[exBegin]
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    63
     |s|
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    64
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    65
     s := WriteStream on:''.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    66
     s nextPutAll:'hello';
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    67
       space;
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    68
       nextPutAll:'world'.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    69
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    70
     s contents inspect
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
    71
								[exEnd]
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    72
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
    73
								[exBegin]
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    74
     |s|
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    75
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    76
     s := WriteStream on:''.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    77
     s nextPutAll:'hello';
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    78
       space;
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    79
       nextPutAll:'world'.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    80
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    81
     Transcript nextPutLine:(s contents)
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
    82
								[exEnd]
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    83
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
    84
								[exBegin]
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    85
     |s|
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    86
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    87
     s := '' writeStream.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    88
     s nextPutAll:'hello';
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    89
       space;
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    90
       nextPutAll:'world'.
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    91
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    92
     Transcript nextPutLine:(s contents)
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
    93
								[exEnd]
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    94
"
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    95
345
claus
parents: 329
diff changeset
    96
! !
claus
parents: 329
diff changeset
    97
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7260
diff changeset
    98
!WriteStream methodsFor:'Compatibility-Dolphin'!
6325
6ea71ffec923 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5888
diff changeset
    99
6ea71ffec923 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5888
diff changeset
   100
display:someObject
6871
1c4a799a048c display: use printOn instead of printString.
Claus Gittinger <cg@exept.de>
parents: 6326
diff changeset
   101
    someObject printOn:self.
6325
6ea71ffec923 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5888
diff changeset
   102
! !
6ea71ffec923 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5888
diff changeset
   103
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   104
!WriteStream methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   105
a27a279701f8 Initial revision
claus
parents:
diff changeset
   106
contents
345
claus
parents: 329
diff changeset
   107
    "return the current contents (a collection) of the stream.
claus
parents: 329
diff changeset
   108
     Currently, this returns the actual collection if possible
claus
parents: 329
diff changeset
   109
     (and reset is implemented to create a new one) in contrast to
claus
parents: 329
diff changeset
   110
     ST80, where contents returns a copy and reset only sets the writePointer.
claus
parents: 329
diff changeset
   111
     The ST/X behavior creates less temporary garbage in the normal case
2410
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   112
     (where things are written for the contents only) but may be incompatible
345
claus
parents: 329
diff changeset
   113
     with some applications. Time will show, if this is to be changed."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   114
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   115
    |lastIndex|
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   116
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   117
    lastIndex := position - ZeroPosition.
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   118
    collection size == lastIndex ifFalse:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   119
	collection isFixedSize ifTrue:[
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   120
	    "
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   121
	     grow is expensive - return a copy.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   122
	     (is this what users of writeStream expect ?)
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   123
	    "
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   124
	    collection := collection copyFrom:1 to:lastIndex
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   125
	] ifFalse:[
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   126
	    collection grow:lastIndex
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   127
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   128
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   129
    ^ collection
2410
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   130
3087
609b8f05a250 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3031
diff changeset
   131
    "Modified: / 19.2.1997 / 08:57:28 / stefan"
609b8f05a250 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3031
diff changeset
   132
    "Modified: / 30.10.1997 / 16:21:23 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   133
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   134
5888
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   135
last
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   136
    "return the last element - report an error if the stream is empty"
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   137
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   138
    |position1Based|
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   139
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   140
    position1Based := position - ZeroPosition + 1.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   141
    ^ collection at:(position1Based - 1).
5888
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   142
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   143
    "
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   144
     |s|
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   145
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   146
     s := '' writeStream.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   147
     s nextPut:$a.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   148
     s last.       
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   149
     s nextPut:$b.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   150
     s last.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   151
     s nextPut:$c.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   152
     s last.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   153
    "
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   154
!
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   155
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   156
last:n
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   157
    "return the last n elements as species of the underlying collection;
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   158
     Report an error if the stream is empty"
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   159
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   160
    |position1Based|
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   161
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   162
    position1Based := position - ZeroPosition + 1.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   163
    ^ collection copyFrom:(position1Based - n) to:(position1Based - 1).
5888
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   164
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   165
    "
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   166
     |s|
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   167
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   168
     s := '' writeStream.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   169
     s nextPut:$a.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   170
     s last:1.       
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   171
     s nextPut:$b.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   172
     s last:1.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   173
     s last:2.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   174
     s nextPut:$c.
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   175
     s last:1.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   176
     s last:2.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   177
     s last:3.        
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   178
    "
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   179
!
64d077a702c7 added #last and #last:
Claus Gittinger <cg@exept.de>
parents: 5556
diff changeset
   180
329
claus
parents: 293
diff changeset
   181
reset
345
claus
parents: 329
diff changeset
   182
    "reset the stream; write anew.
2410
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   183
     See the comment in WriteStream>>contents"
329
claus
parents: 293
diff changeset
   184
claus
parents: 293
diff changeset
   185
    collection := collection species new:(collection size).
claus
parents: 293
diff changeset
   186
    super reset
2410
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   187
eea60bba0412 Fix typos.
Stefan Vogel <sv@exept.de>
parents: 1965
diff changeset
   188
    "Modified: 19.2.1997 / 08:57:00 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   189
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   190
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   191
!WriteStream methodsFor:'positioning'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   192
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   193
position0Based:index0Based
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   194
    "redefined to allow positioning past the readLimit"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   195
7052
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   196
    ((index0Based > collection size) or:[index0Based < 0]) ifTrue: [^ self positionError].
207cc9c62982 prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents: 7051
diff changeset
   197
    position := index0Based + ZeroPosition
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   198
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   199
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   200
!WriteStream methodsFor:'private'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   201
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   202
growCollection
2863
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   203
    "grow the streamed collection to at least 10 elements"
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   204
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   205
    self growCollection:10
2863
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   206
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   207
    "Modified: 19.8.1997 / 17:53:28 / cg"
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   208
!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   209
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   210
growCollection:minNewSize
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   211
    "grow the streamed collection to at least minNewSize"
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   212
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   213
    |oldSize newSize newColl|
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   214
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   215
    oldSize := collection size.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   216
    (oldSize == 0) ifTrue:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   217
	newSize := minNewSize
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   218
    ] ifFalse:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   219
	newSize := oldSize * 2.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   220
	(newSize < minNewSize) ifTrue:[newSize := minNewSize].
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   221
    ].
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   222
    collection isFixedSize ifTrue:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   223
	newColl := collection species new:newSize.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   224
	newColl replaceFrom:1 to:oldSize with:collection startingAt:1.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   225
	collection := newColl
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   226
    ] ifFalse:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   227
	collection grow:newSize
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   228
    ].
2863
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   229
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   230
    "Modified: 19.8.1997 / 17:53:11 / cg"
8868
12ac754138b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8615
diff changeset
   231
!
12ac754138b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8615
diff changeset
   232
12ac754138b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8615
diff changeset
   233
setCollection:newCollection
12ac754138b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8615
diff changeset
   234
    collection := newCollection
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   235
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   236
7260
edfa8d6a6046 method category rename
Claus Gittinger <cg@exept.de>
parents: 7113
diff changeset
   237
!WriteStream methodsFor:'private-accessing'!
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   238
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   239
on:aCollection from:start to:last
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   240
    "create and return a new stream for writing onto aCollection, where
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   241
     writing is limited to the elements in the range start to last."
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   242
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   243
    super on:aCollection from:start to:last.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   244
    writeLimit := last.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   245
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   246
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   247
!WriteStream methodsFor:'queries'!
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   248
3098
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   249
isReadable 
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   250
    "return true if the receiver supports reading - thats not true"
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   251
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   252
    ^ false
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   253
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   254
    "Created: / 8.11.1997 / 14:06:07 / cg"
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   255
!
4203b0d13fc8 added #isReadable (ST80 compat)
Claus Gittinger <cg@exept.de>
parents: 3087
diff changeset
   256
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   257
isWritable
1405
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   258
    "return true, if writing is supported by the recevier.
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   259
     Always return true here"
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   260
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   261
    ^ true
1405
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   262
f4ab59f3888a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1398
diff changeset
   263
    "Modified: 16.5.1996 / 14:44:49 / cg"
3031
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   264
!
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   265
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   266
size
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   267
    "return the current size"
565ba030c404 added #size & #isEmpty
Claus Gittinger <cg@exept.de>
parents: 2899
diff changeset
   268
9311
5682c109e49f remove dead code
Stefan Vogel <sv@exept.de>
parents: 8913
diff changeset
   269
    ^ position - ZeroPosition
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   270
! !
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   271
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   272
!WriteStream methodsFor:'reading'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   273
a27a279701f8 Initial revision
claus
parents:
diff changeset
   274
next
10
claus
parents: 5
diff changeset
   275
    "catch read access to write stream - report an error"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   276
10
claus
parents: 5
diff changeset
   277
    self shouldNotImplement
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   278
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   279
a27a279701f8 Initial revision
claus
parents:
diff changeset
   280
peek
10
claus
parents: 5
diff changeset
   281
    "catch read access to write stream - report an error"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   282
10
claus
parents: 5
diff changeset
   283
    self shouldNotImplement
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   284
! !
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   285
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   286
!WriteStream methodsFor:'testing'!
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   287
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   288
isEmpty
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   289
    "return true, if the contents of the stream is empty"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   290
7620
cf2c3d9d6d9c Fix #isEmpty for external streams.
Stefan Vogel <sv@exept.de>
parents: 7261
diff changeset
   291
    ^ self position0Based == ZeroPosition
5556
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   292
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   293
    "Created: 14.10.1997 / 20:44:37 / cg"
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   294
! !
1056cc5d6ce0 category change
Claus Gittinger <cg@exept.de>
parents: 5198
diff changeset
   295
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   296
!WriteStream methodsFor:'writing'!
369
claus
parents: 359
diff changeset
   297
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   298
next:count put:anObject
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   299
    "append anObject count times to the receiver.
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   300
     Redefined to avoid count grows of the underlying collection -
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   301
     instead a single grow on the final size is performed."
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   302
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   303
    |final position1Based|
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   304
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   305
    (collection isNil or:[writeLimit notNil]) ifTrue:[
7113
23182ef346a5 position fixes
Claus Gittinger <cg@exept.de>
parents: 7052
diff changeset
   306
        ^ super next:count put:anObject
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   307
    ].
369
claus
parents: 359
diff changeset
   308
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   309
    position1Based := position - ZeroPosition + 1.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   310
    final := position1Based + count - 1.
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   311
    (final > collection size) ifTrue:[
7113
23182ef346a5 position fixes
Claus Gittinger <cg@exept.de>
parents: 7052
diff changeset
   312
        self growCollection:final
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   313
    ].
369
claus
parents: 359
diff changeset
   314
7113
23182ef346a5 position fixes
Claus Gittinger <cg@exept.de>
parents: 7052
diff changeset
   315
    position1Based to:final do:[:index |
23182ef346a5 position fixes
Claus Gittinger <cg@exept.de>
parents: 7052
diff changeset
   316
        collection at:index put:anObject.
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   317
    ].
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   318
    position1Based := position1Based + count.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   319
    (position1Based > readLimit) ifTrue:[readLimit := position1Based - 1].
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   320
    position := position1Based - 1 + ZeroPosition.
611
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   321
    ^ anObject
80bb0f1a7bab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   322
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   323
5198
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   324
next:n putAll:aCollection startingAt:pos1
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   325
    "append some elements of the argument, aCollection to the stream."
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   326
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   327
    ^ self nextPutAll:aCollection startingAt:pos1 to:pos1+n-1
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   328
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   329
    "
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   330
     |s|
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   331
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   332
     s := '' writeStream.
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   333
     s nextPutAll:'hello '.
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   334
     s next:5 putAll:'1234world012345' startingAt:5.
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   335
     s contents   
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   336
    "
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   337
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   338
    "Modified: 12.7.1996 / 10:31:36 / cg"
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   339
!
ca2c2f7ec69c added #next:putAll:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4406
diff changeset
   340
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   341
nextPut:anObject
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   342
    "append the argument, anObject to the stream.
2863
aec08a0c2c2e no need for unsigned compare against 0
Claus Gittinger <cg@exept.de>
parents: 2410
diff changeset
   343
     Specially tuned for appending to String, ByteArray and Array streams."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   344
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   345
%{  /* NOCONTEXT */
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   346
8293
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   347
#ifndef NO_PRIM_STREAM
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   348
    REGISTER int pos;
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   349
    unsigned ch;
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   350
    OBJ coll;
2883
ee0eb799bd3e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
   351
    OBJ p, wL, rL;
1584
cad4f2c515c7 nextPut: slightly modified
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
   352
    int __readLimit = -1;
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   353
1136
898af060dfde underline cleanup
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
   354
    coll = __INST(collection);
898af060dfde underline cleanup
Claus Gittinger <cg@exept.de>
parents: 838
diff changeset
   355
    p = __INST(position);
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   356
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   357
    if (__isNonNilObject(coll) && __isSmallInteger(p)) {
8293
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   358
        pos = __intVal(p);
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   359
        /* make 1-based */
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   360
        pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   361
        wL = __INST(writeLimit);
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   362
8293
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   363
        if ((wL == nil)
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   364
         || (__isSmallInteger(wL) && (pos <= __intVal(wL)))) {
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   365
            OBJ cls;
252
claus
parents: 95
diff changeset
   366
8293
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   367
            cls = __qClass(coll);
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   368
8293
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   369
            rL = __INST(readLimit);
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   370
            if (__isSmallInteger(rL)) {
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   371
                __readLimit = __intVal(rL);
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   372
            }
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   373
8293
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   374
            if (cls == @global(String)) {
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   375
                if (__isCharacter(anObject) 
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   376
                 && ((ch = __intVal(__characterVal(anObject))) <= 255) /* ch is unsigned */
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   377
                 && (pos <= __stringSize(coll))) {
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   378
                    __StringInstPtr(coll)->s_element[pos-1] = ch;
8615
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   379
advancePositionAndReturn: ;            
8293
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   380
                    if ((__readLimit >= 0) && (pos >= __readLimit)) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8868
diff changeset
   381
                        __INST(readLimit) = __mkSmallInteger(pos);
8293
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   382
                    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8868
diff changeset
   383
                    __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
8293
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   384
                    RETURN ( anObject );
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   385
                }
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   386
            } else if (cls == @global(ByteArray)) {
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   387
                if (__isSmallInteger(anObject) 
8296
5c989a1551fa *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 8293
diff changeset
   388
                 && ((ch = __intVal(anObject)) <= 0xFF) /* ch is unsigned */
8293
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   389
                 && (pos <= __byteArraySize(coll))) {
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   390
                    __ByteArrayInstPtr(coll)->ba_element[pos-1] = ch;
8615
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   391
                    goto advancePositionAndReturn;
8293
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   392
                }
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   393
            } else if (cls == @global(Array)) {
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   394
                if (pos <= __arraySize(coll)) {
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   395
                     __ArrayInstPtr(coll)->a_element[pos-1] = anObject;
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   396
                    __STORE(coll, anObject);
8615
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   397
                    goto advancePositionAndReturn;
8293
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   398
                }
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   399
            } else if (cls == @global(Unicode16String)) {
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   400
                if (__isCharacter(anObject) 
8296
5c989a1551fa *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 8293
diff changeset
   401
                 && ((ch = __intVal(__characterVal(anObject))) <= 0xFFFF) /* ch is unsigned */
8293
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   402
                 && (pos <= __unicode16StringSize(coll))) {
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   403
                     __Unicode16StringInstPtr(coll)->s_element[pos-1] = ch;
8615
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   404
                    goto advancePositionAndReturn;
8293
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   405
                }
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   406
            } else if (cls == @global(Unicode32String)) {
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   407
                if (__isCharacter(anObject) 
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   408
                 && (pos <= __unicode32StringSize(coll))) {
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   409
                     __Unicode32StringInstPtr(coll)->s_element[pos-1] = __intVal(__characterVal(anObject));
8615
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   410
                    goto advancePositionAndReturn;
8293
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   411
                }
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   412
            }
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   413
        }
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   414
    }
2894
344aec8ba014 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2883
diff changeset
   415
#endif
260
cefb485445a7 *** empty log message ***
claus
parents: 252
diff changeset
   416
%}.
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   417
    (writeLimit isNil
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   418
    or:[(position + 1 - ZeroPosition) <= writeLimit]) ifTrue:[
8293
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   419
        ((position + 1 - ZeroPosition) > collection size) ifTrue:[self growCollection].
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   420
        collection at:(position + 1 - ZeroPosition) put:anObject.
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   421
        ((position + 1 - ZeroPosition) > readLimit) ifTrue:[readLimit := (position + 1 - ZeroPosition)].
dcffeb2c11e0 Optimize #nextPut: on UnicodeStrings
Stefan Vogel <sv@exept.de>
parents: 7686
diff changeset
   422
        position := position + 1.
838
67a53cceaab1 no global refs
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   423
    ] ifFalse:[
8320
229adaeaf183 Use exception classes instead of class vars
Stefan Vogel <sv@exept.de>
parents: 8296
diff changeset
   424
        WriteError raiseErrorString:'write beyond writeLimit'
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   425
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   426
    ^anObject
a27a279701f8 Initial revision
claus
parents:
diff changeset
   427
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   428
a27a279701f8 Initial revision
claus
parents:
diff changeset
   429
nextPutAll:aCollection
63
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   430
    "append all elements of the argument, aCollection to the stream.
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   431
     Redefined to avoid count grows of the underlying collection -
1f0cdefb013f *** empty log message ***
claus
parents: 10
diff changeset
   432
     instead a single grow on the final size is performed."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   433
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   434
    |nMore final position1Based|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   435
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   436
    collection isNil ifTrue:[
7686
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7620
diff changeset
   437
        ^ super nextPutAll:aCollection
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   438
    ].
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   439
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   440
    position1Based := position - ZeroPosition + 1.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   441
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   442
    nMore := aCollection size.
9499
01ee6017569e check for non-colelction in nextPutAll:
fm
parents: 9311
diff changeset
   443
    nMore == 0 ifTrue:[
01ee6017569e check for non-colelction in nextPutAll:
fm
parents: 9311
diff changeset
   444
        "/ for the programmer..
01ee6017569e check for non-colelction in nextPutAll:
fm
parents: 9311
diff changeset
   445
        aCollection isCollection ifFalse:[
10070
ee4e2cf0a591 non-collection argument error is proceedable
fm
parents: 9499
diff changeset
   446
            self error:'invalid argument (not a collection)' mayProceed:true
9499
01ee6017569e check for non-colelction in nextPutAll:
fm
parents: 9311
diff changeset
   447
        ].
01ee6017569e check for non-colelction in nextPutAll:
fm
parents: 9311
diff changeset
   448
    ].
01ee6017569e check for non-colelction in nextPutAll:
fm
parents: 9311
diff changeset
   449
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   450
    final := position1Based + nMore - 1.
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   451
    (writeLimit notNil
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   452
    and:[final > writeLimit]) ifTrue:[
7686
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7620
diff changeset
   453
        final := writeLimit.
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7620
diff changeset
   454
        nMore := final - position1Based + 1
293
31df3850e98c *** empty log message ***
claus
parents: 261
diff changeset
   455
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   456
    (final > collection size) ifTrue:[
7686
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7620
diff changeset
   457
        self growCollection:final
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   458
    ].
7686
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7620
diff changeset
   459
    collection 
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7620
diff changeset
   460
        replaceFrom:position1Based
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7620
diff changeset
   461
        to:final
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7620
diff changeset
   462
        with:aCollection 
290cda6075ac String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7620
diff changeset
   463
        startingAt:1.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   464
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   465
    position1Based := position1Based + nMore.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   466
    (position1Based > readLimit) ifTrue:[readLimit := position1Based - 1].
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   467
    position := position1Based - 1 + ZeroPosition.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   468
    ^ aCollection
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   469
!
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   470
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   471
nextPutAll:aCollection startingAt:pos1 to:pos2
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   472
    "append some elements of the argument, aCollection to the stream.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   473
     Redefined to avoid count grows of the underlying collection -
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   474
     instead a single grow on the final size is performed."
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   475
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   476
    |nMore final position1Based|
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   477
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   478
    collection isNil ifTrue:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   479
	^ super nextPutAll:aCollection startingAt:pos1 to:pos2
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   480
    ].
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   481
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   482
    position1Based := position - ZeroPosition + 1.
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   483
    nMore := pos2 - pos1 + 1.
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   484
    final := position1Based + nMore - 1.
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   485
    (writeLimit notNil
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   486
    and:[final > writeLimit]) ifTrue:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   487
	final := writeLimit.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   488
	nMore := final - position1Based + 1
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   489
    ].
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   490
    (final > collection size) ifTrue:[
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   491
	self growCollection:final
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   492
    ].
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   493
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   494
    collection replaceFrom:position1Based
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   495
			to:final
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   496
		      with:aCollection 
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   497
		startingAt:pos1.
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   498
7051
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   499
    position1Based := position1Based + nMore.
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   500
    (position1Based > readLimit) ifTrue:[readLimit := position1Based - 1].
984d8271d06b preps for 0-based stream positions
Claus Gittinger <cg@exept.de>
parents: 6871
diff changeset
   501
    position := position1Based - 1 + ZeroPosition.
1539
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   502
    ^ aCollection
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   503
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   504
    "
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   505
     |s|
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   506
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   507
     s := '' writeStream.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   508
     s nextPutAll:'hello '.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   509
     s nextPutAll:'1234world012345' startingAt:5 to:9.
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   510
     s contents
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   511
    "
b1ac096a81e3 added #nextPutAll:startingAt:to:
Claus Gittinger <cg@exept.de>
parents: 1405
diff changeset
   512
1541
6ed5feddc4ed checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1539
diff changeset
   513
    "Modified: 12.7.1996 / 10:31:36 / cg"
8361
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   514
!
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   515
11324
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   516
nextPutAllUnicode:aString
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   517
    "normal streams can not handle multi-byte characters, so convert them to utf8"
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   518
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   519
    (collection isString and:[collection bitsPerCharacter == 8]) ifTrue:[
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   520
        aString do:[:eachCharacter|
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   521
            self nextPutUtf8:eachCharacter.
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   522
        ].
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   523
    ] ifFalse:[
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   524
        self nextPutAll:aString
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   525
    ].
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   526
!
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   527
8615
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   528
nextPutByte:anObject
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   529
    "append the argument, anObject to the stream.
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   530
     Specially tuned for appending to String and ByteArray streams."
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   531
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   532
%{  /* NOCONTEXT */
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   533
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   534
#ifndef NO_PRIM_STREAM
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   535
    REGISTER int pos;
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   536
    OBJ coll;
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   537
    OBJ p, wL, rL;
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   538
    int __readLimit = -1;
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   539
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   540
    coll = __INST(collection);
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   541
    p = __INST(position);
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   542
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   543
    if (__isNonNilObject(coll) && __isSmallInteger(p) && __isSmallInteger(anObject)) {
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   544
        unsigned ch;
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   545
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   546
        ch = __intVal(anObject);
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   547
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   548
        pos = __intVal(p);
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   549
        /* make 1-based */
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   550
        pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition));
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   551
        wL = __INST(writeLimit);
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   552
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   553
        if ((wL == nil)
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   554
         || (__isSmallInteger(wL) && (pos <= __intVal(wL)))) {
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   555
            OBJ cls;
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   556
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   557
            cls = __qClass(coll);
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   558
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   559
            rL = __INST(readLimit);
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   560
            if (__isSmallInteger(rL)) {
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   561
                __readLimit = __intVal(rL);
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   562
            }
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   563
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   564
            if (cls == @global(String)) {
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   565
                if ((pos <= __stringSize(coll))
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   566
                 && (ch <= 0xFF)) { /* ch is unsigned */
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   567
                    __StringInstPtr(coll)->s_element[pos-1] = ch;
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   568
    advancePositionAndReturn: ;            
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   569
                    if ((__readLimit >= 0) && (pos >= __readLimit)) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8868
diff changeset
   570
                        __INST(readLimit) = __mkSmallInteger(pos);
8615
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   571
                    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8868
diff changeset
   572
                    __INST(position) = __mkSmallInteger(__intVal(__INST(position)) + 1);
8615
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   573
                    RETURN ( anObject );
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   574
                }
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   575
            } else if (cls == @global(ByteArray)) {
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   576
                if ((pos <= __byteArraySize(coll))
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   577
                 && (ch <= 0xFF)) { /* ch is unsigned */
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   578
                    __ByteArrayInstPtr(coll)->ba_element[pos-1] = ch;
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   579
                    goto advancePositionAndReturn;
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   580
                }
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   581
            }
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   582
        }
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   583
    }
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   584
#endif
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   585
%}.
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   586
    ^ super nextPutByte:anObject
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   587
!
df60f835f2e0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8437
diff changeset
   588
8361
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   589
nextPutBytes:count from:anObject startingAt:start
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   590
    "write count bytes from an object starting at index start.
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   591
     Return the number of bytes written.
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   592
     The object must have non-pointer indexed instvars 
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   593
     (i.e. be a ByteArray, String, Float- or DoubleArray).     
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   594
     Use with care - non object oriented i/o.
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   595
     This is provided for compatibility with externalStream;
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   596
     to support binary storage"
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   597
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   598
    anObject class isBytes ifTrue:[
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   599
        self nextPutAll:anObject startingAt:start to:(start + count - 1).
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   600
        ^ count.
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   601
    ].
726a906f1901 tuned nextPutBytes
Claus Gittinger <cg@exept.de>
parents: 8320
diff changeset
   602
    ^ super nextPutBytes:count from:anObject startingAt:start
11324
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   603
!
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   604
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   605
nextPutUnicode:aCharacter
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   606
    "normal streams can not handle multi-byte characters, so convert them to utf8"
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   607
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   608
    (collection isString and:[collection bitsPerCharacter == 8]) ifTrue:[
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   609
        self nextPutUtf8:aCharacter.
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   610
    ] ifFalse:[
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   611
        self nextPut:aCharacter.
670872419b37 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 10281
diff changeset
   612
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   613
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   614
1965
4ca38574df3b Fix typo.
Stefan Vogel <sv@exept.de>
parents: 1584
diff changeset
   615
!WriteStream class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   616
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   617
version
17711
39faaaf888b4 Added branch jv
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11324
diff changeset
   618
    ^ '$Id: WriteStream.st 10447 2009-06-14 13:09:55Z vranyj1 $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   619
! !