Shop OBEX P1 Docs P2 Docs Learn Events
Bug in STRINGS library object — Parallax Forums

Bug in STRINGS library object

w8anw8an Posts: 176
edited 2009-11-16 16:34 in Propeller 1
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:
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

  • Nick MuellerNick Mueller Posts: 815
    edited 2009-11-14 08:24
    > As you can see, there is a glaring error in the PADL function.

    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
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-11-14 09:01
    Nick,

    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
  • localrogerlocalroger Posts: 3,452
    edited 2009-11-14 15:02
    How about this:
    pub padleft(str, strlen) | slen
      slen = strsize(str)
      bytemove(str + strlen - slen, str, slen + 1) 'need to copy null terminator too
      bytefill(str, " ", strlen - slen)
    
  • w8anw8an Posts: 176
    edited 2009-11-14 20:37
    The "STRINGS_simple_demo.spin" file included with the object does not have an example of left padding, however it does have a right pad test. I added a left pad test and it too has the problem.
      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
  • Nick MuellerNick Mueller Posts: 815
    edited 2009-11-14 21:05
    > paddedString is just such a beast, pointing to an array in the Strings object.

    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
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2009-11-15 02:33
    I am the author. I know pad left worked at 1.0. So I will go through it and find what's wrong. I am sure it will be a simple fix. I don't have a prop here over this weekend. I will be able to fix it Monday.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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!
  • Invent-O-DocInvent-O-Doc Posts: 768
    edited 2009-11-15 19:44
    This was a great post! I didn't know there was a string library for Spin. Strings, or the lack thereof, have been the hardest thing for me to get used to with the propeller.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Talbot
    New Market, MD, USA
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2009-11-15 19:59
    Invent-O-Doc said...
    This was a great post! I didn't know there was a string library for Spin. Strings, or the lack thereof, have been the hardest thing for me to get used to with the propeller.
    The library is fairly new. There are actually two different ones. Both have their strengths and weaknesses. I am trying to work with the author of the other library to combine our efforts and make a single, more definitive library for the Obex. He said he won't be able to work with me on it for a while, so I might just use some of his methodologies and code and cite his work.

    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!
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2009-11-16 16:34
    I have uploaded the object with fixed code on the Obex (version 1.31). There is a link to it in my signature.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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!
Sign In or Register to comment.