RV: [Glorp-development] SmallInteger>>printPaddedWith:to:base: should consider padded only the number right?

Sebastian Sastre ssastre at seaswork.com
Mon Apr 2 17:49:22 UTC 2007


Hi there,
 
    I found this Squeak specific issue that is used by Glorp.
 
    cheers,
 
Sebastian Sastre



  _____  

De: Alan Knight [mailto:knight at acm.org] 
Enviado el: Sábado, 31 de Marzo de 2007 22:41
Para: Sebastian Sastre; glorp-development at lists.sourceforge.net
Asunto: Re: [Glorp-development] SmallInteger>>printPaddedWith:to:base:
should consider padded only the number right?


Yes, that's what I'd expect too. But I note that that sounds to me like a
more general Squeak issue. Unless the Glorp port for Squeak is adding the
printOn:paddedWith:to:base: method. And then that sounds like something to
pester Todd about :-)

At 08:37 PM 3/29/2007, Sebastian Sastre wrote:


Hi there,
 
    trying to store some binary content on a postgreSQL database with Glorp
lead me to see how SmallInteger does it's octal representation.
 
    If you evaluate:
 
 str := String new writeStream.
 12 printOn: str paddedWith: $0 to: 3 base: 8.
 str  
a displayIt on the str gives you:  a WriteStream '8r14'
 
    This was suprising. I rather would espect '8r014' or '014' (as in
VisualWorks) because the padded size is related to the size of the symbolic
representation of the number (without involving it's header wich only
indicates how one should make the interpretation of the symbolic
representation of the number).
 
    cheers,    
 

<?xml:namespace prefix = st1 ns =
"urn:schemas-microsoft-com:office:smarttags" />Sebastian Sastre

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

PD1: this method is expecting that #printOn:base:showRadix DO NOT print the
radix header:
 
printPaddedWith: aCharacter to: anInteger base: aRadix 
 "Answer the string containing the ASCII representation of the receiver 
 padded on the left with aCharacter to be at least anInteger characters."
 | aStream padding digits |
 #Numeric.
 "2000/03/04  Harmon R. Added Date and Time support"
 aStream := WriteStream on: (String new: 10).
 self
  printOn: aStream
  base: aRadix
  showRadix: false.
 digits := aStream contents.
 padding := anInteger - digits size.
 padding > 0 ifFalse: [^ digits].
 ^ ((String new: padding) atAllPut: aCharacter;
  yourself) , digits
 
PD2: so.. it would act as expected if we patch #printOn:base:showRadix to:
 
SmallInteger>>printOn: outputStream base: baseInteger showRadix: flagBoolean

 "Write a sequence of characters that describes the receiver in radix 
 baseInteger with optional radix specifier. 
 The result is undefined if baseInteger less than 2 or greater than 36."
 | tempString startPos |
 #Numeric.
 "2000/03/04  Harmon R. Added ANSI <integer> protocol"
 tempString := self printStringRadix: baseInteger.
 "rh 6/9/2005 20:24 change to make it half-work (when you don't want radix
printed) instead of being completely broken"
 flagBoolean ifTrue: [^ outputStream nextPutAll: tempString].
 startPos := (tempString indexOf: $r ifAbsent: [self error: 'radix indicator
not found.'])
    + 1.
 self negative ifTrue: [outputStream nextPut: $-].
 outputStream nextPutAll: (tempString copyFrom: startPos to: tempString
size)
 
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php
<http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV>
&p=sourceforge&CID=DEVDEV 
_______________________________________________
Glorp-development mailing list
Glorp-development at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/glorp-development 


--
Alan Knight [|], Cincom Smalltalk Development
knight at acm.org
aknight at cincom.com
http://www.cincom.com/smalltalk

"The Static Typing Philosophy: Make it fast. Make it right. Make it run." -
Niall Ross

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20070402/2887f1ed/attachment.htm


More information about the Squeak-dev mailing list