programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Re: Strings -- Character counted vs NULL terminated

From: Bob Nash <BNash_at_smud.org>
Date: Fri, 21 Sep 2001 09:31:22 -0700

Richard - You might also want to check out BUFOUT.f (in LIB/OPTIONS). It
defines a class that creates text buffers with dynamic memory allocation and
de-allocation. I frequently use this type of buffer to accumulate/assemble
strings, later parsing the text for display or output. When you are
finished, you can use the WIPE operator to de-allocate memory. Note that
the buffer is always "big enough."

-----Original Message-----
From: Gene LeFave [mailto:gene_at_tekdata.com]
Sent: Friday, September 21, 2001 9:07 AM
To: sftalk_at_forth.com
Subject: [sftalk] Re: Strings -- Character counted vs NULL terminated

My approach would be use SPLIT also. I've also found it useful to
have a word I call DELIM that is the same as split except that the
character is not included in the returned strings.

FOr example assuming blob and blob length are on the stack.
then ( a l ) [char] { SPLIT 2SWAP [CHAR] } SPLIT
       ( a l a l a l)

will leave the string contained by {} on the top of the stack with
the before and after segments underneath. There is a very "lisp"
like feel to this. Keeping a mental image of the stack is a bit
challenging.

I would definitly avoid a design that moves and copies a lot of
terminated or counted strings. Invariably there are memory
management problems.

Try to map out the recognizer as a state machine and then write a
short forth word for each state.

My other general rule for problems of this type is never nest IF
statements in the same word. It is a simple matter to test each
progressively complicated pattern until the problem is solved.

Gene

Date sent: Thu, 20 Sep 2001 19:30:22 -0500
From: Richard Owlett <rowlett_at_atlascomm.net>
To: sftalk_at_forth.com
Subject: [sftalk] Re: Strings -- Character counted vs NULL
terminated
Send reply to: sftalk_at_forth.com

>
>
>
> Bob Nash wrote:
> >
> > Does the program generating the text really generate strings or just
text
> > with embedded CRLFs? In the latter case, you may want to deal with the
text
> > by parsing out strings with SPLIT.
> >
>
> The source program produces an essentially normal text file, large
> portions of which are effectively "noise". There is a regularity in that
> "logical units" are surrounded by "{" and "}" pairs. Any data between a
> "}" and a "{" is ALWAYS noise. Data between a "{" and a "}" MAY be
> noise.
>
> It seemed logical to load everything from an opening "{" and closing "}"
> into a buffer at a fixed location and treat it as a single string. Call
> it a BLOB of data for want of a better term. All BLOB's lacking a
> specific sub-string are noise. Unfortunately this identifier occurs well
> inside the BLOB. That is, whether or not "Line N" has data is indicated
> by the content of "Line N + x". Number and length of lines in a BLOB are
> unknowable in advance.
>
> This, and two companion programs, are my first attempt at a significant
> amount of FORTH code. Much of this could more easily be done in a word
> processor or database application. My purpose is to use a problem I
> basically understand as a learning experience.
> ----------------------------------------------------------------------
> sftalk_at_forth.com The SwiftForth programming discussion email list
> To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
> For help with listar commands, send subject "help" to listar_at_forth.com
> Archives are located at http://www.forth.com/sftalk -- check them out!
> Search the archives! Visit http://www.forth.com/search for details.
>

----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
Search the archives! Visit http://www.forth.com/search for details.
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
Search the archives! Visit http://www.forth.com/search for details.
Received on Fri Sep 21 2001 - 09:31:08 PDT

This archive was generated by hypermail 2.2.0 : Fri Nov 21 2008 - 03:04:19 PST