Dynamic Strings, Heap Manager, Formatted Output
Phil Pilgrim (PhiPi)
Posts: 23,514
In another thread there was a question about string functions. Awhile back I wrote an object for strings that some may find useful. It's probably not tested sufficiently to include in the object library yet, but perhaps some brave souls may wish to try it out anyway.
Attached is an archive containing a dynamic strings object, a heap manager object, and a C-like formatted output object. The top-level program uses these objects to generate nonsense English sentences derived from a context-free grammar.
For the next week or so, I'm swamped, so won't be able to offer much in the way of support. But leave any questions you may have in this thread, and I'll attempt to answer them when I get the chance.
Cheers!
Phil
Attached is an archive containing a dynamic strings object, a heap manager object, and a C-like formatted output object. The top-level program uses these objects to generate nonsense English sentences derived from a context-free grammar.
For the next week or so, I'm swamped, so won't be able to offer much in the way of support. But leave any questions you may have in this thread, and I'll attempt to answer them when I get the chance.
Cheers!
Phil


Comments
This is really needed.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··
Thanks Phil!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket
KK
·
Sorry for this reply on such old thread, but can i use the strings.spin file to split a string into segments?
like: string = "Hello World, how are you doing?"
after a split i need
Hello
World,
how
...
...
Here's something I came up with:
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 OBJ FDS : "FullDuplexSerial" VAR word address[20] PUB Main | i, words FDS.start(31,30,0,115200) waitcnt(cnt + clkfreq) FDS.tx($00) words := parse(string("Hello World, how are you doing?")) waitcnt(cnt + clkfreq) repeat i from 0 to words - 1 display(address[i]) ' The display method is useful if you're preserving fds.tx($0D) ' the original string with spaces intact fds.tx($0D) repeat i from 0 to words - 1 fds.str(address[i]) ' The FullDuplexSerial str method can be used if fds.tx($0D) ' splitting the string with nulls PUB Display(stringPtr) { This method displays bytes in a string up to a space or a null } repeat until byte[stringPtr] == " " or byte[stringPtr] == $00 FDS.tx(byte[stringPtr++]) PUB parse(stringPtr) | i { This method stores the addresses of each first byte that follows a space, ignoring leading, trailing, and repeated spaces Returns the number of addresses stored } i := 0 if byte[stringPtr] <> " " ' Ignore leading spaces address[i++] := stringPtr ' Store the first address repeat if byte[stringPtr] == $00 ' Repeat until the null-terminator return i ' Return the number of words if byte[stringPtr] == " " ' Look for a space if byte[stringPtr + 1] <> " " and byte[stringPtr + 1] <> $00 ' Ignore repeated spaces and nulls address[i++] := stringPtr + 1 ' Store the address following a space byte[stringPtr] := $00 ' Replace spaces with nulls to split the string ' comment out to keep the string intact stringPtr++Works like i wanted it