CTRE Phoenix 6 C++ 24.3.0
ctre::phoenix::string_util Namespace Reference

Functions

CTREXPORT std::vector< std::string > string_split (std::string const &input, char delimiter)
 Splits a string by the given delimiter. More...
 
CTREXPORT std::string toLower (std::string_view input)
 Creates a new, lowercase version of the given string. More...
 
CTREXPORT void makeLower (std::string &input)
 Converts the given string to lowercase in-place. More...
 
CTREXPORT std::string toUpper (std::string_view input)
 Creates a new, uppercase version of the given string. More...
 
CTREXPORT void makeUpper (std::string &input)
 Converts the given string to uppercase in-place. More...
 
CTREXPORT int strcmp_nocase (char const *a, char const *b)
 Case-insensitive strcmp. More...
 
CTREXPORT uint32_t safe_copyDoubles (double *dest, double const *src, int32_t numDoubles, int32_t capacityDoubles)
 
CTREXPORT uint32_t safe_copyDoubles (double *dest, std::vector< double > const &src, int32_t capacityDoubles)
 
CTREXPORT size_t safe_memcpy (void *dest, void const *src, size_t numBytesToCopy, size_t capacity)
 Safely copies data from the source to the destination. More...
 
CTREXPORT char * safe_strcpy (char *dest, char const *src, size_t capacity)
 Safely copies a string to the destination. More...
 
CTREXPORT char * safe_strcpy (char *dest, char const *src, size_t capacityDest, size_t capacitySrc)
 Safely copies a string to the destination. More...
 
CTREXPORT char * safe_strcat (char *dest, char const *src, size_t capacity)
 Safely concatenates a string to the destination. More...
 
CTREXPORT char * safe_strcat (char *dest, char const *src, size_t capacityDest, size_t capacitySrc)
 Safely concatenates a string to the destination. More...
 
CTREXPORT char * safe_strtok (char **str_ptr, char const *delimiters)
 Safer strtok that finds and returns a pointer to the next token in *str_ptr, separated using one of the delimiters passed in. More...
 
CTREXPORT constexpr size_t safe_strlen (char const *s, size_t capacity)
 Safely determines the length of a string with the given capacity. More...
 
template<typename T >
bool toNumber (std::string const &str, T &value)
 Converts string to number while informing caller if operation was successful. More...
 

Function Documentation

◆ makeLower()

CTREXPORT void ctre::phoenix::string_util::makeLower ( std::string &  input)

Converts the given string to lowercase in-place.

◆ makeUpper()

CTREXPORT void ctre::phoenix::string_util::makeUpper ( std::string &  input)

Converts the given string to uppercase in-place.

◆ safe_copyDoubles() [1/2]

CTREXPORT uint32_t ctre::phoenix::string_util::safe_copyDoubles ( double *  dest,
double const *  src,
int32_t  numDoubles,
int32_t  capacityDoubles 
)
Returns
number of doubles copied

◆ safe_copyDoubles() [2/2]

CTREXPORT uint32_t ctre::phoenix::string_util::safe_copyDoubles ( double *  dest,
std::vector< double > const &  src,
int32_t  capacityDoubles 
)
Returns
number of doubles copied

◆ safe_memcpy()

CTREXPORT size_t ctre::phoenix::string_util::safe_memcpy ( void *  dest,
void const *  src,
size_t  numBytesToCopy,
size_t  capacity 
)

Safely copies data from the source to the destination.

At most capacity bytes will be copied.

◆ safe_strcat() [1/2]

CTREXPORT char * ctre::phoenix::string_util::safe_strcat ( char *  dest,
char const *  src,
size_t  capacity 
)

Safely concatenates a string to the destination.

The source will be concatenated until the destination is full, and the destination will be null-terminated.

◆ safe_strcat() [2/2]

CTREXPORT char * ctre::phoenix::string_util::safe_strcat ( char *  dest,
char const *  src,
size_t  capacityDest,
size_t  capacitySrc 
)

Safely concatenates a string to the destination.

The source will be concatenated until the destination is full or the source capacity has been reached, and the destination will be null-terminated.

◆ safe_strcpy() [1/2]

CTREXPORT char * ctre::phoenix::string_util::safe_strcpy ( char *  dest,
char const *  src,
size_t  capacity 
)

Safely copies a string to the destination.

The source will be copied until the destination is full, and the destination will be null-terminated.

◆ safe_strcpy() [2/2]

CTREXPORT char * ctre::phoenix::string_util::safe_strcpy ( char *  dest,
char const *  src,
size_t  capacityDest,
size_t  capacitySrc 
)

Safely copies a string to the destination.

The source will be copied until the destination is full or the source capacity has been reached, and the destination will be null-terminated.

◆ safe_strlen()

CTREXPORT constexpr size_t ctre::phoenix::string_util::safe_strlen ( char const *  s,
size_t  capacity 
)
constexpr

Safely determines the length of a string with the given capacity.

◆ safe_strtok()

CTREXPORT char * ctre::phoenix::string_util::safe_strtok ( char **  str_ptr,
char const *  delimiters 
)

Safer strtok that finds and returns a pointer to the next token in *str_ptr, separated using one of the delimiters passed in.

This also function modifies the input str_ptr to point to the remaining string after the delimiter, or NULL if none is found.

This function is similar to the POSIX strsep()

Unlike strtok, you should always pass in str_ptr. The caller must make sure both inputs are null terminated.

char str_buffer[] = "\nThis is\n a test ";
char *str = str_buffer;
char *token = safe_strtok(&str, " \n");
while (token != NULL) {
printf("%s\n", token);
token = safe_strtok(&str, " \n");
}
CTREXPORT char * safe_strtok(char **str_ptr, char const *delimiters)
Safer strtok that finds and returns a pointer to the next token in *str_ptr, separated using one of t...

◆ strcmp_nocase()

CTREXPORT int ctre::phoenix::string_util::strcmp_nocase ( char const *  a,
char const *  b 
)

Case-insensitive strcmp.

◆ string_split()

CTREXPORT std::vector< std::string > ctre::phoenix::string_util::string_split ( std::string const &  input,
char  delimiter 
)

Splits a string by the given delimiter.

◆ toLower()

CTREXPORT std::string ctre::phoenix::string_util::toLower ( std::string_view  input)

Creates a new, lowercase version of the given string.

◆ toNumber()

template<typename T >
bool ctre::phoenix::string_util::toNumber ( std::string const &  str,
T &  value 
)

Converts string to number while informing caller if operation was successful.

Template Parameters
TType of number to convert to
Parameters
strString to convert from
valueValue of Type T to capture numeric value
Returns
true iff operation was successful

◆ toUpper()

CTREXPORT std::string ctre::phoenix::string_util::toUpper ( std::string_view  input)

Creates a new, uppercase version of the given string.