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. (LIST ((PAGE NIL (FOLIOINFO (ARABIC) STARTINGPAGE# 1) (0 0 612 792) ((FOLIO NIL (PARALOOKS (QUAD CENTERED) CHARLOOKS (SUPERSCRIPT 0 SIZE 10 FAMILY MODERN OVERLINE OFF STRIKEOUT OFF UNDERLINE OFF SLOPE REGULAR WEIGHT MEDIUM) FORMATINFO (ARABIC)) (174 36 288 36) NIL) (HEADING NIL (HEADINGTYPE RUNNINGHEAD) (84 744 444 36) NIL) (TEXT NIL NIL (84 96 456 600) NIL))) (PAGE NIL NIL (0 0 612 792) ((FOLIO NIL (PARALOOKS (QUAD CENTERED) CHARLOOKS (SUPERSCRIPT 0 SIZE 10 FAMILY MODERN OVERLINE OFF STRIKEOUT OFF UNDERLINE OFF SLOPE REGULAR WEIGHT MEDIUM)) (282 42 72 36) NIL) (HEADING NIL (HEADINGTYPE RUNNINGHEAD) (84 744 444 36) NIL) (TEXT NIL NIL (84 96 456 600) NIL))) (PAGE NIL NIL (0 0 612 792) ((FOLIO NIL (PARALOOKS (QUAD CENTERED) CHARLOOKS (SUPERSCRIPT 0 SIZE 10 FAMILY MODERN OVERLINE OFF STRIKEOUT OFF UNDERLINE OFF SLOPE REGULAR WEIGHT MEDIUM)) (282 42 72 36) NIL) (HEADING NIL (HEADINGTYPE RUNNINGHEAD) (84 744 444 36) NIL) (TEXT NIL NIL (84 96 456 600) NIL)))))(È1È È(ŠŠ8(È (ŠŠ8DÈÈ PAGEHEADING RUNNINGHEADTERMINAL  HELVETICA MODERN MODERN MODERN MODERNMODERN LOGO HRULE.GETFNMODERN  HRULE.GETFNMODERN  HRULE.GETFNMODERN  HRULE.GETFNMODERN  HRULE.GETFNMODERN &. ! Û  =  Ñ K r ’%$¹./›": Xozº