EncodedStream.st
author Claus Gittinger <cg@exept.de>
Fri, 29 Jul 2011 17:43:00 +0200
changeset 13525 e17ebc11ca73
parent 13400 8dcdfacd2f34
child 14084 341e275c4bba
permissions -rw-r--r--
changed: #skipEncodingChunk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8148
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
     1
"
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
     2
 COPYRIGHT (c) 2004 by eXept Software AG
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
     3
              All Rights Reserved
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
     4
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
     5
 This software is furnished under a license and may be used
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
     6
 only in accordance with the terms of that license and with the
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
     8
 be provided or otherwise made available to, or used by, any
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
     9
 other person.  No title to or ownership of the software is
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
    10
 hereby transferred.
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
    11
"
8047
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libbasic' }"
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
8447
9bdea3431846 EncodedStream inherts from PeekableStream
Stefan Vogel <sv@exept.de>
parents: 8444
diff changeset
    14
PeekableStream subclass:#EncodedStream
8047
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
	instanceVariableNames:'encoder stream'
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	classVariableNames:''
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	category:'Collections-Text-Encodings'
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
8148
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
    21
!EncodedStream class methodsFor:'documentation'!
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
    22
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
    23
copyright
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
    24
"
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
    25
 COPYRIGHT (c) 2004 by eXept Software AG
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
    26
              All Rights Reserved
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
    27
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
    28
 This software is furnished under a license and may be used
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
    29
 only in accordance with the terms of that license and with the
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
    31
 be provided or otherwise made available to, or used by, any
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
    32
 other person.  No title to or ownership of the software is
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
    33
 hereby transferred.
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
    34
"
dbf64e3142d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8147
diff changeset
    35
