1 : safe
-type ( str
-addr str
-len
-- )
3 drop
256 type ." ...<lots more>"
8 \
=== mutable string buffer
=== /
9 \
string buffer that
maintains an allocation larger than the
current
10 \
string size
. When appending would cause
the string size
exceed the
11 \
current allocation, resize
is used
to double
the allocation. The
12 \
current allocation is not stored anywhere
, but
computed based on
13 \
current string size
or str
-base
-size
, whichever
is larger.
14 64 constant
str-base
-size
16 : new-str ( -- addr length
)
17 str-base
-size
allocate throw
0 ;
26 : str-append
{ buf
-addr buf
-str-len
str-addr
str-len
}
29 new-len
str-base
-size
>= if
30 buf
-str-len
new-len xor buf
-str-len
> if
31 buf
-addr
new-len round
-up resize
throw
35 str-addr buf
-addr buf
-str-len
+ str-len cmove
38 \ define
a-space
, to append
a space
char to a string
40 here
constant space
-str
41 : a-space
space-str 1 str-append
;
43 : str-append
-char ( buf
-addr buf
-str-len
char -- buf
-addr buf
-str-len
)
44 pad
! pad
1 str-append
;
46 \ from gforth docs
, there
named 'my-.'
47 : int>str ( num
-- str-addr
str-len
)
48 \ handling negatives
.. behaves
like Standard .
49 s
>d \ convert
to signed double
50 swap over dabs \ leave
sign byte
followed by unsigned double
51 <<# \ start conversion
52 #s \ convert all digits
53 rot
sign \ get
at sign byte
, append
"-" if needed
54 #> \ complete conversion
55 #>> ; \ release hold area
69 nil
value exception-object
72 ...str to exception-object