Previous: Address arithmetic, Up: Memory
Memory blocks often represent character strings; For ways of storing character strings in memory see String Formats. For other string-processing words see Displaying characters and strings.
A few of these words work on address unit blocks. In that case, you
usually have to insert CHARS
before the word when working on
character strings. Most words work on character blocks, and expect a
char-aligned address.
When copying characters between overlapping memory regions, use
chars move
or choose carefully between cmove
and
cmove>
.
move
c-from c-to ucount – core “move”
Copy the contents of ucount aus at c-from to
c-to. move
works correctly even if the two areas overlap.
erase
addr u – core-ext “erase”
Clear all bits in u aus starting at addr.
cmove
c-from c-to u – string “c-move”
Copy the contents of ucount characters from data space at
c-from to c-to. The copy proceeds char
-by-char
from low address to high address; i.e., for overlapping areas it is
safe if c-to=<c-from.
cmove>
c-from c-to u – string “c-move-up”
Copy the contents of ucount characters from data space at
c-from to c-to. The copy proceeds char
-by-char
from high address to low address; i.e., for overlapping areas it is
safe if c-to>=c-from.
fill
c-addr u c – core “fill”
Store c in u chars starting at c-addr.
blank
c-addr u – string “blank”
Store the space character into u chars starting at c-addr.
compare
c-addr1 u1 c-addr2 u2 – n string “compare”
Compare two strings lexicographically. If they are equal, n is 0; if the first string is smaller, n is -1; if the first string is larger, n is 1. Currently this is based on the machine's character comparison. In the future, this may change to consider the current locale and its collation order.
str=
c-addr1 u1 c-addr2 u2 – f gforth “str=”
str<
c-addr1 u1 c-addr2 u2 – f gforth “str<”
string-prefix?
c-addr1 u1 c-addr2 u2 – f gforth “string-prefix?”
Is c-addr2 u2 a prefix of c-addr1 u1?
search
c-addr1 u1 c-addr2 u2 – c-addr3 u3 flag string “search”
Search the string specified by c-addr1, u1 for the string specified by c-addr2, u2. If flag is true: match was found at c-addr3 with u3 characters remaining. If flag is false: no match was found; c-addr3, u3 are equal to c-addr1, u1.
-trailing
c_addr u1 – c_addr u2 string “dash-trailing”
Adjust the string specified by c-addr, u1 to remove all trailing spaces. u2 is the length of the modified string.
/string
c-addr1 u1 n – c-addr2 u2 string “slash-string”
Adjust the string specified by c-addr1, u1 to remove n characters from the start of the string.
bounds
addr u – addr+u addr gforth “bounds”
Given a memory block represented by starting address addr
and length u in aus, produce the end address addr+u and
the start address in the right order for u+do
or
?do
.
pad
– c-addr core-ext “pad”
c-addr is the address of a transient region that can be used as temporary data storage. At least 84 characters of space is available.