! !
8047
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
!EncodedStream class methodsFor:'instance creation'!
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
stream:streamArg encoder:encoder
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
    ^ (self basicNew) stream:streamArg; encoder:encoder
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
! !
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
12610
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    43
!EncodedStream class methodsFor:'utilities'!
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    44
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    45
decodedStreamFor:aStream
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    46
    |encoding decoder decodedStream|
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    47
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    48
    "/ setup for no-encoding; allows for a later switch to a real encoder,
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    49
    "/ whenever an encoding pragma is encountered later.
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    50
    decoder := CharacterEncoder nullEncoderInstance.
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    51
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    52
    aStream isPositionable ifTrue:[
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    53
        encoding := CharacterEncoder guessEncodingOfStream:aStream.
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    54
        (encoding notNil
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    55
        and:[ encoding ~= #'iso8859-1' 
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    56
        and:[ encoding ~= #'ascii' ]]) ifTrue:[
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    57
            decoder := CharacterEncoder encoderFor:encoding.
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    58
        ].
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    59
    ].
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    60
    decodedStream := EncodedStream stream:aStream encoder:decoder.
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    61
    decodedStream skipEncodingChunk.
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    62
    ^ decodedStream
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    63
! !
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
    64
8047
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
!EncodedStream methodsFor:'accessing'!
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
11992
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
    67
contentsSpecies
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
    68
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
    69
    "Not sure if this is ok"
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
    70
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
    71
    ^ stream contentsSpecies.
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
    72
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
    73
"/    ^UnicodeString
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
    74
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
    75
    "Created: / 14-06-2005 / 17:11:01 / janfrog"
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
    76
!
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
    77
8047
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
encoder
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    ^ encoder
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
!
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
encoder:something
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
    encoder := something.
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
!
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
12646
ee2144f97338 added: #pathName
Stefan Vogel <sv@exept.de>
parents: 12610
diff changeset
    86
pathName
ee2144f97338 added: #pathName
Stefan Vogel <sv@exept.de>
parents: 12610
diff changeset
    87
    "if our base stream hat a pathname, delegate..."
ee2144f97338 added: #pathName
Stefan Vogel <sv@exept.de>
parents: 12610
diff changeset
    88
ee2144f97338 added: #pathName
Stefan Vogel <sv@exept.de>
parents: 12610
diff changeset
    89
    stream isNil ifTrue:[
ee2144f97338 added: #pathName
Stefan Vogel <sv@exept.de>
parents: 12610
diff changeset
    90
        ^ nil.
ee2144f97338 added: #pathName
Stefan Vogel <sv@exept.de>
parents: 12610
diff changeset
    91
    ].
ee2144f97338 added: #pathName
Stefan Vogel <sv@exept.de>
parents: 12610
diff changeset
    92
    ^ stream pathName.
ee2144f97338 added: #pathName
Stefan Vogel <sv@exept.de>
parents: 12610
diff changeset
    93
!
ee2144f97338 added: #pathName
Stefan Vogel <sv@exept.de>
parents: 12610
diff changeset
    94
11766
b26aac1e4eb1 *** empty log message ***
Michael Beyl <mb@exept.de>
parents: 8712
diff changeset
    95
readStream
b26aac1e4eb1 *** empty log message ***
Michael Beyl <mb@exept.de>
parents: 8712
diff changeset
    96
    ^ self
b26aac1e4eb1 *** empty log message ***
Michael Beyl <mb@exept.de>
parents: 8712
diff changeset
    97
!
b26aac1e4eb1 *** empty log message ***
Michael Beyl <mb@exept.de>
parents: 8712
diff changeset
    98
8047
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
stream
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
    ^ stream
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
!
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
stream:something
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
    stream := something.
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
! !
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
!EncodedStream methodsFor:'stream protocol'!
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
8175
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   109
atEnd
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   110
    ^ stream atEnd
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   111
!
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   112
8165
d6446fc1ea3b more stream protocol
ca
parents: 8148
diff changeset
   113
close
d6446fc1ea3b more stream protocol
ca
parents: 8148
diff changeset
   114
    stream close
d6446fc1ea3b more stream protocol
ca
parents: 8148
diff changeset
   115
!
d6446fc1ea3b more stream protocol
ca
parents: 8148
diff changeset
   116
13400
8dcdfacd2f34 changed: #version_CVS
vrany
parents: 12690
diff changeset
   117
contents
8dcdfacd2f34 changed: #version_CVS
vrany
parents: 12690
diff changeset
   118
8dcdfacd2f34 changed: #version_CVS
vrany
parents: 12690
diff changeset
   119
    ^String streamContents:
8dcdfacd2f34 changed: #version_CVS
vrany
parents: 12690
diff changeset
   120
        [:s|
8dcdfacd2f34 changed: #version_CVS
vrany
parents: 12690
diff changeset
   121
        [ stream atEnd ] whileFalse:
8dcdfacd2f34 changed: #version_CVS
vrany
parents: 12690
diff changeset
   122
            [s nextPut: stream next]
8dcdfacd2f34 changed: #version_CVS
vrany
parents: 12690
diff changeset
   123
        ]
8dcdfacd2f34 changed: #version_CVS
vrany
parents: 12690
diff changeset
   124
8dcdfacd2f34 changed: #version_CVS
vrany
parents: 12690
diff changeset
   125
    "Created: / 25-02-2010 / 23:34:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
8dcdfacd2f34 changed: #version_CVS
vrany
parents: 12690
diff changeset
   126
!
8dcdfacd2f34 changed: #version_CVS
vrany
parents: 12690
diff changeset
   127
8213
0f9d34b2afb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   128
cr
8459
1f59b17291a3 *** empty log message ***
penk
parents: 8447
diff changeset
   129
    self nextPutAll:(Character cr asString)
8213
0f9d34b2afb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   130
!
0f9d34b2afb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   131
11992
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   132
emphasis:anObject
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   133
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   134
    stream emphasis:anObject
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   135
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   136
    "Created: / 15-06-2005 / 11:16:33 / janfrog"
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   137
!
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   138
11946
1d2aefade06e +isOpen
Claus Gittinger <cg@exept.de>
parents: 11766
diff changeset
   139
isOpen
12690
1dab7b405304 changed: #isOpen
Stefan Vogel <sv@exept.de>
parents: 12646
diff changeset
   140
    ^ stream notNil and:[stream isOpen]
11946
1d2aefade06e +isOpen
Claus Gittinger <cg@exept.de>
parents: 11766
diff changeset
   141
!
1d2aefade06e +isOpen
Claus Gittinger <cg@exept.de>
parents: 11766
diff changeset
   142
11766
b26aac1e4eb1 *** empty log message ***
Michael Beyl <mb@exept.de>
parents: 8712
diff changeset
   143
next
11992
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   144
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   145
    ^encoder readNextCharacterFrom:stream
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   146
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   147
    "Created: / 14-06-2005 / 17:01:39 / janfrog"
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   148
!
11766
b26aac1e4eb1 *** empty log message ***
Michael Beyl <mb@exept.de>
parents: 8712
diff changeset
   149
11992
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   150
next:charactersToRead
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   151
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   152
    ^encoder readNext:charactersToRead charactersFrom:stream
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   153
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   154
    "Created: / 16-06-2005 / 11:43:43 / masca"
11766
b26aac1e4eb1 *** empty log message ***
Michael Beyl <mb@exept.de>
parents: 8712
diff changeset
   155
!
b26aac1e4eb1 *** empty log message ***
Michael Beyl <mb@exept.de>
parents: 8712
diff changeset
   156
8147
416bcaa573ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 8047
diff changeset
   157
nextChunk
8175
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   158
    |chunk|
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   159
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   160
    chunk := stream nextChunk.
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   161
    chunk isNil ifTrue:[^ chunk].
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   162
    ^ encoder decodeString:chunk
8147
416bcaa573ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 8047
diff changeset
   163
!
416bcaa573ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 8047
diff changeset
   164
8213
0f9d34b2afb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   165
nextChunkPut:chunk
0f9d34b2afb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   166
    stream nextChunkPut:(encoder encodeString:chunk)
0f9d34b2afb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   167
!
0f9d34b2afb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   168
8047
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
nextPut:aCharacter
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
    self nextPutAll:(aCharacter asString).
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
!
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
nextPutAll:aCollection
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
    stream nextPutAll:(encoder encodeString:aCollection).
8147
416bcaa573ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 8047
diff changeset
   175
!
416bcaa573ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 8047
diff changeset
   176
8444
354d0c48618d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8213
diff changeset
   177
peek
11992
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   178
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   179
    ^stream peek
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   180
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   181
    "Created: / 20-06-2005 / 10:13:03 / masca"
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   182
    "Modified: / 20-06-2005 / 13:06:14 / masca"
8444
354d0c48618d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8213
diff changeset
   183
!
354d0c48618d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8213
diff changeset
   184
8175
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   185
peekFor:aCharacter
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   186
    ^ stream peekFor:aCharacter
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   187
!
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   188
8165
d6446fc1ea3b more stream protocol
ca
parents: 8148
diff changeset
   189
position
d6446fc1ea3b more stream protocol
ca
parents: 8148
diff changeset
   190
    ^ stream position
d6446fc1ea3b more stream protocol
ca
parents: 8148
diff changeset
   191
!
d6446fc1ea3b more stream protocol
ca
parents: 8148
diff changeset
   192
8197
4fccb2671b9d stream protocol
Claus Gittinger <cg@exept.de>
parents: 8175
diff changeset
   193
position0Based
11947
18ce463920de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11946
diff changeset
   194
    "to be obsoleted - use position"
18ce463920de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11946
diff changeset
   195
8197
4fccb2671b9d stream protocol
Claus Gittinger <cg@exept.de>
parents: 8175
diff changeset
   196
    ^ stream position0Based
4fccb2671b9d stream protocol
Claus Gittinger <cg@exept.de>
parents: 8175
diff changeset
   197
!
4fccb2671b9d stream protocol
Claus Gittinger <cg@exept.de>
parents: 8175
diff changeset
   198
4fccb2671b9d stream protocol
Claus Gittinger <cg@exept.de>
parents: 8175
diff changeset
   199
position0Based:newPosition
11947
18ce463920de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11946
diff changeset
   200
    "to be obsoleted - use position"
18ce463920de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11946
diff changeset
   201
8197
4fccb2671b9d stream protocol
Claus Gittinger <cg@exept.de>
parents: 8175
diff changeset
   202
    stream position0Based:newPosition
4fccb2671b9d stream protocol
Claus Gittinger <cg@exept.de>
parents: 8175
diff changeset
   203
!
4fccb2671b9d stream protocol
Claus Gittinger <cg@exept.de>
parents: 8175
diff changeset
   204
8175
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   205
position1Based
11947
18ce463920de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11946
diff changeset
   206
    "to be obsoleted - use position"
18ce463920de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11946
diff changeset
   207
8175
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   208
    ^ stream position1Based
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   209
!
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   210
8147
416bcaa573ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 8047
diff changeset
   211
position1Based:newPosition
11947
18ce463920de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11946
diff changeset
   212
    "to be obsoleted - use position"
18ce463920de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11946
diff changeset
   213
8147
416bcaa573ef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 8047
diff changeset
   214
    stream position1Based:newPosition
8175
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   215
!
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   216
8197
4fccb2671b9d stream protocol
Claus Gittinger <cg@exept.de>
parents: 8175
diff changeset
   217
position:newPosition
4fccb2671b9d stream protocol
Claus Gittinger <cg@exept.de>
parents: 8175
diff changeset
   218
    stream position:newPosition
4fccb2671b9d stream protocol
Claus Gittinger <cg@exept.de>
parents: 8175
diff changeset
   219
!
4fccb2671b9d stream protocol
Claus Gittinger <cg@exept.de>
parents: 8175
diff changeset
   220
13400
8dcdfacd2f34 changed: #version_CVS
vrany
parents: 12690
diff changeset
   221
reset
8dcdfacd2f34 changed: #version_CVS
vrany
parents: 12690
diff changeset
   222
    stream reset
8dcdfacd2f34 changed: #version_CVS
vrany
parents: 12690
diff changeset
   223
8dcdfacd2f34 changed: #version_CVS
vrany
parents: 12690
diff changeset
   224
    "Created: / 25-02-2010 / 23:37:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
8dcdfacd2f34 changed: #version_CVS
vrany
parents: 12690
diff changeset
   225
!
8dcdfacd2f34 changed: #version_CVS
vrany
parents: 12690
diff changeset
   226
8213
0f9d34b2afb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   227
setToEnd
0f9d34b2afb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   228
    stream setToEnd
0f9d34b2afb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   229
!
0f9d34b2afb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   230
11992
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   231
skip: anInteger
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   232
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   233
    "/ Should skip on character basis, not on bytes. This works for XML reader
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   234
    ^stream skip: anInteger
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   235
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   236
    "Created: / 20-06-2005 / 13:06:06 / masca"
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   237
!
1d7a1c1c1ccc extended protocol
fm
parents: 11947
diff changeset
   238
8175
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   239
skipSeparators
3548845d3c09 more stream protocol
Claus Gittinger <cg@exept.de>
parents: 8165
diff changeset
   240
    ^ stream skipSeparators
8047
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
! !
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
8712
bcef3a0c0a1d skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents: 8459
diff changeset
   243
!EncodedStream methodsFor:'utilities'!
bcef3a0c0a1d skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents: 8459
diff changeset
   244
bcef3a0c0a1d skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents: 8459
diff changeset
   245
skipEncodingChunk
bcef3a0c0a1d skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents: 8459
diff changeset
   246
    |pos chunk tree|
bcef3a0c0a1d skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents: 8459
diff changeset
   247
13525
e17ebc11ca73 changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents: 13400
diff changeset
   248
    stream isPositionable ifFalse:[
e17ebc11ca73 changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents: 13400
diff changeset
   249
        ^ self
e17ebc11ca73 changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents: 13400
diff changeset
   250
    ].
e17ebc11ca73 changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents: 13400
diff changeset
   251
8712
bcef3a0c0a1d skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents: 8459
diff changeset
   252
    pos := self position.
bcef3a0c0a1d skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents: 8459
diff changeset
   253
    chunk := self nextChunk.
bcef3a0c0a1d skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents: 8459
diff changeset
   254
    tree := (Parser parseExpression:chunk).
bcef3a0c0a1d skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents: 8459
diff changeset
   255
    "/ if this is a valid chunk (i.e. not a comment or encoding-directive),
bcef3a0c0a1d skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents: 8459
diff changeset
   256
    "/ then position back, so it will be processed as usual.
bcef3a0c0a1d skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents: 8459
diff changeset
   257
    tree notNil ifTrue:[
bcef3a0c0a1d skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents: 8459
diff changeset
   258
        self position:pos
bcef3a0c0a1d skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents: 8459
diff changeset
   259
    ]
13525
e17ebc11ca73 changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents: 13400
diff changeset
   260
e17ebc11ca73 changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents: 13400
diff changeset
   261
    "Modified: / 29-07-2011 / 17:42:11 / cg"
8712
bcef3a0c0a1d skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents: 8459
diff changeset
   262
! !
bcef3a0c0a1d skipEncodingCHunk now in EncodedStream
Claus Gittinger <cg@exept.de>
parents: 8459
diff changeset
   263
8047
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
!EncodedStream class methodsFor:'documentation'!
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
13400
8dcdfacd2f34 changed: #version_CVS
vrany
parents: 12690
diff changeset
   266
version_CVS
13525
e17ebc11ca73 changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents: 13400
diff changeset
   267
    ^ '$Header: /cvs/stx/stx/libbasic/EncodedStream.st,v 1.20 2011-07-29 15:43:00 cg Exp $'
12610
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
   268
!
cfbb45980e28 added: #decodedStreamFor:
Claus Gittinger <cg@exept.de>
parents: 11992
diff changeset
   269
13400
8dcdfacd2f34 changed: #version_CVS
vrany
parents: 12690
diff changeset
   270
version_SVN
13525
e17ebc11ca73 changed: #skipEncodingChunk
Claus Gittinger <cg@exept.de>
parents: 13400
diff changeset
   271
    ^ '§ Id: EncodedStream.st 10643 2011-06-08 21:53:07Z vranyj1  §'
8047
9cfc575512eb initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
! !