epicsString.h

Collection of string utility functions.

Defines

epicsStrSnPrintEscaped

Functions

int epicsStrnRawFromEscaped(char *outbuf, size_t outsize, const char *inbuf, size_t inlen)

Converts C-style escape sequences to their binary form.

Copies characters from string to an output buffer and converts C-style escape sequences to their binary form. Since the output string can never be longer than the source, it is legal for inbuf and outbuf to point to the same buffer and outsize and inlen be equal, thus performing the character translation in-place.

Parameters:
  • outbuf – buffer to copy string to. The resulting string will be zero-terminated as long as outsize is non-zero.

  • outsize – length of output buffer not including the null-terminator.

  • inbuf – buffer to copy from. Null byte terminates the string.

  • inlen – maximum number of characters to copy from input buffer.

Returns:

number of characters that were written into output buffer, not counting the null terminator.

int epicsStrnEscapedFromRaw(char *outbuf, size_t outsize, const char *inbuf, size_t inlen)

Converts non-printable characters into C-style escape sequences.

Copies characters from the string into a output buffer converting non-printable characters into C-style escape sequences. In-place translations are not allowed since the escaped results will usually be larger than the input string.

The following escaped character constants will be used in the output:

\a \b \f \n \r \t \v \\ \’ \" \0
All other non-printable characters appear in form \xHH where HH are two hex digits. Non-printable characters are determined by the C runtime library’s isprint() function.

Parameters:
  • outbuf – buffer to copy string to. The resulting string will be zero-terminated as long as outsize is non-zero.

  • outsize – length of output buffer not including the null-terminator.

  • inbuf – buffer to copy from. Null byte will not terminates the string.

  • inlen – Number of characters to copy from input buffer.

Returns:

number of characters that would have been stored in the output buffer if it were large enough, or a negative value if outbuf == inbuf.

size_t epicsStrnEscapedFromRawSize(const char *buf, size_t len)

Scans string and returns size of output buffer needed to escape that string.

Scans up to len characters of the string that may contain non-printable characters, and returns the size of the output buffer that would be needed to escape that string. This routine is faster than calling epicsStrnEscapedFromRaw() with a zero length output buffer; both should return the same result.

Parameters:
  • buf – string to scan

  • len – length of input string

Returns:

size of the output buffer that would be needed for converting to escape characters, not including the null terminator.

int epicsStrCaseCmp(const char *s1, const char *s2)

Does case-insensitive comparison of two strings.

Implements strcmp from the C standard library, except is case insensitive

int epicsStrnCaseCmp(const char *s1, const char *s2, size_t len)

Does case-insensitive comparision of two strings.

Implements strncmp from the C standard library, except is case insensitive

char *epicsStrDup(const char *s)

Duplicates a string.

Implements strdup from the C standard library. Calls mallocMustSucceed() to allocate memory

char *epicsStrnDup(const char *s, size_t len)

Duplicates a string.

implements strndup from the C standard library. Calls mallocMustSucceed() to allocate memory

int epicsStrPrintEscaped(FILE *fp, const char *s, size_t n)

Prints escaped version of string.

Prints the contents of its input buffer to given file descriptor, substituting escape sequences for non-printable characters.

Parameters:
  • fp – File descriptor to print to

  • s – String to print

  • n – Length of string

size_t epicsStrnLen(const char *s, size_t maxlen)

Calculates length of string.

Implements strnlen from the C standard library.

int epicsStrGlobMatch(const char *str, const char *pattern)

Matches a string against a pattern.

Checks if str matches the glob style pattern, which may contain ? or * wildcards. A ? matches any single character. A * matched any sub-string.

Since

EPICS 3.14.7

Returns:

1 if str matches the pattern, 0 if not.

int epicsStrnGlobMatch(const char *str, size_t len, const char *pattern)

Matches a string against a pattern.

Like epicsStrGlobMatch() but with limited string length. If the length of str is less than len, the full string is matched.

Since

7.0.6

Returns:

1 if the first len characters of str match the pattern, 0 if not.

char *epicsStrtok_r(char *s, const char *delim, char **lasts)

Extract tokens from string.

Implements strtok_r from the C standard library

unsigned int epicsStrHash(const char *str, unsigned int seed)

Calculates a hash of a null-terminated string.

Calculates a hash of a null-terminated string. Initial seed may be provided which permits multiple strings to be combined into a single hash result.

Parameters:
  • str – null-terminated string

  • seed – Optionally provide seed to combine multiple strings in a single hash. Otherwise set to 0.

Returns:

Hash value for string

unsigned int epicsMemHash(const char *str, size_t length, unsigned int seed)

Calculates a hash of a memory buffer.

Calculates a hash of a memory buffer that may contain null values. Initial seed may be provided which permits multiple buffers to be combined into a single hash result.

Parameters:
  • str – buffer

  • length – size of buffer

  • seed – Optionally provide seed to combine multiple buffers in a single hash. Otherwise set to 0.

Returns:

Hash value for buffer

double epicsStrSimilarity(const char *A, const char *B)

Compare two strings and return a number in the range [0.0, 1.0] or -1.0 on error.

Computes a normalized edit distance representing the similarity between two strings.

Since

EPICS 7.0.5

Returns:

1.0 when A and B are identical, down to 0.0 when A and B are unrelated, or < 0.0 on error.

int dbTranslateEscape(char *s, const char *ct)

DEPRECATED.

Deprecated:

dbTranslateEscape is deprecated, use epicsStrnRawFromEscaped() instead