F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
Fw::StringUtils Namespace Reference

Enumerations

enum  StringToNumberStatus {
  SUCCESSFUL_CONVERSION , NULL_INPUT , INVALID_STRING , INVALID_BASE ,
  INVALID_NUMBER , INVALID_RANGE
}
 

Functions

char * string_copy (char *destination, const char *source, FwSizeType num)
 copy string with null-termination guaranteed More...
 
FwSizeType string_length (const CHAR *source, FwSizeType buffer_size)
 get the length of the source string More...
 
FwSignedSizeType substring_find (const CHAR *source_string, FwSizeType source_size, const CHAR *sub_string, FwSizeType sub_size)
 find the first occurrence of a substring More...
 
StringToNumberStatus string_to_number (const CHAR *input, FwSizeType buffer_size, U8 &output, char **next, U8 base=0)
 converts a string to a U8 More...
 
StringToNumberStatus string_to_number (const CHAR *input, FwSizeType buffer_size, I8 &output, char **next, U8 base=0)
 converts a string to a I8 More...
 
StringToNumberStatus string_to_number (const CHAR *input, FwSizeType buffer_size, F32 &output, char **next)
 converts a string to a F32 More...
 

Enumeration Type Documentation

◆ StringToNumberStatus

Enumerator
SUCCESSFUL_CONVERSION 

Output should be valid.

NULL_INPUT 

A null string was supplied.

INVALID_STRING 

No \0 detected within the supplied length.

INVALID_BASE 

Base was not supplied as 0, or 2-36.

INVALID_NUMBER 

String did not contain a valid number matching supplied base.

INVALID_RANGE 

Definition at line 47 of file StringUtils.hpp.

Function Documentation

◆ string_copy()

char * Fw::StringUtils::string_copy ( char *  destination,
const char *  source,
FwSizeType  num 
)

copy string with null-termination guaranteed

Standard implementations of strncpy fail to guarantee the termination of a string with the null terminator. This implementation guarantees the string is properly null-terminated at the possible expense of the last character of the copied string being lost. The user is responsible for providing a destination large enough for the content and a null-character. Other behavior retains the behavior of strncpy.

Parameters
destinationdestination buffer to hold copied contents
sourcesource buffer to read content to copy
numlength of destination buffer
Returns
destination buffer

Definition at line 6 of file StringUtils.cpp.

◆ string_length()

FwSizeType Fw::StringUtils::string_length ( const CHAR source,
FwSizeType  buffer_size 
)

get the length of the source string

If no string termination character is detected within buffer_size number of characters then buffer_size is returned. When buffer_size is returned, it can be assumed that the source string is invalid within a bound of buffer_size.

Parameters
sourcestring to calculate the length
buffer_sizethe size of the buffer containing source string.
Returns
length of the source string or buffer_size if no \0 is found within buffer_size characters.

Definition at line 23 of file StringUtils.cpp.

◆ string_to_number() [1/3]

Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number ( const CHAR input,
FwSizeType  buffer_size,
F32 output,
char **  next 
)

converts a string to a F32

See string_to_number (above) for full explanation. base is not supported on floating point conversions.

Parameters
inputinput string
buffer_sizemaximum length of string bounding the conversion
basebase of the number. 0 to detect decimal, octal, hexadecimal. 2-36 to use specified base.
output(output) will contain the converted number or 0 on error
next(output) will contain a pointer to the next character after the number and null pointer on error
Returns
SUCCESSFUL_CONVERSION when output is valid, something else on error.

Definition at line 118 of file StringToNumber.cpp.

◆ string_to_number() [2/3]

Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number ( const CHAR input,
FwSizeType  buffer_size,
I8 output,
char **  next,
U8  base = 0 
)

converts a string to a I8

See string_to_number (above) for full explanation.

Parameters
inputinput string
buffer_sizemaximum length of string bounding the conversion
basebase of the number. 0 to detect decimal, octal, hexadecimal. 2-36 to use specified base.
output(output) will contain the converted number or 0 on error
next(output) will contain a pointer to the next character after the number and null pointer on error
Returns
SUCCESSFUL_CONVERSION when output is valid, something else on error.

Definition at line 103 of file StringToNumber.cpp.

◆ string_to_number() [3/3]

Fw::StringUtils::StringToNumberStatus Fw::StringUtils::string_to_number ( const CHAR input,
FwSizeType  buffer_size,
U8 output,
char **  next,
U8  base = 0 
)

converts a string to a U8

See string_to_number (above) for full explanation.

Parameters
inputinput string
buffer_sizemaximum length of string bounding the conversion
basebase of the number. 0 to detect decimal, octal, hexadecimal. 2-36 to use specified base.
output(output) will contain the converted number or 0 on error
next(output) will contain a pointer to the next character after the number and null pointer on error
Returns
SUCCESSFUL_CONVERSION when output is valid, something else on error.

Definition at line 100 of file StringToNumber.cpp.

◆ substring_find()

FwSignedSizeType Fw::StringUtils::substring_find ( const CHAR source_string,
FwSizeType  source_size,
const CHAR sub_string,
FwSizeType  sub_size 
)

find the first occurrence of a substring

Parameters
source_stringstring to search for the substring
source_sizethe size of the source string
substringstring to search for
sub_sizethe size of the string to search for
Returns
index of substring, -1 if not found

Definition at line 34 of file StringUtils.cpp.