strings_unbounded

extras/strings_unbounded.vhdl

Description

This package provides a string library for operating on unbounded length strings. This is a clone of the Ada‘95 library Ada.Strings.Unbounded. Due to the VHDL restriction on using access types as function parameters only a limited subset of the Ada library is reproduced. The unbounded strings are represented by the subtype unbounded_string which is derived from line to ease interoperability with std.textio.line and unbounded_string are of type access to string. Their contents are dynamically allocated. Because operators cannot be provided, a new set of “copy” procedures are included to simplify duplication of an existing unbounded string.

Subtypes

strings_unbounded.unbounded_string

A subtype of the textio line type to form a coupling between libraries.

Subprograms

strings_unbounded.to_unbounded_string (source : string) → unbounded_string
Convert a string to unbounded_string.
Parameters:
  • source (string) – String to convert into unbounded_string
Returns:

A converted string.

strings_unbounded.to_unbounded_string (length : natural) → unbounded_string
Allocate a string of length.
Parameters:
  • length (natural) – Length of the new string
Returns:

A new string of the requested length.

strings_unbounded.to_string (source : in unbounded_string; dest : out string)
Copy a unbounded_string to the string dest.
Parameters:
  • source (in unbounded_string) – String to copy
  • dest (out string) – Copy destination
strings_unbounded.initialize (source : inout unbounded_string)
Create an empty unbounded_string.
Parameters:
  • source (inout unbounded_string) – String to initialize
strings_unbounded.free (source : inout unbounded_string)
Free allocated memory for source.
Parameters:
  • source (inout unbounded_string) – Deallocate an unbounded_string
strings_unbounded.length (source : in unbounded_string; len : out natural)
Return the length of a unbounded_string.
Parameters:
  • source (in unbounded_string) – String to check length of
  • len (out natural) – Length of the string
strings_unbounded.copy (source : in unbounded_string; dest : inout unbounded_string; max : in integer := -1)
Copy at most max characters from source to the unallocated dest.
Parameters:
  • source (in unbounded_string) – String to copy
  • dest (inout unbounded_string) – Destination of copy
  • max (in integer) – Maximum number of characters to copy
strings_unbounded.copy (source : in string; dest : inout unbounded_string; max : in integer := -1)
Copy at most max characters from source to the unallocated dest.
Parameters:
  • source (in string) – String to copy
  • dest (inout unbounded_string) – Destination of copy
  • max (in integer) – Maximum number of characters to copy
strings_unbounded.append (source : inout unbounded_string; new_item : in unbounded_string)
Append unbounded_string new_item to source.
Parameters:
  • source (inout unbounded_string) – String to append onto
  • new_item (in unbounded_string) – String to append
strings_unbounded.append (source : inout unbounded_string; new_item : in string)
Append string new_item to source.
Parameters:
  • source (inout unbounded_string) – String to append onto
  • new_item (in string) – String to append
strings_unbounded.append (source : inout unbounded_string; new_item : in character)
Append character new_item to source.
Parameters:
  • source (inout unbounded_string) – String to append onto
  • new_item (in character) – Character to append
strings_unbounded.element (source : in unbounded_string; index : in positive; el : out character)
Lookup the character in source at index.
Parameters:
  • source (in unbounded_string) – String to index into
  • index (in positive) – Position of element to retrieve
  • el (out character) – Character at index position
strings_unbounded.replace_element (source : inout unbounded_string; index : in positive; by : in character)
Replace the character in source at index with by.
Parameters:
  • source (inout unbounded_string) – String to modify
  • index (in positive) – Position of element to modify
  • by (in character) – New character to place in index position
strings_unbounded.slice (source : in unbounded_string; low : in positive; high : in positive; result : inout unbounded_string)
Extract a slice from source.
Parameters:
  • source (in unbounded_string) – String to slice
  • low (in positive) – Start index of slice (inclusive)
  • high (in positive) – End index of slice (inclusive)
  • result (inout unbounded_string) – Sliced string
