text_buffering

extras/text_buffering.vhdl

Dependencies

strings_unbounded

Description

This package provides a facility for storing buffered text. It can be used to represent the contents of a text file as a linked list of dynamically allocated strings for each line. A text file can be read into a buffer and the resulting data structure can be incorporated into records passable to procedures without having to maintain a separate file handle.

Example usage

variable buf    : text_buffer;
variable at_end : boolean;
variable tl     : unbounded_string;

-- Add lines of text to a buffer
append("First line", buf);
append("Second line", buf);
write("example.txt", buf);
free(buf);

-- Read a file into a buffer and iterate over its lines
load_buffer("example.txt", buf);
endbuffer(buf, at_end);
while not at_end loop
 nextline(buf, tl);
 endbuffer(buf, at_end);
end loop;
free(buf);

Types

text_buffering.buffer_line_acc

Pointer to next node in list.

text_buffering.buffer_line

Linked list node of text lines.

text_buffering.text_buffer

Buffer of text lines.

Subprograms

text_buffering.load_buffer (Fh : text; Buf : out text_buffer)
Load a text file object into a buffer.
Parameters:
  • Fh (None text) – File handle
  • Buf (out text_buffer) – Buffer created from file contents
text_buffering.load_buffer (Fname : in string; Buf : out text_buffer)
Load a file into a buffer.
Parameters:
  • Fname (in string) – Name of text file to read
  • Buf (out text_buffer) – Buffer created from file contents
text_buffering.append_file (Fh : text; Buf : inout text_buffer)
Append a text file object to an existing buffer.
Parameters:
  • Fh (None text) – File handle
  • Buf (inout text_buffer) – Buffer to append onto
text_buffering.append_file (Fname : in string; Buf : inout text_buffer)
Append a text file to an existing buffer.
Parameters:
  • Fname (in string) – Name of text file to read
  • Buf (inout text_buffer) – Buffer to append onto
text_buffering.append (One_line : in unbounded_string; Buf : inout text_buffer)
Append an unbounded string to a buffer.
Parameters:
  • One_line (in unbounded_string) – String to append
  • Buf (inout text_buffer) – Buffer to append onto
text_buffering.append (One_line : in string; Buf : inout text_buffer)
Append a string to a buffer
Parameters:
  • One_line (in string) – String to append
  • Buf (inout text_buffer) – Buffer to append onto
text_buffering.write (Fh : text; Buf : in text_buffer)
Write a buffer to a text file object.
Parameters:
  • Fh (None text) – File handle
  • Buf (in text_buffer) – Buffer to write into the file
text_buffering.write (Fname : string; Buf : in text_buffer)
Write a buffer to a text file.
Parameters:
  • Fname (None string) – Name of text file to write
  • Buf (in text_buffer) – Buffer to write into the file
text_buffering.nextline (Buf : inout text_buffer; Tl : inout unbounded_string)
Retrieve the current line from a buffer.
Parameters:
  • Buf (inout text_buffer) – Buffer to get line from
  • Tl (inout unbounded_string) – Current line in the buffer
text_buffering.setline (Buf : inout text_buffer; N : in positive)
Move to a specific line in the buffer.
Parameters:
  • Buf (inout text_buffer) – Buffer to seek into
  • N (in positive) – Line number (zero based)
text_buffering.endbuffer (Buf : in text_buffer; At_end : out boolean)
Check if the end of the buffer has been reached.
Parameters:
  • Buf (in text_buffer) – Buffer to test
  • At_end (out boolean) – true when the buffer line pointer is at the end
text_buffering.free (Buf : inout text_buffer)
Deallocate the buffer contents
Parameters:
  • Buf (inout text_buffer) – Buffer to free