5
5
/// coded by @pradosh-arduino (github)
6
6
/// </summary>
7
7
public class prad_buffer {
8
- private char [ ] buffer = new char [ 1024 ] ;
8
+ private char [ ] buffer ;
9
+ private int buffer_size ;
9
10
10
11
/// <summary>
11
12
/// Stores the current index of the input buffer.
@@ -17,6 +18,25 @@ public class prad_buffer {
17
18
/// </summary>
18
19
public int length = 0 ;
19
20
21
+ /// <summary>
22
+ /// Constructor to initialize the buffer with its size.
23
+ /// </summary>
24
+ public prad_buffer ( )
25
+ {
26
+ buffer_size = 1024 ;
27
+ buffer = new char [ buffer_size ] ;
28
+ }
29
+
30
+ /// <summary>
31
+ /// Constructor to initialize the buffer with your own size.
32
+ /// </summary>
33
+ /// <param name="size">The size of the buffer.</param>
34
+ public prad_buffer ( int size )
35
+ {
36
+ buffer_size = size ;
37
+ buffer = new char [ buffer_size ] ;
38
+ }
39
+
20
40
/// <summary>
21
41
/// Function to add a character to the buffer.
22
42
/// </summary>
@@ -43,7 +63,7 @@ public void clear_buffer(){
43
63
}
44
64
45
65
/// <summary>
46
- /// Gets the input and stores it in the input buffer array cleanly. It does not return the buffer.
66
+ /// Gets the input and stores it in the input buffer array cleanly. It does <b>NOT</b> return the buffer.
47
67
/// </summary>
48
68
public void get_input ( ) {
49
69
ConsoleKeyInfo current ;
@@ -106,7 +126,7 @@ public void get_input(){
106
126
}
107
127
108
128
/// <summary>
109
- /// Gets the input and stores it in the input buffer array cleanly. It does not return the buffer. We can add a prefix to the input.
129
+ /// Gets the input and stores it in the input buffer array cleanly. It does <b>NOT</b> return the buffer. We can add a prefix to the input.
110
130
/// </summary>
111
131
/// <param name="prefix">The actual prefix needed to be displayed</param>
112
132
public void get_input ( string prefix ) {
@@ -187,5 +207,23 @@ public char[] get_buffer(){
187
207
public string get_buffer_as_string ( ) {
188
208
return new string ( buffer , 0 , length ) ;
189
209
}
210
+
211
+ /// <summary>
212
+ /// Function to get the allocated buffer size.
213
+ /// </summary>
214
+ /// <returns>The buffer size in integer.</returns>
215
+ public int get_buffer_size ( ) {
216
+ return buffer_size ;
217
+ }
218
+
219
+ /// <summary>
220
+ /// Function to set the buffer size.
221
+ /// This function will <b>CLEAR</b> the buffer and reallocate the buffer with the new size.
222
+ /// </summary>
223
+ /// <param name="size">The size of buffer (default is 1024)</param>
224
+ public void set_buffer_size ( int size ) {
225
+ buffer_size = size ;
226
+ buffer = new char [ buffer_size ] ;
227
+ }
190
228
}
191
229
}
0 commit comments