CNDP  22.08.0
cne_strings.h File Reference
#include <stdio.h>
#include <ctype.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <bsd/bsd.h>
#include <errno.h>
#include <bsd/string.h>
#include <sys/socket.h>
#include <cne_common.h>

Go to the source code of this file.

Enumerations

enum  { STR_MAX_ARGVS = 64 , STR_TOKEN_SIZE = 128 }
 

Functions

static __inline__ char * strtrimset (char *str, const char *set)
 
static __inline__ char * strtrim_quotes (char *str)
 
static __inline__ char * strtrim (char *str)
 
static __inline__ int cne_strtok (char *str, const char *delim, char *entries[], int maxtokens)
 
static __inline__ int cne_strqtok (char *str, const char *delim, char *argv[], int maxtokens)
 
static __inline__ char * cne_strtolower (char *str)
 
static __inline__ char * cne_strtoupper (char *str)
 
static __inline__ int cne_stropt (const char *list, char *str, const char *delim)
 
static __inline__ char * cne_strdupf (char *str, char *newstr)
 
static __inline__ int cne_strcnt (char *s, char c)
 
static __inline__ int mask_size (uint32_t mask)
 

Detailed Description

String-related utility functions

Definition in file cne_strings.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
STR_MAX_ARGVS 

Max number of args to support

STR_TOKEN_SIZE 

Token max size

Definition at line 33 of file cne_strings.h.

Function Documentation

◆ strtrimset()

static __inline__ char* strtrimset ( char *  str,
const char *  set 
)
static

Trim a set of characters like "[]" or "{}" from the start and end of string.

Parameters
strA null terminated string to be trimmed.
setThe set string is a set of two character values to be removed from the str. Removes only one set at a time, if you have more then one set to remove then you must call the routine for each set. The set string must be two characters and can be any characters you want to call a set.
Returns
Pointer to the trimmed string or NULL on error

Definition at line 53 of file cne_strings.h.

◆ strtrim_quotes()

static __inline__ char* strtrim_quotes ( char *  str)
static

Remove quotes from around a string helper routine.

Parameters
strString to remove the quote marks or tick marks from around a string
Returns
If quote or tick marks are removed then return &str[1] or return str.

Definition at line 83 of file cne_strings.h.

◆ strtrim()

static __inline__ char* strtrim ( char *  str)
static

Remove leading and trailing white space from a string.

Parameters
strString to be trimmed, must be null terminated
Returns
pointer to the trimmed string or NULL if str is Null or if string is empty then return pointer to str

Definition at line 104 of file cne_strings.h.

◆ cne_strtok()

static __inline__ int cne_strtok ( char *  str,
const char *  delim,
char *  entries[],
int  maxtokens 
)
static

Parse a string into a argc/argv list using a set of delimiters, but does not handle quoted strings within the string being parsed.

Parameters
strString to be tokenized and will be modified, must be null terminated
delimA null terminated list of delimiters
entriesA pointer to an array to place the token pointers
maxtokensMax number of tokens to be placed in entries
Returns
The number of tokens in the entries array.

Definition at line 142 of file cne_strings.h.

◆ cne_strqtok()

static __inline__ int cne_strqtok ( char *  str,
const char *  delim,
char *  argv[],
int  maxtokens 
)
static

Parse a string into a argv list using a set of delimiters, but does handle quoted strings within the string being parsed

Parameters
strString to be tokenized and will be modified, null terminated
delimA null terminated list of delimiters
argvA pointer to an array to place the token pointers
maxtokensMax number of tokens to be placed in entries
Returns
The number of tokens in the entries array.

Definition at line 176 of file cne_strings.h.

◆ cne_strtolower()

static __inline__ char* cne_strtolower ( char *  str)
static

Convert characters in str to lowercase.

Parameters
strString to convert to lowercase
Returns
For success lower case string, NULL on error

Definition at line 272 of file cne_strings.h.

◆ cne_strtoupper()

static __inline__ char* cne_strtoupper ( char *  str)
static

Convert characters in str to uppercase.

Parameters
strString to convert to uppercase
Returns
For success upper case string, NULL on error

Definition at line 293 of file cne_strings.h.

◆ cne_stropt()

static __inline__ int cne_stropt ( const char *  list,
char *  str,
const char *  delim 
)
static

Parse a string list looking for str using delim character.

Parameters
listA string list of options with delim character between them.
strString to search for in list
delimA character string to use as a delim values
Returns
The index in the list of option strings, -1 if not found

Definition at line 317 of file cne_strings.h.

◆ cne_strdupf()

static __inline__ char* cne_strdupf ( char *  str,
char *  newstr 
)
static

The function is a wrapper around strdup() and will free the previous string if the pointer is present.

Definition at line 352 of file cne_strings.h.

◆ cne_strcnt()

static __inline__ int cne_strcnt ( char *  s,
char  c 
)
static

Count the number of c characters in a string s

Parameters
sNull terminated string to search
ccharacter to count
Returns
Number of times the character is in string.

Definition at line 370 of file cne_strings.h.

◆ mask_size()

static __inline__ int mask_size ( uint32_t  mask)
static

Return the number of contiguous bits in a 32bit mask variable.

The mask can not contain gaps between bits, must be contiguous from MSB.

Parameters
maskThe mask variable to determine the number of bits.
Returns
The number of contiguous bit in the mask.

Definition at line 388 of file cne_strings.h.