Bug in STRINGS library object
w8an
Posts: 176
After having too much trouble with padded strings, I decided I better throw together a quick test program to see why I wasn't able to figure out the proper code for padding the left with spaces.
The version 1.3 Obex STRINGS object is not working.
This code:
produces this output:
As you can see, there is a glaring error in the PADL function.
..Steve
The version 1.3 Obex STRINGS object is not working.
This code:
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
s : "Strings"
debug : "FullDuplexSerial"
PUB Start | paddedString
waitcnt(clkfreq * 5 + cnt) 'Start FullDuplexSerial
Debug.start(31, 30, 0, 57600)
Debug.Str(String("SERIAL Initializing...",13))
paddedString := s.StrPad(string("XYZ"),6,string(" "),s#PAD_RIGHT)
debug.Str(string("PADR -->"))
debug.Str(paddedString)
debug.Str(string("<-- size:"))
debug.Dec(strsize(paddedString))
debug.Str(string(13))
paddedString := s.StrPad(string("XYZ"),6,string(" "),s#PAD_LEFT)
debug.Str(string("PADL -->"))
debug.Str(paddedString)
debug.Str(string("<-- size:"))
debug.Dec(strsize(paddedString))
debug.Str(string(13))
repeat 'stop
produces this output:
SERIAL Initializing... PADR -->XYZ <-- size:6 PADL --> <-- size:3
As you can see, there is a glaring error in the PADL function.
..Steve

Comments
unless I'm totaly confused (that might be right), you cant use a local ("paddedString") for a string. Locals only store integers.
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
In Spin "strings" are pointers (i.e. word-sized integer addresses) to zero-terminated byte arrays. paddedString is just such a beast, pointing to an array in the Strings object.
-Phil
DEBUG.str(STR.StrPad(string("short"), 10, string("-_-"), STR#PAD_RIGHT)) 'Result: "short-_--_" DEBUG.str(STR.StrPad(string("short"), 10, string("-_-"), STR#PAD_LEFT)) 'Result: "-_--_"If anyone knows the author of the object, they might notify him so he can update the code.
Steve
My fault! I overlooked, that paddedString is assigned through s.StrPad.
Sorry for the fuzz.
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
Some of my objects:
MCP3X0X ADC Driver - Programmable Schmitt inputs, frequency reading, and more!
Simple Propeller-based Database - Making life easier and more readable for all your EEPROM storage needs.
String Manipulation Library - Don't allow strings to be the bane of the Propeller, bend them to your will!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Talbot
New Market, MD, USA
If there are any requests as to what functionality people want in the object, please post and I will see what can be done.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
Some of my objects:
MCP3X0X ADC Driver - Programmable Schmitt inputs, frequency reading, and more!
Simple Propeller-based Database - Making life easier and more readable for all your EEPROM storage needs.
String Manipulation Library - Don't allow strings to be the bane of the Propeller, bend them to your will!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
Some of my objects:
MCP3X0X ADC Driver - Programmable Schmitt inputs, frequency reading, and more!
Simple Propeller-based Database - Making life easier and more readable for all your EEPROM storage needs.
String Manipulation Library - Don't allow strings to be the bane of the Propeller, bend them to your will!