Stream.st
changeset 1402 82462d153a7d
parent 1401 ee3de5b5742d
child 1403 2417f8fa4d4a
equal deleted inserted replaced
1401:ee3de5b5742d 1402:82462d153a7d
   138 
   138 
   139 !Stream methodsFor:'accessing'!
   139 !Stream methodsFor:'accessing'!
   140 
   140 
   141 contents
   141 contents
   142     "return the entire contents of the stream
   142     "return the entire contents of the stream
   143      - we do not know here how to do it, it must be redefined in subclass"
   143      - we do not know here how to do it, it must be redefined in subclasses."
   144 
   144 
   145     ^ self subclassResponsibility
   145     ^ self subclassResponsibility
       
   146 
       
   147     "Modified: 15.5.1996 / 17:36:29 / cg"
   146 !
   148 !
   147 
   149 
   148 signalAtEnd
   150 signalAtEnd
   149     "return signalAtEnd"
   151     "return the signalAtEnd flag setting. If true, reading past the end
       
   152      will raise an EndOfStream exception. If false, no exception is
       
   153      raised and nil is returned from all reading messages.
       
   154      The default is (currently) to NOT raise a signal."
   150 
   155 
   151     ^ signalAtEnd
   156     ^ signalAtEnd
   152 
   157 
   153     "Created: 5.2.1996 / 18:24:53 / stefan"
   158     "Created: 5.2.1996 / 18:24:53 / stefan"
   154 !
   159     "Modified: 15.5.1996 / 17:35:55 / cg"
   155 
   160 !
   156 signalAtEnd:something
   161 
   157     "set signalAtEnd"
   162 signalAtEnd:aBoolean
   158 
   163     "set the signalAtEnd flag setting. If true, reading past the end
   159     signalAtEnd := something.
   164      will raise an EndOfStream exception. If false, no exception is
       
   165      raised and nil is returned from all reading messages.
       
   166      The default is (currently) to NOT raise a signal."
       
   167 
       
   168     signalAtEnd := aBoolean.
   160 
   169 
   161     "Created: 5.2.1996 / 18:24:53 / stefan"
   170     "Created: 5.2.1996 / 18:24:53 / stefan"
       
   171     "Modified: 15.5.1996 / 17:36:12 / cg"
   162 ! !
   172 ! !
   163 
   173 
   164 !Stream methodsFor:'closing'!
   174 !Stream methodsFor:'closing'!
   165 
   175 
   166 close
   176 close
   261 ! !
   271 ! !
   262 
   272 
   263 !Stream methodsFor:'misc'!
   273 !Stream methodsFor:'misc'!
   264 
   274 
   265 binary
   275 binary
   266     "switch to binary mode. ignored here, but added to make
   276     "switch to binary mode. In binary mode, reading of text streams
   267      internalStreams protocol compatible with externStreams."
   277      returns byte-valued integers instead of characters; writing expects
   268 
   278      byte-valued integers respectively.
       
   279      Ignored here, but added to make internalStreams protocol compatible 
       
   280      with externalStreams."
       
   281 
       
   282     "Modified: 15.5.1996 / 17:38:36 / cg"
   269 ! !
   283 ! !
   270 
   284 
   271 !Stream methodsFor:'non homogenous reading'!
   285 !Stream methodsFor:'non homogenous reading'!
       
   286 
       
   287 nextAlphaNumericWord
       
   288     "read the next word (i.e. up to non letter-or-digit).
       
   289      Return a string containing those characters.
       
   290      Any leading whitespace is skipped.
       
   291      This method does not advance over any non-alphanumeric characters;
       
   292      i.e. it will stick and continue to continue to return nil in
       
   293      this case. Only call for it in a loop, AFTER you have checked for
       
   294      the next character to really be alphanumeric (using #peek)"
       
   295 
       
   296     |s c|
       
   297 
       
   298     [self atEnd not
       
   299      and:[(c := self peek) isSeparator]] whileTrue:[
       
   300         self next 
       
   301     ].
       
   302 
       
   303     self atEnd ifTrue:[^ nil].
       
   304 
       
   305     s := ''.
       
   306 
       
   307     [self atEnd not
       
   308      and:[(c := self peek) isLetterOrDigit]] whileTrue:[ 
       
   309         s := s copyWith:c. 
       
   310         self next 
       
   311     ].
       
   312 
       
   313     s size == 0 ifTrue:[^ nil].
       
   314     ^ s.
       
   315 
       
   316     "
       
   317      |s|
       
   318 
       
   319      s := 'hello world 1234 foo1 foo2' readStream.
       
   320      [s atEnd] whileFalse:[
       
   321         Transcript showCr:(s nextAlphaNumericWord).
       
   322      ].
       
   323 
       
   324 
       
   325    notice: streams end never reached this way (sticking at the '+'-character:
       
   326      |s|
       
   327 
       
   328      s := 'hello world 1234 foo1+foo2' readStream.
       
   329      10 timesRepeat:[
       
   330         Transcript showCr:(s nextAlphaNumericWord).
       
   331      ].
       
   332     "
       
   333 
       
   334     "Modified: 15.5.1996 / 17:50:32 / cg"
       
   335 !
   272 
   336 
   273 nextLine
   337 nextLine
   274     "return the characters upTo (but excluding) the next cr character.
   338     "return the characters upTo (but excluding) the next cr character.
   275      Added for protocol compatibility with externalStreams."
   339      Added for protocol compatibility with externalStreams."
   276 
   340 
   453 
   517 
   454     "Created: 10.1.1996 / 19:50:02 / cg"
   518     "Created: 10.1.1996 / 19:50:02 / cg"
   455 !
   519 !
   456 
   520 
   457 nextWord
   521 nextWord
       
   522     "return the next characters which form an alphanumeric word
       
   523      (i.e. everything upTo (but excluding) the next non alphanumeric
       
   524       element)"
       
   525 
   458     ^ self nextAlphaNumericWord
   526     ^ self nextAlphaNumericWord
       
   527 
       
   528     "Modified: 15.5.1996 / 17:39:32 / cg"
   459 ! !
   529 ! !
   460 
   530 
   461 !Stream methodsFor:'non homogenous writing'!
   531 !Stream methodsFor:'non homogenous writing'!
   462 
   532 
   463 nextLongPut:aNumber
   533 nextLongPut:aNumber
  1104 ! !
  1174 ! !
  1105 
  1175 
  1106 !Stream class methodsFor:'documentation'!
  1176 !Stream class methodsFor:'documentation'!
  1107 
  1177 
  1108 version
  1178 version
  1109     ^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.39 1996-05-15 15:33:59 cg Exp $'
  1179     ^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.40 1996-05-15 15:51:12 cg Exp $'
  1110 ! !
  1180 ! !
  1111 Stream initialize!
  1181 Stream initialize!