Debian Codegraph @

terps/tads/tads3/include/strbuf.h

raw symbols SCIP
1 #charset "us-ascii"
2 #pragma once
3
4 /*
5 * Copyright 2009 Michael J. Roberts.
6 *
7 * This file is part of TADS 3.
8 *
9 * This module defines the StringBuffer intrinsic class. StringBuffer is
10 * essentialy a mutable version of String: you can append, insert, replace,
11 * and delete characters in place, without creating new objects as a
12 * result. This is useful for complex string constructions that involve
13 * many incremental steps, since it avoids the repeated memory allocation
14 * and string copying operations that would be involved if the intermediate
15 * steps were performed with ordinary String objects.
16 */
17
18 /*
19 * A StringBuffer is a mutable character string object. You can insert,
20 * append, delete, and replace characters in the buffer in place. These
21 * operations don't create new objects as they do with ordinary strings,
22 * but simply modify the existing StringBuffer object's contents.
23 *
24 * The object manages memory automatically. When you first create the
25 * object, it allocates an initial buffer to hold its character contents.
26 * You can specify the initial buffer size with a constructor argument, or
27 * simply let the object pick a default. As you add text to the buffer,
28 * the object automatically allocates more memory as needed to accommodate
29 * the added text. The maximum size for the string contained in the buffer
30 * is about 32000 characters.
31 *
32 * Construction: new StringBuffer() creates a buffer with default initial
33 * size values. new StringBuffer(length, increment) specifies the initial
34 * buffer size in characters ('length'), and the minimum number of
35 * characters to add to the buffer each time it's automatically expanded
36 * ('increment').
37 *
38 * Passing a StringBuffer to an internal function or method that takes a
39 * String argument, such as tadsSay(), will automatically convert the
40 * object to a string. To explicitly convert a StringBuffer to an ordinary
41 * String, use the toString() function. You can also create an ordinary
42 * string from a section of the buffer using the substr() method.
43 */
44 intrinsic class StringBuffer 'stringbuffer/030000'
45 {
46 /*
47 * Get the length in characters of the current text in the buffer.
48 */
49 length();
50
51 /*
52 * Retrieve the Unicode character value of the character at the given
53 * index. Returns an integer with the Unicode value. If idx is
54 * negative, it's an index from the end of the string: -1 is the last
55 * character, -2 is the second to last, etc.
56 */
57 charAt(idx);
58
59 /*
60 * Append text to the current contents of the buffer. This adds the
61 * new text at the end of the current text. The value is automatically
62 * converted to a string if possible; this includes numbers and
63 * true and nil values.
64 */
65 append(str);
66
67 /*
68 * Insert text into the buffer just before the character at the given
69 * index. The first character is at index 1, so to insert the new text
70 * before the first current character, insert at index 1. If the index
71 * is past the end of the current text, this has the same effect as
72 * append(). A negative value indexes from the end of the string. The
73 * text is automatically converted to a string if possible.
74 */
75 insert(txt, idx);
76
77 /*
78 * Copy text into the buffer, starting at the given index (the first
79 * character in the buffer is at index 1). Overwrites any text
80 * currently in the buffer at this point.
81 */
82 copyChars(txt, idx);
83
84 /*
85 * Delete the given text. This deletes 'len' characters starting at
86 * the given index (the first character is at index 1). If the length
87 * is omitted, the portion from idx to the end of the string is
88 * deleted. A negative idx value indexes from the end of the string.
89 */
90 deleteChars(idx, len?);
91
92 /*
93 * Splice text. This deletes 'len' characters starting at the given
94 * index (the first character is at index 1), and replaces them with
95 * the given new text. If the new text is nil, this simply deletes the
96 * old characters without inserting anything new. If 'len' is zero,
97 * simply inserts the new text without deleting any old text. A
98 * negative idx value indexes from the end of the string. The 'str'
99 * value is automatically converted to a string if possible.
100 */
101 splice(idx, len, str);
102
103 /*
104 * Retrieve the substring of the buffer starting at the given index and
105 * running for the given character length. If the length is omitted,
106 * everything from the starting index to the end of the buffer is
107 * included in the result string. A negative value for 'idx' indexes
108 * from the end of the string.
109 */
110 substr(idx, len?);
111 }