strings_unbounded.eq (left : in unbounded_string; right : in unbounded_string; result : out boolean)
Test if left is identical to right.
Parameters:
  • left (in unbounded_string) – Left string
  • right (in unbounded_string) – Right string
  • result (out boolean) – true when strings are identical.
strings_unbounded.eq (left : in unbounded_string; right : in string; result : out boolean)
Test if left is identical to right.
Parameters:
  • left (in unbounded_string) – Left string
  • right (in string) – Right string
  • result (out boolean) – true when strings are identical.
strings_unbounded.count (source : in unbounded_string; pattern : in string; val : out natural)
Count the occurrences of pattern in source.
Parameters:
  • source (in unbounded_string) – String to count patterns in
  • pattern (in string) – Pattern to count in source string
  • val (out natural) – Number or times pattern occurs in the source string.
strings_unbounded.delete (source : inout unbounded_string; from : in positive; through : in natural)
Delete a slice from source. If from is greater than through, source is unmodified.
Parameters:
  • source (inout unbounded_string) – String to delete a slice from
  • from (in positive) – Start index (inclusive)
  • through (in natural) – End index (inclusive)
strings_unbounded.find_token (source : in unbounded_string; set : in character_set; test : in membership; first : out positive; last : out natural)
Return the indices of a slice of source that satisfies the membership selection for the character set.
Parameters:
  • source (in unbounded_string) – String to search for the token
  • set (in character_set) – Character set for the token
  • test (in membership) – Check for characters inside or outside the set
  • first (out positive) – Start index of the token
  • last (out natural) – End index of the token or 0 if not found
strings_unbounded.head (source : inout unbounded_string; count : in natural; pad : in character := ' ')
Return the first count characters from source.
Parameters:
  • source (inout unbounded_string) – String to slice head from
  • count (in natural) – Number of characters to take from the start of source
  • pad (in character) – Characters to pad with if source length is less than count
strings_unbounded.insert (source : inout unbounded_string; before : in positive; new_item : in string)
Insert the string new_item before the selected index in source.
Parameters:
  • source (inout unbounded_string) – String to insert into
  • before (in positive) – Index position for insertion
  • new_item (in string) – String to insert
strings_unbounded.overwrite (source : inout unbounded_string; position : in positive; new_item : in string)
Overwrite new_item into source starting at the selected position.
Parameters:
  • source (inout unbounded_string) – String to overwrite
  • position (in positive) – Index position for overwrite
  • new_item (in string) – String to write into source
strings_unbounded.replace_slice (source : inout unbounded_string; low : in positive; high : in natural; by : in string)
Replace a slice of the source string with the contents of by.
Parameters:
  • source (inout unbounded_string) – String to replace
  • low (in positive) – Start of the slice (inclusive)
  • high (in natural) – End of the slice (inclusive)
  • by (in string) – String to insert into slice position
strings_unbounded.tail (source : inout unbounded_string; count : in natural; pad : in character := ' ')
Return the last count characters from source.
Parameters:
  • source (inout unbounded_string) – String to slice tail from
  • count (in natural) – Number of characters to take from the end of source
  • pad (in character) – Characters to pad with if source length is less than count
strings_unbounded.translate (source : inout unbounded_string; mapping : in character_mapping)
Convert a source string with the provided character mapping.
Parameters:
  • source (inout unbounded_string) – String to translate
  • mapping (in character_mapping) – Mapping to apply
strings_unbounded.trim (source : inout unbounded_string; side : in trim_end)
Remove space characters from leading, trailing, or both ends of source.
Parameters:
  • source (inout unbounded_string) – String to trim
  • side (in trim_end) – Which end to trim
strings_unbounded.trim (source : inout unbounded_string; left : in character_set; right : in character_set)
Remove all leading characters in left and trailing characters in right from source.
Parameters:
  • source (inout unbounded_string) – String to trim
  • left (in character_set) – Index position for start trim
  • right (in character_set) – Index position for end trim