class: PrintfScanf
comment/format in: #examples
changed:
#printArgFrom:to:arguments:
#scanArgFrom:to:format:
added binary format %b
--- a/PrintfScanf.st Thu Jan 24 16:52:14 2013 +0100
+++ b/PrintfScanf.st Fri Jan 25 12:04:42 2013 +0100
@@ -49,6 +49,10 @@
self new printf:'%8.3f' arguments: (Array with: 200 sqrt negated)
+ self new printf:'%x' arguments: #(16r41)
+ self new printf:'%#x' arguments: #(16r41)
+ self new printf:'%d' arguments: #(16r41)
+ self new printf:'%b' arguments: #(16r41)
self new printf:'%c' arguments: #(16r41)
self new printf:'%c' arguments: #( $A )
self new printf:'%s' arguments: #( $A )
@@ -86,7 +90,7 @@
!PrintfScanf class methodsFor:'others'!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic2/PrintfScanf.st,v 1.6 2013-01-23 10:01:22 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/PrintfScanf.st,v 1.7 2013-01-25 11:04:42 cg Exp $'
! !
!PrintfScanf class methodsFor:'printing'!
@@ -317,49 +321,49 @@
].
char isDigit ifTrue:[
- char == $0 ifTrue: [pad _ $0].
+ char == $0 ifTrue: [pad := $0].
width := Integer readFrom: inStream.
char := inStream peek
].
char == $. ifTrue:[
- inStream next. char _ inStream peek.
+ inStream next. char := inStream peek.
char == $*
- ifTrue: [precision _ argStream next. inStream next.]
- ifFalse: [precision _ Integer readFrom: inStream.].
- char _ inStream peek
+ ifTrue: [precision := argStream next. inStream next.]
+ ifFalse: [precision := Integer readFrom: inStream.].
+ char := inStream peek
].
char == $l ifTrue:[
"Ignore long specifier."
- inStream next. char _ inStream peek
+ inStream next. char := inStream peek
].
('feg' includes: char) ifTrue:[
- arg _ argStream next asFloat.
- precision _ precision min: 6.
- argString _ WriteStream on: String new.
+ arg := argStream next asFloat.
+ precision := precision min: 6.
+ argString := WriteStream on: String new.
char == $g ifTrue:
[self absPrintFloat:arg on: argString digits: precision + 1].
char == $f ifTrue:
[self absDecimalPrintFloat:arg on: argString digits: precision + arg abs log + 1].
char == $e ifTrue:
[self absScientificPrintFloat:arg on: argString digits: precision + 1].
- argString _ argString contents.
+ argString := argString contents.
arg < 0
- ifTrue: [argString _ '-', argString]
- ifFalse: [plus ifTrue: [argString _ '+', argString]].
+ ifTrue: [argString := '-', argString]
+ ifFalse: [plus ifTrue: [argString := '+', argString]].
(precision = 0 and: [pound not]) ifTrue:
[(argString includes: $e)
ifTrue: ["self halt"]
ifFalse:
- [argString _ arg truncated printString]].
+ [argString := arg truncated printString]].
pound ifTrue:
[(argString includes: $e)
ifTrue: ["self halt"]
ifFalse:
[precision - (argString size - (argString indexOf: $.)) timesRepeat:
- [argString _ argString, '0']]].
+ [argString := argString, '0']]].
ljust ifTrue: [outStream nextPutAll: argString].
width - argString size timesRepeat: [outStream nextPut: pad].
ljust ifFalse: [outStream nextPutAll: argString].
@@ -367,31 +371,35 @@
].
char == $c ifTrue:[
- arg _ String with: argStream next asCharacter
+ arg := String with: argStream next asCharacter
].
char == $s ifTrue:[
"Assume the arg is a String or Symbol."
- arg _ argStream next asString
+ arg := argStream next asString
].
char == $d ifTrue:[
- arg _ argStream next asInteger printString.
- plus ifTrue: [arg _ '+', arg]
+ arg := argStream next asInteger printString.
+ plus ifTrue: [arg := '+', arg]
].
char == $u ifTrue:[
- arg _ argStream next asInteger abs printString
+ arg := argStream next asInteger abs printString
].
char == $o ifTrue:[
- arg _ argStream next asInteger abs printStringRadix: 8.
- pound ifTrue: [arg _ '0', arg]
+ arg := argStream next asInteger abs printStringRadix: 8.
+ pound ifTrue: [arg := '0', arg]
].
('xX' includes: char) ifTrue:[
- arg _ argStream next asInteger abs printStringRadix: 16.
- pound ifTrue: [arg _ '0x', arg]
+ arg := argStream next asInteger abs printStringRadix: 16.
+ pound ifTrue: [arg := '0x', arg]
+ ].
+ ('bB' includes: char) ifTrue:[
+ arg := argStream next asInteger abs printStringRadix: 2.
+ pound ifTrue: [arg := '0b', arg]
].
char == $x ifTrue:[
@@ -400,7 +408,7 @@
[arg at: i put: ((arg at: i) asciiValue + 16r20) asCharacter]]
].
- precision _ precision min: arg size.
+ precision := precision min: arg size.
ljust ifTrue: [outStream nextPutAll: (arg copyFrom: 1 to: precision)].
width - precision timesRepeat: [outStream nextPut: pad].
ljust ifFalse: [outStream nextPutAll: (arg copyFrom: 1 to: precision)].
@@ -552,7 +560,10 @@
].
('Xx' includes:char) ifTrue:[
final value:(Integer readFrom:data radix:16)
- ]
+ ].
+ ('Bb' includes:char) ifTrue:[
+ final value:(Integer readFrom:data radix:2)
+ ].
"Modified: / 29-11-2011 / 11:55:32 / cg"
!
@@ -601,6 +612,6 @@
!PrintfScanf class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/PrintfScanf.st,v 1.6 2013-01-23 10:01:22 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/PrintfScanf.st,v 1.7 2013-01-25 11:04:42 cg Exp $'
! !