stringlist.h File Reference
`#include <gwenhywfar/gwenhywfarapi.h>`
`#include <gwenhywfar/buffer.h>`

Go to the source code of this file.

## Typedefs

typedef struct GWEN_STRINGLISTSTRUCT | GWEN_STRINGLIST
typedef struct GWEN_STRINGLISTENTRYSTRUCT | GWEN_STRINGLISTENTRY

## Enumerations

enum | GWEN_STRINGLIST_SORT_MODE { GWEN_StringList_SortModeNoCase =0 , GWEN_StringList_SortModeCase , GWEN_StringList_SortModeInt }

## Functions

GWENHYWFAR_API void | GWEN_StringList_AppendEntry (GWEN_STRINGLIST *sl, GWEN_STRINGLISTENTRY *se)
GWENHYWFAR_API int | GWEN_StringList_AppendString (GWEN_STRINGLIST *sl, const char *s, int take, int checkDouble)
GWENHYWFAR_API void | GWEN_StringList_AppendStringList (GWEN_STRINGLIST *slDest, const GWEN_STRINGLIST *slSource, int checkDouble)
GWENHYWFAR_API void | GWEN_StringList_Clear (GWEN_STRINGLIST *sl)
GWENHYWFAR_API unsigned int | GWEN_StringList_Count (const GWEN_STRINGLIST *sl)
GWENHYWFAR_API GWEN_STRINGLIST * | GWEN_StringList_dup (const GWEN_STRINGLIST *sl)
GWENHYWFAR_API GWEN_STRINGLISTENTRY * | GWEN_StringList_FindStringEntry (const GWEN_STRINGLIST *sl, const char *s)
GWENHYWFAR_API GWEN_STRINGLISTENTRY * | GWEN_StringList_FirstEntry (const GWEN_STRINGLIST *sl)
GWENHYWFAR_API const char * | GWEN_StringList_FirstString (const GWEN_STRINGLIST *l)
GWENHYWFAR_API void * | GWEN_StringList_ForEach (const GWEN_STRINGLIST *l, void *(*func)(const char *s, void *u), void *user_data)
GWENHYWFAR_API void | GWEN_StringList_free (GWEN_STRINGLIST *sl)
GWENHYWFAR_API GWEN_STRINGLIST * | GWEN_StringList_fromString (const char *str, const char *delimiters, int checkDouble)
GWENHYWFAR_API GWEN_STRINGLIST * | GWEN_StringList_fromString2 (const char *str, const char *delimiters, int checkDouble, uint32_t flags)
GWENHYWFAR_API GWEN_STRINGLIST * | GWEN_StringList_fromTabString (const char *s, int checkDup)
GWENHYWFAR_API int | GWEN_StringList_GetStringPos (const GWEN_STRINGLIST *sl, const char *s)
GWENHYWFAR_API int | GWEN_StringList_HasString (const GWEN_STRINGLIST *sl, const char *s)
GWENHYWFAR_API int | GWEN_StringList_InsertString (GWEN_STRINGLIST *sl, const char *s, int take, int checkDouble)
GWENHYWFAR_API GWEN_STRINGLIST * | GWEN_StringList_new (void)
GWENHYWFAR_API void | GWEN_StringList_RemoveCommonFirstEntries (GWEN_STRINGLIST *sl1, GWEN_STRINGLIST *sl2)
GWENHYWFAR_API void | GWEN_StringList_RemoveEntry (GWEN_STRINGLIST *sl, GWEN_STRINGLISTENTRY *se)
GWENHYWFAR_API void | GWEN_StringList_RemoveFirstString (GWEN_STRINGLIST *sl)
GWENHYWFAR_API int | GWEN_StringList_RemoveString (GWEN_STRINGLIST *sl, const char *s)
GWENHYWFAR_API void | GWEN_StringList_SetIgnoreRefCount (GWEN_STRINGLIST *sl, int i)
GWENHYWFAR_API void | GWEN_StringList_SetSenseCase (GWEN_STRINGLIST *sl, int i)
GWENHYWFAR_API void | GWEN_StringList_Sort (GWEN_STRINGLIST *l, int ascending, GWEN_STRINGLIST_SORT_MODE sortMode)
GWENHYWFAR_API int | GWEN_StringList_StringAsIntAt (const GWEN_STRINGLIST *l, int idx, int defaultValue)
GWENHYWFAR_API const char * | GWEN_StringList_StringAt (const GWEN_STRINGLIST *l, int idx)
GWENHYWFAR_API int | GWEN_StringList_toBuffer (const GWEN_STRINGLIST *sl, const char *delimiter, GWEN_BUFFER *outBuffer)
GWENHYWFAR_API const char * | GWEN_StringListEntry_Data (const GWEN_STRINGLISTENTRY *se)
GWENHYWFAR_API void | GWEN_StringListEntry_free (GWEN_STRINGLISTENTRY *sl)
GWENHYWFAR_API GWEN_STRINGLISTENTRY * | GWEN_StringListEntry_new (const char *s, int take)
GWENHYWFAR_API GWEN_STRINGLISTENTRY * | GWEN_StringListEntry_Next (const GWEN_STRINGLISTENTRY *se)
GWENHYWFAR_API void | GWEN_StringListEntry_ReplaceString (GWEN_STRINGLISTENTRY *e, const char *s, int take)
GWENHYWFAR_API void | GWEN_StringListEntry_SetData (GWEN_STRINGLISTENTRY *se, const char *s)

