9 lines
5.3 KiB
Plaintext
9 lines
5.3 KiB
Plaintext
XEROX SETSTRINGLENGTH
|
||
2
|
||
|
||
4
|
||
|
||
1
|
||
|
||
SETSTRINGLENGTH
|
||
1
|
||
|
||
4
|
||
|
||
By: Ron Kaplan (Kaplan.pa@Xerox.com)
|
||
This document last edited on October 20, 1987
|
||
INTRODUCTION
|
||
SETSTRINGLENGTH is a collection of functions for manipulating strings such that strings can grow larger than their original size. These functions are particularly helpful in managing the scratch-string buffers that are used by the read and translation functions of the WORDFNS module.
|
||
USE
|
||
(!RPLCHARCODE X N CHAR) [Function]
|
||
This function is similar to RPLCHARCODE except that string X is made larger if N specifies a character beyond the current end of X. The Nth character of the string X is replaced by the character code CHAR. As with RPLCHARCODE, N may be positive or negative. The new X is returned. If X must be enlarged, it is extended (by SETSTRINGLENGTH) to hold at least 20 characters beyond what is actually required, so that copying is not needed every time the string grows by one.
|
||
(!RPLSTRING X N Y) [Function]
|
||
This function is similar to RPLSTRING except that string X is made larger if necessary. The characters of string X beginning at character position N are replaced by string Y. X and Y are converted to strings if they aren't already. N may be positive or negative, as with SUBSTRING. The new string X is returned.
|
||
(SETSTRINGLENGTH STRING NEWLEN) [Function]
|
||
Modifies STRING so that its length becomes NEWLEN, possibly copying the underlying character block to a larger block. The effect is similar to (but slightly more efficient than) SUBSTRING if NEWLEN is less than the previous string length. Value is STRING.
|
||
(MAXIMALSTRING STRING) [Function]
|
||
Adjust the string STRING, such that it is the maximum size possible. Value is the maximal length.
|
||
(MAXSTRINGLENGTH STRING) [Function]
|
||
MAXSTRINGLENGTH returns the number of characters that STRING would hold if (MAXIMALSTRING STRING) were executed.
|
||
|
||
Examples
|
||
In the following example, a string, MyString, is created of length 3. After the call to !RPLSTRING, MyString now has the four characters "abcd".
|
||
(SETQ MyString (ALLOCSTRING 3))
|
||
(!RPLSTRING MyString 1 "abcd")
|
||
|
||
In the next example, the string MyString (which previously contained "abcd") has its length increased to six as a result of the function !RPLCHARCODE. MyString then contains "abcdef".
|
||
(!RPLCHARCODE MyString 5 (CHARCODE "e"))
|
||
(!RPLCHARCODE MyString 6 (CHARCODE "f"))
|
||
|
||
In the following example, the length of MyString is reduced by one character as a result of the function SETSTRINGLENGTH. MyString then contains "abcde".
|
||
(SETSTRINGLENGTH MyString 5)
|
||
If (GLCCODE MyString) is executed, the length of MyString is reduced to 4. However, (MAXSTRINGLENGTH MyString) will return 8 (which corresponds to the smallest block that the Interlisp string allocator will assign) and (MAXIMALSTRING MyString) will in fact modify the string so that (NCHARS MyString) returns 8.
|
||
|
||
|