strings_fixed

extras/strings_fixed.vhdl

Description

This package provides a string library for operating on fixed length strings. This is a clone of the Ada‘95 library Ada.Strings.Fixed. It is a nearly complete implementation with only the procedures taking character mapping functions omitted because of VHDL limitations.

These are functions for operating on the native VHDL string type. Any operation that results in a shorter string must be padded with additional characters to fill out the entire string.

Subprograms

strings_fixed.move (source : in string; target : out string; drop : in truncation := error; justify : in alignment := left; pad : in character := ' ')
Move source to target.
Parameters:
  • source (in string) – String to move
  • target (out string) – Destingation string
  • drop (in truncation) – Truncation mode
  • justify (in alignment) – Alignment mode
  • pad (in character) – Padding character for target when longer than source
strings_fixed.index (source : string; pattern : string; going : direction := forward; mapping : character_mapping := identity) → natural
Find the index of the first occurance of pattern in source from the beginning or end.
Parameters:
  • source (string) – String to search
  • pattern (string) – Search pattern
  • going (direction) – Search direction
  • mapping (character_mapping) – Optional mapping applied to source string
Returns:

Index position of pattern or 0 if not found.

strings_fixed.index (source : string; set : character_set; test : membership := inside; going : direction := forward) → natural
Find the index of first occurance of a character from set in source.
Parameters:
  • source (string) – String to search
  • set (character_set) – Character set to search for
  • test (membership) – Check for characters inside or outside the set
  • going (direction) – Search direction
Returns:

Index position of first matching character or 0 if not found.

strings_fixed.index_non_blank (source : string; going : direction := forward) → natural
Find the index of the first non-space character in source.
Parameters:
  • source (string) – String to search
  • going (direction) – Search direction
Returns:

Index position of first non-space character or 0 if none found.

strings_fixed.count (source : string; pattern : string; mapping : character_mapping := identity) → natural
Count the occurrences of pattern in source.
Parameters:
  • source (string) – String to count patterns in
  • pattern (string) – Pattern to count in source string
Returns:

Number or times pattern occurs in the source string.

strings_fixed.count (source : string; set : character_set) → natural
Count the occurrences of characters from set in source.
Parameters:
  • source (string) – String to count characters in
  • set (character_set) – Character set to count
Returns:

Number of times a character from set occurs in the source string.

