eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'PrintfScanf':

Home

everywhere
www.exept.de
for:
[back]

Class: PrintfScanf


Inheritance:

   Object
   |
   +--PrintfScanf

Package:
stx:libbasic2
Category:
System-Support
Version:
rev: 1.3 date: 2004/07/27 11:07:32
user: cg
file: PrintfScanf.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


 Contributed by Jan Steinman donated to the
 community in 1989.

 Provided AS-IS - no warranty, use at your own risk.

 Original comment:

     NAME            printf-scanf
     AUTHOR          Jan Steinman <jans@tekgvs.labs.tek.com>
     FUNCTION        printf and scanf for Smalltalk
     ST-VERSIONS     Tek 2.2.2a 4.0
     PREREQUISITES   CharacterComparing
     CONFLICTS       
     DISTRIBUTION    world
     VERSION         1.1
     DATE            Apr 1989?
     SUMMARY 

 The following methods implement printf and scanf functionality.  They
 are intended to be used to ease porting between Smalltalk and C, and
 for facilitating machine-machine communication.  They are not at all
 intended as replacements for Smalltalk's printOn: functionality.

 Jan Steinman - N7JDB
 Tektronix Electronic Systems Laboratory
 Box 500, MS 50-370, Beaverton, OR 97077
 (w)503/627-5881 (h)503/657-7703


Instance protocol:

printing
o  printArgFrom: inStream to: outStream arguments: argStream
Interpret the required number of arguments from <argStream>
according to the formatting information in <inStream>. Place
the interpretation on <outStream>. The interpretation is C
printf(3) style, as described in the UTek manual page for
printf(3). <inStream> is assumed to be positioned just past
$%, and a complete control string is assumed available.

Return when the conversion control string is consumed.
Leave <inStream> pointing past the last character in the conversion control string.

This code assumes that <inStream> is formatted according to
specification, and error checking is minimal. Unexpected
results will be obtained by illegal control strings, or when
argument types do not match conversion codes, but it probably
won't dump core, like C does in such cases!!

o  printf: aString arguments: args
Format and print the receiver with <args> formatted in C style,
as described in the UTek manual page for printf(3).

o  printf: aFormatString on: outStream arguments: args
Format and print aFormatString on <outStream> with <args>
formatted in C style, as described in the UTek manual page for
printf(3). This method is designed for producing output
suitable for a machine.

queries
o  absDecimalPrintFloat: aFloat on: aStream digits: digits
Place a string representation of the receiver on <aStream> using <digits> significant digits, using decimal notation.

o  absPrintFloat: aFloat on: aStream digits: digits
Place a string representation of the receiver on <aStream> using <digits> significant digits.

o  absScientificPrintFloat: aFloat on: aStream digits: digits
Place a string representation of the receiver on <aStream> using <digits> significant digits, using scientific notation.

o  formatArgCountFor: aFormatString
Return the number of arguments required/produced,
if the argument is interpreted as a printf/scanf format control string.

scanning
o  scanArgFrom: dataStream to: collection format: format
Add to <collection> an object who's representation is found
in <dataStream> interpreted according to the conversion
control string in the Stream <format>. <format> is assumed to
be positioned just past a $%, and a complete control string is
assumed available.

Return when the conversion control string is consumed. Leave
<format> pointing past the last character in the conversion
control string, leave <dataStream> pointing past any width
specified in <format>, or at the first character that doesn't
make sense for the <format>.

o  scanf: formatString fromStream: dataStream
Return a Collection of objects found in the Character Stream
<dataStream> as interpreted according to the receiver. The
receiver is assumed to be a conversion control string as
specified in the UTek manual page for scanf(3).

o  sscanf: formatString fromString: aString
Return a Collection of objects found in <string> as
interpreted according to the receiver. The receiver is
assumed to be a conversion control string as specified in the
UTek manual page for scanf(3).


Examples:


self new printf:'%#x %#X %03o%*.*s' arguments: #(16rABCD 16rEF 5 9 5 ''ghijklmn'') self new printf:'%- 10.4s%.2e' arguments: (Array with: 'abcdefghijkl' with: Float pi) self new printf:'%8.3f' arguments: (Array with: 200 sqrt negated) self new printf:'%c' arguments: #(16r41) self new printf:'%c' arguments: #( $A ) self new printf:'%s' arguments: #( $A ) self new printf:'%s' arguments: #( 'hello' ) self new printf:'%4s' arguments: #( 'hello' ) self new printf:'%7s' arguments: #( 'hello' ) self new sscanf:'%f%2s%s%s%s' string: '237.0 this is a test' self new sscanf:'%d%f%s' fromString: '25 54.32e-01 monday' self new sscanf:'%f%*f %8[A-F0-9]%c%d 0x%x%f' fromString: '12.45 1048.73 AE40Z527 0x75BCD15 34' '%#x %#X %03o%*.*s' printf: #(16rABCD 16rEF 5 9 5 ''ghijklmn'') '%- 10.4s%.2e' printf: (Array with: 'abcdefghijkl' with: Float pi) '%8.3f' printf: (Array with: 200 sqrt negated) '%c' printf: #(16r41) '%f%2s%s%s%s' sscanf: '237.0 this is a test' '%d%f%s' sscanf: '25 54.32e-01 monday' '%f%*f %8[A-F0-9]%c%d 0x%x%f' sscanf: '12.45 1048.73 AE40Z527 0x75BCD15 34'

ST/X 6.1.1; WebServer 1.620 at exept:8081; Tue, 22 May 2012 21:42:27 GMT