Teonet library  0.4.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
string_arr.c File Reference
#include <stdlib.h>
#include <string.h>
#include "string_arr.h"
#include "teo_memory.h"

Macros

#define MAX_STRING_LEN   1024
 
#define arr_realloc(_len_)
 
#define arr_inc_size(_pos_)
 

Functions

ksnet_stringArr ksnet_stringArrCreate ()
 Create empty c string array. More...
 
ksnet_stringArr ksnet_stringArrAdd (ksnet_stringArr *arr, const char *str)
 Add c string to string array. More...
 
int ksnet_stringArrLength (ksnet_stringArr arr)
 Get length of string array. More...
 
int ksnet_stringArrMoveTo (ksnet_stringArr arr, unsigned int fromIdx, unsigned toIdx)
 Move array item from one position to another. More...
 
ksnet_stringArr ksnet_stringArrFree (ksnet_stringArr *arr)
 Free string array. More...
 
ksnet_stringArr ksnet_stringArrSplit (const char *string, const char *separators, int with_empty, int max_parts)
 Split string by separators into words. More...
 
char * ksnet_stringArrCombine (ksnet_stringArr arr, const char *separator)
 Combine string array to string. More...
 

Macro Definition Documentation

#define arr_inc_size (   _pos_)
Value:
if(_pos_ >= result_len) { \
arr_realloc(result_len + MAX_STRING_LEN); \
}
#define arr_realloc(_len_)
#define MAX_STRING_LEN

Referenced by ksnet_stringArrSplit().

#define arr_realloc (   _len_)
Value:
result_len = _len_; \
result = teo_realloc(result, sizeof(char*) * result_len)
void * teo_realloc(void *ptr, size_t size)
Definition: teo_memory.c:64
int result
Definition: grammar-filter.c:79

Referenced by ksnet_stringArrSplit().

#define MAX_STRING_LEN   1024

Referenced by ksnet_stringArrSplit().

Function Documentation

ksnet_stringArr ksnet_stringArrAdd ( ksnet_stringArr arr,
const char *  str 
)

Add c string to string array.

Parameters
str
arr
Returns

References ksnet_stringArrLength(), teo_malloc(), and teo_realloc().

Referenced by teo::StringArray::add(), getIPs(), and ksnTDBkeyList().

char* ksnet_stringArrCombine ( ksnet_stringArr  arr,
const char *  separator 
)

Combine string array to string.

Parameters
arrString array
separator
Returns
Combined string, should be free after use

References malloc().

Referenced by test_3_5().

ksnet_stringArr ksnet_stringArrCreate ( )

Create empty c string array.

Returns

Referenced by getIPs(), and test_3_5().

ksnet_stringArr ksnet_stringArrFree ( ksnet_stringArr arr)

Free string array.

Parameters
arr

References free().

Referenced by createCmdConnectRPacketUdp(), event_cb(), open_local_port(), and test_3_5().

int ksnet_stringArrLength ( ksnet_stringArr  arr)

Get length of string array.

Parameters
arr
Returns

Referenced by createCmdConnectRPacketUdp(), ksnet_stringArrAdd(), ksnet_stringArrMoveTo(), open_local_port(), teo::StringArray::size(), and test_3_5().

int ksnet_stringArrMoveTo ( ksnet_stringArr  arr,
unsigned int  fromIdx,
unsigned  toIdx 
)

Move array item from one position to another.

Parameters
arr
fromIdx
toIdx
Returns
True at success, null at error

References ksnet_stringArrLength().

Referenced by teo::StringArray::move().

ksnet_stringArr ksnet_stringArrSplit ( const char *  string,
const char *  separators,
int  with_empty,
int  max_parts 
)

Split string by separators into words.

Parameters
string
separators
with_empty
max_partsNumber of parts. if max_parts == 0 then there isn't parts limit
Returns
String array. Should be free with free_string_array after using

References arr_inc_size, arr_realloc, malloc(), MAX_STRING_LEN, and result.

Referenced by ksnetEvMgrRestart().