strings_fixed.find_token (source : in 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 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_fixed.translate (source : string; mapping : character_mapping) → string
Convert a source string with the provided character mapping.
Parameters:
  • source (string) – String to translate
  • mapping (character_mapping) – Mapping to apply
Returns:

New string with applied mapping.

strings_fixed.translate (source : inout string; mapping : in character_mapping)
Convert a source string with the provided character mapping.
Parameters:
  • source (inout string) – String to translate
  • mapping (in character_mapping) – Mapping to apply
strings_fixed.replace_slice (source : string; low : positive; high : natural; by : string) → string
Replace a slice of the source string with the contents of by.
Parameters:
  • source (string) – String to replace
  • low (positive) – Start of the slice (inclusive)
  • high (natural) – End of the slice (inclusive)
  • by (string) – String to insert into slice position
Returns:

New string with replaced slice.

strings_fixed.replace_slice (source : inout string; low : in positive; high : in natural; by : in string; drop : in truncation := error; justify : in alignment := left; pad : in character := ' ')
Replace a slice of the source string with the contents of by.
Parameters:
  • source (inout 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
  • drop (in truncation) – Truncation mode
  • justify (in alignment) – Alignment mode
  • pad (in character) – Padding character when result is shorter than original string
strings_fixed.insert (source : string; before : positive; new_item : string) → string
Insert the string new_item before the selected index in source.
Parameters:
  • source (string) – String to insert into
  • before (positive) – Index position for insertion
  • new_item (string) – String to insert
Returns:

Source string with new_item inserted.

strings_fixed.insert (source : inout string; before : in positive; new_item : in string; drop : in truncation := error)
Insert the string new_item before the selected index in source.
Parameters:
  • source (inout string) – String to insert into
  • before (in positive) – Index position for insertion
  • new_item (in string) – String to insert
  • drop (in truncation) – Truncation mode
strings_fixed.overwrite (source : string; position : positive; new_item : string) → string
Overwrite new_item into source starting at the selected position.
Parameters:
  • source (string) – String to overwrite
  • position (positive) – Index position for overwrite
  • new_item (string) – String to write into source
Returns:

New string with overwritten item.

strings_fixed.overwrite (source : inout string; position : in positive; new_item : in string; drop : in truncation := right)
Overwrite new_item into source starting at the selected position.
Parameters:
  • source (inout string) – String to overwrite
  • position (in positive) – Index position for overwrite
  • new_item (in string) – String to write into source
  • drop (in truncation) – Truncation mode
strings_fixed.delete (source : string; from : positive; through : natural) → string
Delete a slice from source. If from is greater than through, source is unmodified.
Parameters:
  • source (string) – String to delete a slice from
  • from (positive) – Start index (inclusive)
  • through (natural) – End index (inclusive)
Returns:

New string with a slice deleted.

strings_fixed.delete (source : inout string; from : in positive; through : in natural; justify : in alignment := left; pad : in character := ' ')
Delete a slice from source. If from is greater than through, source is unmodified.
Parameters:
  • source (inout string) – String to delete a slice from
  • from (in positive) – Start index (inclusive)
  • through (in natural) – End index (inclusive)
  • justify (in alignment) – Position of shortened result in string
  • pad (in character) – Character to use as padding for shortened string
strings_fixed.trim (source : string; side : trim_end) → string
Remove space characters from leading, trailing, or both ends of source.
Parameters:
  • source (string) – String to trim
  • side (trim_end) – Which end to trim
Returns:

Source string with space trimmed.

strings_fixed.trim (source : inout string; side : in trim_end; justify : in alignment := left; pad : in character := ' ')
Remove space characters from leading, trailing, or both ends of source.
Parameters:
  • source (inout string) – String to trim
  • side (in trim_end) – Which end to trim
  • justify (in alignment) – Position of shortened result in string
  • pad (in character) – Character to use as padding for shortened string
strings_fixed.trim (source : string; left : character_set; right : character_set) → string
Remove all leading characters in left and trailing characters in right from source.
Parameters:
  • source (string) – String to trim
  • left (character_set) – Index position for start trim
  • right (character_set) – Index position for end trim
Returns:

Source string with ends trimmed.

strings_fixed.trim (source : inout string; left : in character_set; right : in character_set; justify : in alignment := extras.strings.left; pad : in character := ' ')
Remove all leading characters in left and trailing characters in right from source.
Parameters:
  • source (inout string) – String to trim
  • left (in character_set) – Index position for start trim
  • right (in character_set) – Index position for end trim
  • justify (in alignment) – Position of shortened result in string
  • pad (in character) – Character to use as padding for shortened string
strings_fixed.head (source : string; count : natural; pad : character := ' ') → string
Return the first count characters from source.
Parameters:
  • source (string) – String to slice from
  • count (natural) – Number of characters to take from the start of source
  • pad (character) – Characters to pad with if source length is less than count
Returns:

A string of length count.

strings_fixed.head (source : inout string; count : in natural; justify : in alignment := left; pad : in character := ' ')
Return the first count characters from source.
Parameters:
  • source (inout string) – String to slice from
  • count (in natural) – Number of characters to take from the start of source
  • justify (in alignment) – Position of shortened result in string
  • pad (in character) – Characters to pad with if source length is less than count
strings_fixed.tail (source : string; count : natural; pad : character := ' ') → string
Return the last count characters from source.
Parameters:
  • source (string) – String to slice from
  • count (natural) – Number of characters to take from the end of source
  • pad (character) – Characters to pad with if source length is less than count
Returns:

A string of length count.

strings_fixed.tail (source : inout string; count : in natural; justify : in alignment := left; pad : in character := ' ')
Return the last count characters from source.
Parameters:
  • source (inout string) – String to slice from
  • count (in natural) – Number of characters to take from the end of source
  • justify (in alignment) – Position of shortened result in string
  • pad (in character) – Characters to pad with if source length is less than count
strings_fixed."*" (left : natural; right : character) → string
Replicate a character left number of times.
Parameters:
  • left (natural) – Number of times to repeat the right operand
  • right (character) – Character to repeat in string
Returns:

String with repeated character.

strings_fixed."*" (left : natural; right : string) → string
Replicate a string left number of times.
Parameters:
  • left (natural) – Number of times to repeat the right operand
  • right (string) – String to repeat in result string
Returns:

String with repeated substring.

strings_fixed.hash (key : string) → natural
Compute hash value of a string.
Parameters:
  • key (string) – String to be hashed
Returns:

Hash value.