55 /// coded by @pradosh-arduino (github)
66 /// </summary>
77 public class prad_buffer {
8- private char [ ] buffer = new char [ 1024 ] ;
8+ private char [ ] buffer ;
9+ private int buffer_size ;
910
1011 /// <summary>
1112 /// Stores the current index of the input buffer.
@@ -17,6 +18,25 @@ public class prad_buffer {
1718 /// </summary>
1819 public int length = 0 ;
1920
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+
2040 /// <summary>
2141 /// Function to add a character to the buffer.
2242 /// </summary>
@@ -43,7 +63,7 @@ public void clear_buffer(){
4363 }
4464
4565 /// <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.
4767 /// </summary>
4868 public void get_input ( ) {
4969 ConsoleKeyInfo current ;
@@ -106,7 +126,7 @@ public void get_input(){
106126 }
107127
108128 /// <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.
110130 /// </summary>
111131 /// <param name="prefix">The actual prefix needed to be displayed</param>
112132 public void get_input ( string prefix ) {
@@ -187,5 +207,23 @@ public char[] get_buffer(){
187207 public string get_buffer_as_string ( ) {
188208 return new string ( buffer , 0 , length ) ;
189209 }
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+ }
190228 }
191229}
0 commit comments