planckforth/lib/string.fs

24 lines
476 B
Forth
Raw Normal View History

2021-12-04 12:53:33 +01:00
\ planckforth -
\ Copyright (C) 2021 nineties
( === String === )
private{
\ Heap-allocated string object
\ p: null terminated string
: make-string ( p -- str )
2021-12-04 13:25:34 +01:00
dup strlen 1 + allocate throw tuck strcpy
2021-12-04 12:53:33 +01:00
; export
: release-string ( str -- ) free ; export
}private
T{ s" AAAAA" make-string constant A -> }T
T{ s" BBBBBBB" make-string constant B -> }T
T{ A s" AAAAA" streq -> true }T
T{ B s" BBBBBBB" streq -> true }T
T{ A release-string -> }T
T{ B release-string -> }T