extensions.st
changeset 2260 fd7e5634d0d0
parent 2256 10583ebc7f64
child 2288 316a202d1c8b
equal deleted inserted replaced
2259:d9b94e7b06a5 2260:fd7e5634d0d0
   101      For copyright information, see goodies/String-printf_scanf.chg"
   101      For copyright information, see goodies/String-printf_scanf.chg"
   102     
   102     
   103     |aStream|
   103     |aStream|
   104 
   104 
   105     aStream := WriteStream on:String new.
   105     aStream := WriteStream on:String new.
   106     self printf_printOn:aStream withData:args.
   106     self printf:args on:aStream.
   107     ^ aStream contents
   107     ^ aStream contents
   108 
   108 
   109     "
   109     "
   110      Transcript showCR:('%05x %d %f %o' printf:{ 123. 234*5. 1.234. 8r377 } ) 
   110      Transcript showCR:('%05x %d %f %o' printf:{ 123. 234*5. 1.234. 8r377 } ) 
   111     "
   111     "
   136      Transcript showCR: ('%d%f%s' sscanf: '25 54.32e-01 monday') printString.
   136      Transcript showCR: ('%d%f%s' sscanf: '25 54.32e-01 monday') printString.
   137 
   137 
   138      Transcript show: '''%f%*f %8[A-F0-9]%c%d 0x%x%f'' sscanf: ''12.45 1048.73 AE40Z527 0x75BCD15 34'' = '.
   138      Transcript show: '''%f%*f %8[A-F0-9]%c%d 0x%x%f'' sscanf: ''12.45 1048.73 AE40Z527 0x75BCD15 34'' = '.
   139      Transcript showCR: ('%f%*f %8[A-F0-9]%c%d 0x%x%f' sscanf: '12.45 1048.73 AE40Z527 0x75BCD15 34') printString.
   139      Transcript showCR: ('%f%*f %8[A-F0-9]%c%d 0x%x%f' sscanf: '12.45 1048.73 AE40Z527 0x75BCD15 34') printString.
   140     "
   140     "
       
   141 ! !
       
   142 
       
   143 !CharacterArray methodsFor:'printing & storing'!
       
   144 
       
   145 printf:args on:outStream
       
   146     "Format and print the receiver on <outStream> with <args>
       
   147      formatted in C style, as specified in the Unix C-language manual page for printf(3).
       
   148 
       
   149      For copyright information, see goodies/String-printf_scanf.chg"
       
   150     
       
   151     |argStream inStream char|
       
   152 
       
   153     argStream := ReadStream on:args.
       
   154     inStream := ReadStream on:self.
       
   155     [ inStream atEnd ] whileFalse:[
       
   156         (char := inStream next) == $% ifFalse:[
       
   157             outStream nextPut:char
       
   158         ] ifTrue:[
       
   159             self 
       
   160                 printf_printArgFrom:inStream
       
   161                 to:outStream
       
   162                 withData:argStream
       
   163         ]
       
   164     ]
   141 ! !
   165 ! !
   142 
   166 
   143 !CharacterArray methodsFor:'printing & storing'!
   167 !CharacterArray methodsFor:'printing & storing'!
   144 
   168 
   145 printfWith:arg1 
   169 printfWith:arg1 
   407     ^ inStream next
   431     ^ inStream next
   408 ! !
   432 ! !
   409 
   433 
   410 !CharacterArray methodsFor:'printing & storing'!
   434 !CharacterArray methodsFor:'printing & storing'!
   411 
   435 
   412 printf_printOn:outStream withData:args 
   436 printf_printOn:outStream withData:args
       
   437     <resource: #obsolete>
       
   438  
   413     "Format and print the receiver on <outStream> with <args>
   439     "Format and print the receiver on <outStream> with <args>
   414      formatted in C style, as specified in the Unix C-language manual page for printf(3).
   440      formatted in C style, as specified in the Unix C-language manual page for printf(3).
   415 
   441 
   416      For copyright information, see goodies/String-printf_scanf.chg"
   442      For copyright information, see goodies/String-printf_scanf.chg"
   417     
   443 
   418     |argStream inStream char|
   444     self obsoleteMethodWarning:'use printf:on:'.
   419 
   445     self printf:args on:outStream
   420     argStream := ReadStream on:args.
       
   421     inStream := ReadStream on:self.
       
   422     [ inStream atEnd ] whileFalse:[
       
   423         (char := inStream next) == $% ifFalse:[
       
   424             outStream nextPut:char
       
   425         ] ifTrue:[
       
   426             self 
       
   427                 printf_printArgFrom:inStream
       
   428                 to:outStream
       
   429                 withData:argStream
       
   430         ]
       
   431     ]
       
   432 ! !
   446 ! !
   433 
   447 
   434 !CharacterArray methodsFor:'converting'!
   448 !CharacterArray methodsFor:'converting'!
   435 
   449 
   436 scanf:dataStream 
   450 scanf:dataStream