WWW Support

The source code for these string and time functions is in PNmisc.fth.

Strings

: -leading      \ c-addr u -- c-addr u
Modify a string address/length pair to ignore leading spaces.

: addchar       \ char string --
Add the character to the end of the counted string

: append        \ c-addr u $dest --
Add the string described by C-ADDR U to the counted string at $DEST.

: is=           \ c-addr1 c-addr2 u -- flag
Compare two same-length strings/memory blocks, returning TRUE if they are identical. The comparison is case insensitive.

: str=          \ addr1 len1 addr2 len2 -- flag
Compare two addr/len memory blocks, returning TRUE if they are identical both in length and contents. The comparison is case sensitive.

: ISEARCH        \ c-addr1 u1 c-addr2 u2 -- c-addr3 u3 f
Search the string c-addr1/u1 for the string (\i{c-addr2/u2}. If a match is found return c-addr3/u3, the address of the start of the match and the number of characters remaining in c-addr1/u1, plus flag f set to true. If no match was found return c-addr1/u1 and f=0. Case insensitive for English.

: left-string \ caddr len char -- caddr len'
Given a string and a delimiter, return the string to the left of the delimiter.

: right-string \ caddr len char -- caddr len'
Given a string and a delimiter, return the string to the right of the delimiter.

: extract-string        \ caddr len char -- caddr' len'
Given a string, return the substring between the delimiters, ignoring leading delimiters.

: jump-string   \ caddr len char -- caddr' len'
Ignore leading delimiters, and return the string to the right of the next delimiter character including the delimiter.

: split         \ addr len char -- laddr llen raddr rlen
Extract a substring at the start of addr/len, returning raddr/rlen the string remaining after char and the substring laddr/llen which includes all characters before but not including char. If the string does not contain the character, raddr is addr+len and rlen=0.

: split$LR      \ addr len char -- laddr llen raddr rlen
Extract a substring at the start of addr/len, returning raddr/rlen the string remaining after char and the substring laddr/llen which includes all characters before but not including char. If the string does not contain the character, raddr is addr+len and rlen=0.

: split$RL      \ addr len char -- raddr rlen laddr llen
As split$LR but the left string is returned topmost.

: csplit        \ addr len char -- raddr rlen laddr llen
Extract a substring at the start of addr/len, returning the string raddr/rlen which includes char (if found) and the string laddr/llen which contains the text to left of char. If the string does not contain the character, raddr is addr+len and rlen=0.

: string>n      \ addr len radix -- value
Converts an ASCII string to a number in the given base. Characters are converted to upper case before conversion.

: string>dec    \ caddr len -- n
Converts an ASCII string as a decimal number.

: string>hex    \ caddr len -- n
Converts an ASCII string as a hexadecimal number.

: dec>string    \ n -- caddr len
N is converted to a signed decimal string.

: hex>string    \ n -- caddr len
N is converted to an unsigned hexadecimal string with a leading $ character

: is=           \ c-addr1 c-addr2 u -- flag
Compare two same-length strings/memory blocks, returning TRUE if they are identical. The comparison is case insensitive.

Time and date

These functions rely on the ANS Forth word TIME&DATE ( -- s m h dd mm yyyy ) and the non-standard DOW ( -- dow, 0=Sun) to get the day of the week.

create days$    \ -- addr
String containing 3 character text for the days of the week.

create months   \ -- addr
String containing 3 character text for the months.

: .dow          \ --
Display day of week.

: .2r           \ n --
Display n as a two digit number with leading zeros.

: .4r           \ n --
Display n as a four digit number with leading zeros.

: .Time&Date    \ --
Display the system time The format is:

  hh:mm:ss dd Mmm yyyy

: .AnsiDate     \ zone --
Display the day of week, date and time. If zone is 0 GMT is displayed. The format is:

  dow, hh:mm:ss dd Mmm yyyy [GMT]

: IncludeMem    \ caddr len --
INCLUDE a block of memory as if it were a file.

Test code