dmaz.SFormat: Functions Modinfo Source  

SFormat

Functions Summary

PrintSF Print a string by combining str and values according to specified formats in str.
SFormat Parse string for specified formats and combine it with one or more values.

Functions

Function PrintSF( str:String, values:String[], clip:Int=CLIPERROR )
DescriptionPrint a string by combining str and values according to specified formats in str.
InformationSee SFormat.
Example
Import dmaz.SFormat

Print
PrintSF "blah @|||||||||| blah",["cen"]
PrintSF "blah @|||||||||| blah",["this is too big to center"],True
PrintSF "blah @|||||||||| blah",["this is too big to center"],False
PrintSF "blah @|||||||||| blah",["this is too big to center"],CLIPERROR
Print
PrintSF "blah @<<<<<<<<<< blah",["this is too big to center"],True
PrintSF "blah @>>>>>>>>>> blah",["this is too big to center"],True
Print

Local x:Int = 10
Local y:Int = 56
Local z:Int = 9

PrintSF "x:@  y:@  z:@",[String(x),String(y),String(z)]
Print
PrintSF "x:@<<<<  y:@<<<<  z:@<<<<",[String(x),String(y),String(z)]
PrintSF "x:@>>>>  y:@>>>>  z:@>>>>",[String(x),String(y),String(z)]
PrintSF "x:@0000  y:@0000  z:@0000",[String(x),String(y),String(z)]
Print

PrintSF "num: @>>>>>.>>",["8373.892"]
PrintSF "num: @>>>>>.>>",["8373.8"]
PrintSF "num: @>>>>>.00",["8373.8"]
PrintSF "num: @>>>>0.00",[".89"]
sformatPrecisionChar = ","
PrintSF "num: @>>>>0.00",[""]

Function SFormat:String( str:String, values:String[], clip:Int=CLIPERROR )
ReturnsReturns a string produced according to the supplied string.
DescriptionParse string for specified formats and combine it with one or more values.
InformationSFormat parses str for the following directives. It then interprets those directives to format a value which is then inserted into the return string. values is an array of strings that will be processed one by one with format. clip determines the output of a specific format if the value is too large to fit within that format.
str is composed of normal text, copied directly to the result and zero or more formats each of which coincide with a value from values. Null values are ok and will still result in the specified format.
A format consists of "@" followed by any of >,<,|,.,0. For example: "@>>>>>" will result in a right justified text field 6 (@ is included) characters wide. "@>>>0.00" will result in a right justified field with 2 decimals of precision
  • @ : By itself, will print out the next value unchanged, otherwise it marks the start of a format consisting of some of the following directives.
  • > : Right justify.
  • < : Left justify.
  • | : Center.
  • . : Indicates how and to what precision a floating point number should be format. Set the global sformatPrecisionChar to use a different character to indicate precision in the output.
  • 0 : Used to left or right pad numbers.

clip can be one of the 3 options...
  • True : Any value too big for the format will be clipped. The format type will determine which side of the value will be cut off.
  • False : Don't do any clipping. Although precision will still be clipped.
  • CLIPERROR : Fill the format with 's instead of the value, this is the default

Module Information

Version1.0
AuthorDavid Maziarka
LicensePublic Domain
History1.00 Release