## Typedef Documentation

## GWEN_STRINGLIST

typedef struct GWEN_STRINGLISTSTRUCT GWEN_STRINGLIST

Definition at line 56 of file stringlist.h.

## GWEN_STRINGLISTENTRY

typedef struct GWEN_STRINGLISTENTRYSTRUCT GWEN_STRINGLISTENTRY

Definition at line 53 of file stringlist.h.

## Enumeration Type Documentation

## GWEN_STRINGLIST_SORT_MODE

enum GWEN_STRINGLIST_SORT_MODE

Enumerator
GWEN_StringList_SortModeNoCase | case-insensitive, i.e. using strcasecmp(3).
GWEN_StringList_SortModeCase | case-sensitive, i.e. using strcmp(3).
GWEN_StringList_SortModeInt | handle string list entries as integers (-> correct sorting of ASCII coded values like "10", "1")

Definition at line 41 of file stringlist.h.

## Function Documentation

## GWEN_StringList_AppendEntry()

GWENHYWFAR_API void GWEN_StringList_AppendEntry | ( | GWEN_STRINGLIST * | sl,
|  | GWEN_STRINGLISTENTRY * | se )

References GWENHYWFAR_API.

## GWEN_StringList_AppendString()

GWENHYWFAR_API int GWEN_StringList_AppendString | ( | GWEN_STRINGLIST * | sl,
|  | const char * | s,
|  | int | take,
|  | int | checkDouble )

Appends a string.

Returns
  0 if not appended, !=0 if appended

Parameters

  take | if true then the StringList takes over ownership of the string
  checkDouble | if true the the string will only be appended if it does not already exist

References GWENHYWFAR_API.

## GWEN_StringList_AppendStringList()

GWENHYWFAR_API void GWEN_StringList_AppendStringList | ( | GWEN_STRINGLIST * | slDest,
|  | const GWEN_STRINGLIST * | slSource,
|  | int | checkDouble )

Append duplicates of the entries in the source list to the destination list. The source list is not modified.

References GWENHYWFAR_API.

## GWEN_StringList_Clear()

GWENHYWFAR_API void GWEN_StringList_Clear | ( | GWEN_STRINGLIST * | sl | ) |

References GWENHYWFAR_API.

## GWEN_StringList_Count()

GWENHYWFAR_API unsigned int GWEN_StringList_Count | ( | const GWEN_STRINGLIST * | sl | ) |

Returns the number of elements in this list.

## GWEN_StringList_dup()

GWENHYWFAR_API GWEN_STRINGLIST * GWEN_StringList_dup | ( | const GWEN_STRINGLIST * | sl | ) |

## GWEN_StringList_FindStringEntry()

GWENHYWFAR_API GWEN_STRINGLISTENTRY * GWEN_StringList_FindStringEntry | ( | const GWEN_STRINGLIST * | sl,
|  | const char * | s )

Returns the first stringlist entry which contains the given string

Returns
  string list entry containing the given string, NULL otherwise

References GWENHYWFAR_API.

## GWEN_StringList_FirstEntry()

GWENHYWFAR_API GWEN_STRINGLISTENTRY * GWEN_StringList_FirstEntry | ( | const GWEN_STRINGLIST * | sl | ) |

References GWENHYWFAR_API.

## GWEN_StringList_FirstString()

