[vwnc] Looking for a string method

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[vwnc] Looking for a string method

david.long
trimOrPadToSize: width justify: aSymbol.

Does anyone know what package or parcel this lives in?

thanks,

David


Your business, your way.
http://sageteagroup.com

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Looking for a string method

Reinout Heeck-2
david wrote:
> trimOrPadToSize: width justify: aSymbol.
>
> Does anyone know what package or parcel this lives in?
>
I don't -- but it seems trivial to implement. (Don't you just love
intention revealing method names :-).

Try adding something like the following (untested code!) to CharacterArray


trimOrPadToSize: width justify: aSymbol
   
    self size = width ifTrue: [^self].
    self size > width ifTrue: [^self contractTo: width].
    aSymbol = #left
        ifTrue:
            [^(WriteStream on: (self species new: width))
                nextPutAll: self;
                next: width - self size
                    put: Character space;
                contents].
    aSymbol = #right
        ifTrue:
            [^(WriteStream on: (self species new: width))
                next: width - self size
                    put: Character space;
                nextPutAll: self;
                contents].
    ^self error: 'Illegal justification: ' , aSymbol




HTH,

Reinout
-------

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc