EPICS Base 7.0.8.0
Loading...
Searching...
No Matches
Macros | Functions
epicsString.h File Reference

Collection of string utility functions. More...

#include <stdio.h>
#include "epicsTypes.h"
#include "libComAPI.h"
Include dependency graph for epicsString.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define epicsStrSnPrintEscaped   epicsStrnEscapedFromRaw
 

Functions

LIBCOM_API int epicsStrnRawFromEscaped (char *outbuf, size_t outsize, const char *inbuf, size_t inlen)
 Converts C-style escape sequences to their binary form.
 
LIBCOM_API int epicsStrnEscapedFromRaw (char *outbuf, size_t outsize, const char *inbuf, size_t inlen)
 Converts non-printable characters into C-style escape sequences.
 
LIBCOM_API size_t epicsStrnEscapedFromRawSize (const char *buf, size_t len)
 Scans string and returns size of output buffer needed to escape that string.
 
LIBCOM_API int epicsStrCaseCmp (const char *s1, const char *s2)
 Does case-insensitive comparison of two strings.
 
LIBCOM_API int epicsStrnCaseCmp (const char *s1, const char *s2, size_t len)
 Does case-insensitive comparision of two strings.
 
LIBCOM_API charepicsStrDup (const char *s)
 Duplicates a string.
 
LIBCOM_API charepicsStrnDup (const char *s, size_t len)
 Duplicates a string.
 
LIBCOM_API int epicsStrPrintEscaped (FILE *fp, const char *s, size_t n)
 Prints escaped version of string.
 
LIBCOM_API size_t epicsStrnLen (const char *s, size_t maxlen)
 Calculates length of string.
 
LIBCOM_API int epicsStrGlobMatch (const char *str, const char *pattern)
 Matches a string against a pattern.
 
LIBCOM_API int epicsStrnGlobMatch (const char *str, size_t len, const char *pattern)
 Matches a string against a pattern.
 
LIBCOM_API charepicsStrtok_r (char *s, const char *delim, char **lasts)
 Extract tokens from string.
 
LIBCOM_API unsigned int epicsStrHash (const char *str, unsigned int seed)
 Calculates a hash of a null-terminated string.
 
LIBCOM_API unsigned int epicsMemHash (const char *str, size_t length, unsigned int seed)
 Calculates a hash of a memory buffer.
 
LIBCOM_API 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.
 
LIBCOM_API int dbTranslateEscape (char *s, const char *ct)
 DEPRECATED.
 

Macro Definition Documentation

◆ epicsStrSnPrintEscaped

#define epicsStrSnPrintEscaped   epicsStrnEscapedFromRaw

Definition at line 125 of file epicsString.h.

Function Documentation

◆ epicsStrnRawFromEscaped()

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

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
outbufbuffer to copy string to. The resulting string will be zero-terminated as long as outsize is non-zero.
outsizelength of output buffer not including the null-terminator.
inbufbuffer to copy from. Null byte terminates the string.
inlenmaximum number of characters to copy from input buffer.
Returns
number of characters that were written into output buffer, not counting the null terminator.

◆ epicsStrnEscapedFromRaw()

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

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
outbufbuffer to copy string to. The resulting string will be zero-terminated as long as outsize is non-zero.
outsizelength of output buffer not including the null-terminator.
inbufbuffer to copy from. Null byte will not terminates the string.
inlenNumber 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.

◆ epicsStrnEscapedFromRawSize()

LIBCOM_API size_t epicsStrnEscapedFromRawSize ( const char buf,
size_t  len 
)

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
bufstring to scan
lenlength of input string
Returns
size of the output buffer that would be needed for converting to escape characters, not including the null terminator.

◆ epicsStrCaseCmp()

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

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

◆ epicsStrnCaseCmp()

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

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

◆ epicsStrDup()

LIBCOM_API char * epicsStrDup ( const char s)

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

◆ epicsStrnDup()

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

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

◆ epicsStrPrintEscaped()

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

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

Parameters
fpFile descriptor to print to
sString to print
nLength of string

◆ epicsStrnLen()

LIBCOM_API size_t epicsStrnLen ( const char s,
size_t  maxlen 
)

Implements strnlen from the C standard library.

◆ epicsStrGlobMatch()

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

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

Returns
1 if str matches the pattern, 0 if not.
Since
EPICS 3.14.7

◆ epicsStrnGlobMatch()

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

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

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

◆ epicsStrtok_r()

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

Implements strtok_r from the C standard library

◆ epicsStrHash()

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

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
strnull-terminated string
seedOptionally provide seed to combine multiple strings in a single hash. Otherwise set to 0.
Returns
Hash value for string

◆ epicsMemHash()

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

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
strbuffer
lengthsize of buffer
seedOptionally provide seed to combine multiple buffers in a single hash. Otherwise set to 0.
Returns
Hash value for buffer

◆ epicsStrSimilarity()

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

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

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

◆ dbTranslateEscape()

LIBCOM_API int dbTranslateEscape ( char s,
const char ct 
)
Deprecated:
dbTranslateEscape is deprecated, use epicsStrnRawFromEscaped() instead