GWENHYWFAR_API const char * GWEN_StringList_FirstString | ( | const GWEN_STRINGLIST * | l | ) |

Returns the first string in this list.

References GWENHYWFAR_API.

## GWEN_StringList_ForEach()

GWENHYWFAR_API void * GWEN_StringList_ForEach | ( | const GWEN_STRINGLIST * | l,
|  | void *(* | func )(const char *s, void *u),
|  | void * | user_data )

Traverses the list, calling the callback function 'func' on each list element. Traversal will stop when 'func' returns a non-NULL value, and the routine will return with that value. Otherwise the routine will return NULL.

Parameters

  l | The list to traverse.
  func | The function to be called with each list element.
  user_data | A pointer passed on to the function 'func'.

Returns
  The non-NULL pointer returned by 'func' as soon as it returns one. Otherwise (i.e. 'func' always returns NULL) returns NULL.

References GWENHYWFAR_API.

## GWEN_StringList_free()

GWENHYWFAR_API void GWEN_StringList_free | ( | GWEN_STRINGLIST * | sl | ) |

References GWENHYWFAR_API.

## GWEN_StringList_fromString()

GWENHYWFAR_API GWEN_STRINGLIST * GWEN_StringList_fromString | ( | const char * | str,
|  | const char * | delimiters,
|  | int | checkDouble )

References GWENHYWFAR_API.

## GWEN_StringList_fromString2()

GWENHYWFAR_API GWEN_STRINGLIST * GWEN_StringList_fromString2 | ( | const char * | str,
|  | const char * | delimiters,
|  | int | checkDouble,
|  | uint32_t | flags )

Create a stringlist from a given complex string.

In addition to GWEN_StringList_fromString() this version allows to modify the behavior of the function by adding some flags (see GWEN_TEXT_FLAGS_CHECK_BACKSLASH and following). Typically used flags are:

- GWEN_TEXT_FLAGS_DEL_QUOTES (delete quotes around single words)
- GWEN_TEXT_FLAGS_CHECK_BACKSLASH (handle backslashes as escape characters)

Returns
  stringlist object (contains at least one entry) or NULL if no entries/empty string

Parameters

  str | string to dissect
  delimiters | word delimiters
  checkDouble | if !=0 only add unique strings to the resulting list
  flags | (see GWEN_TEXT_FLAGS_DEL_QUOTES and others)

References GWENHYWFAR_API.

## GWEN_StringList_fromTabString()

GWENHYWFAR_API GWEN_STRINGLIST * GWEN_StringList_fromTabString | ( | const char * | s,
|  | int | checkDup )

References GWENHYWFAR_API.

## GWEN_StringList_GetStringPos()

GWENHYWFAR_API int GWEN_StringList_GetStringPos | ( | const GWEN_STRINGLIST * | sl,
|  | const char * | s )

Returns the position of the given string within the stringlist.

Returns
  position, -1 if not found

References GWENHYWFAR_API.

## GWEN_StringList_HasString()

GWENHYWFAR_API int GWEN_StringList_HasString | ( | const GWEN_STRINGLIST * | sl,
|  | const char * | s )

Checks whether the given string already exists within in the string list.

Returns
  !=0 if found, 0 otherwise

References GWENHYWFAR_API.

## GWEN_StringList_InsertString()

GWENHYWFAR_API int GWEN_StringList_InsertString | ( | GWEN_STRINGLIST * | sl,
|  | const char * | s,
|  | int | take,
|  | int | checkDouble )

Inserts a string.

Returns
  0 if not inserted, !=0 if inserted

Parameters

  take | if true then the StringList takes over ownership of the string
  checkDouble | if true the the string will only be appended if it does not already exist

References GWENHYWFAR_API.

## GWEN_StringList_new()

GWENHYWFAR_API GWEN_STRINGLIST * GWEN_StringList_new | ( | void |  | ) |

References GWENHYWFAR_API.

## GWEN_StringList_RemoveCommonFirstEntries()

GWENHYWFAR_API void GWEN_StringList_RemoveCommonFirstEntries | ( | GWEN_STRINGLIST * | sl1,
|  | GWEN_STRINGLIST * | sl2 )

Remove first equal entries from both lists.

If stringlist 1 contains "A", "B", "C", "D" and stringlist 2 contains "A", "B", "X" then after this function the lists are changed to this: stringlist 1 contains "C", "D" stringlist 2 contains "X"

## GWEN_StringList_RemoveEntry()

GWENHYWFAR_API void GWEN_StringList_RemoveEntry | ( | GWEN_STRINGLIST * | sl,
|  | GWEN_STRINGLISTENTRY * | se )

References GWENHYWFAR_API.

## GWEN_StringList_RemoveFirstString()

GWENHYWFAR_API void GWEN_StringList_RemoveFirstString | ( | GWEN_STRINGLIST * | sl | ) |

Removes the first string from the stringlist (if any).

References GWENHYWFAR_API.

## GWEN_StringList_RemoveString()

GWENHYWFAR_API int GWEN_StringList_RemoveString | ( | GWEN_STRINGLIST * | sl,
|  | const char * | s )

Removes a given string from the stringlist.

Returns
  0 if not found, !=0 if found and removed

References GWENHYWFAR_API.

## GWEN_StringList_SetIgnoreRefCount()

GWENHYWFAR_API void GWEN_StringList_SetIgnoreRefCount | ( | GWEN_STRINGLIST * | sl,
|  | int | i )

Normally this group of functions ignores reference counters on stringlist entries when removing a string via GWEN_StringList_RemoveString. You can change this behaviour here.

Parameters

  sl | string list
  i | if 0 then reference counters are honoured

## GWEN_StringList_SetSenseCase()

GWENHYWFAR_API void GWEN_StringList_SetSenseCase | ( | GWEN_STRINGLIST * | sl,
|  | int | i )

Normally this group of functions ignores cases when comparing two strings. You can change this behaviour here.

Parameters

  sl | string list
  i | if 0 then cases are ignored

References GWENHYWFAR_API.

## GWEN_StringList_Sort()

GWENHYWFAR_API void GWEN_StringList_Sort | ( | GWEN_STRINGLIST * | l,
|  | int | ascending,
|  | GWEN_STRINGLIST_SORT_MODE | sortMode )

Sorts this list. Internally this uses qsort(3), so the sorting should be reasonably fast even for large lists.

Parameters

  l | The list to sort.
  ascending | If non-zero, the list is sorted ascending, i.e. smallest string first, according to strcmp(3) rules. If zero, the list is sorted descending.
  sortMode | See GWEN_StringList_SortModeNoCase and following

References GWENHYWFAR_API.

## GWEN_StringList_StringAsIntAt()

GWENHYWFAR_API int GWEN_StringList_StringAsIntAt | ( | const GWEN_STRINGLIST * | l,
|  | int | idx,
|  | int | defaultValue )

References GWENHYWFAR_API.

## GWEN_StringList_StringAt()

GWENHYWFAR_API const char * GWEN_StringList_StringAt | ( | const GWEN_STRINGLIST * | l,
|  | int | idx )

References GWENHYWFAR_API.

## GWEN_StringList_toBuffer()

GWENHYWFAR_API int GWEN_StringList_toBuffer | ( | const GWEN_STRINGLIST * | sl,
|  | const char * | delimiter,
|  | GWEN_BUFFER * | outBuffer )

References GWENHYWFAR_API.

## GWEN_StringListEntry_Data()

GWENHYWFAR_API const char * GWEN_StringListEntry_Data | ( | const GWEN_STRINGLISTENTRY * | se | ) |

References GWENHYWFAR_API.

## GWEN_StringListEntry_free()

GWENHYWFAR_API void GWEN_StringListEntry_free | ( | GWEN_STRINGLISTENTRY * | sl | ) |

References GWENHYWFAR_API.

## GWEN_StringListEntry_new()

GWENHYWFAR_API GWEN_STRINGLISTENTRY * GWEN_StringListEntry_new | ( | const char * | s,
|  | int | take )

References GWENHYWFAR_API.

## GWEN_StringListEntry_Next()

GWENHYWFAR_API GWEN_STRINGLISTENTRY * GWEN_StringListEntry_Next | ( | const GWEN_STRINGLISTENTRY * | se | ) |

References GWENHYWFAR_API.

## GWEN_StringListEntry_ReplaceString()

GWENHYWFAR_API void GWEN_StringListEntry_ReplaceString | ( | GWEN_STRINGLISTENTRY * | e,
|  | const char * | s,
|  | int | take )

References GWENHYWFAR_API.

## GWEN_StringListEntry_SetData()

GWENHYWFAR_API void GWEN_StringListEntry_SetData | ( | GWEN_STRINGLISTENTRY * | se,
|  | const char * | s )

References GWENHYWFAR_API.