26 #include <lal/XLALError.h>
27 #include <lal/StringVector.h>
28 #include <lal/LALMalloc.h>
29 #include <lal/LALString.h>
55 XLALPrintError (
"\n%s: NULL 'string' passed to append\n\n", __func__ );
62 XLALPrintError (
"%s: XLALCreateStringVector() failed!\n", __func__ );
72 XLALPrintError (
"%s: XLALRealloc(%d) failed!\n", __func__, oldlen + 1 );
78 if ( (ret->
data[oldlen] =
XLALCalloc(1, strlen(
string) + 1 )) == NULL ) {
79 XLALPrintError (
"%s: XLALCalloc(%zu) failed!\n", __func__, strlen(
string) + 1 );
83 strcpy ( ret->
data[oldlen],
string );
107 XLALPrintError (
"%s: invalid NULL input string 'str1'\n", __func__ );
118 len =
sizeof(ret->
data[0]);
122 len = strlen(str1)+1;
126 strcpy ( ret->
data[0], str1 );
132 while ( (next = va_arg(ap,
const CHAR *)) != NULL )
140 len = strlen(next)+1;
154 XLALPrintError (
"%s: failed to allocate '%zu' bytes\n", __func__, len );
176 if ( ! vector->
data )
194 for (
size_t i = 1; i < vect->
length; ++i) {
213 for ( i=0; i < vect->
length; i++ )
240 return strcmp ( * (
char *
const *) p1, * (
char *
const *) p2 );
255 if ( strings->
length > 0 ) {
256 len += strlen( strings->
data[0] );
257 for (
size_t i = 1; i < strings->
length; ++i ) {
258 len += strlen( sep ) + strlen( strings->
data[i] );
265 if ( strings->
length > 0 ) {
266 strcpy( s, strings->
data[0] );
267 for (
size_t i = 1; i < strings->
length; ++i ) {
269 strcat( s, strings->
data[i] );
296 while ( t != NULL ) {
314 if ( !strings || strings->
length == 0 ) {
315 XLALPrintError (
"%s: invalid empty or zero-length input 'strings'\n", __func__ );
335 const CHAR *blank_chars =
" \t\n";
338 const char *pos0 = start;
339 const char *pos1 = start + len - 1;
340 while ( (pos0 < pos1) && strchr ( blank_chars, (*pos0) ) ) {
345 while ( (pos1 >= pos0) && strchr ( blank_chars, (*pos1) ) ) {
349 UINT4 newlen = pos1 - pos0 + 1;
355 strncpy ( ret, pos0, newlen );
377 if ( !haystack || (haystack->
length == 0) )
381 for ( i=0; i < haystack->
length; i ++ )
382 if ( !strcmp ( needle, haystack->
data[i] ) )
static int StringCompare(const void *p1, const void *p2)
int XLALPrintError(const char *fmt,...)
char CHAR
One-byte signed integer, see Headers LAL(Atomic)Datatypes.h for more details.
uint32_t UINT4
Four-byte unsigned integer.
int32_t INT4
Four-byte signed integer.
#define XLALRealloc(p, n)
char * XLALStringDuplicate(const char *s)
Like strdup but uses LAL allocation routines (free with LALFree).
char * XLALStringToken(char **s, const char *delim, int empty)
Return the next token delimited by any character in 'delim' from the string 's', which is updated to ...
LALStringVector * XLALAppendString2Vector(LALStringVector *vect, const CHAR *string)
Append the given string to the string-vector (XLAL interface), return pointer to the resulting string...
char * XLALDeblankString(const CHAR *start, UINT4 len)
Copy (and allocate) string from 'start' with length 'len', removing all starting- and trailing blanks...
void XLALDestroyStringVector(LALStringVector *vect)
XLAL-interface: Free a string-vector ;)
LALStringVector * XLALParseStringVector(const char *string, const char *delim)
Parse 'string' into a string vector of tokens, delimited by the characters 'delim'.
LALStringVector * XLALCreateStringVector(const CHAR *str1,...)
Create a StringVector from the list of strings passed as arguments.
LALStringVector * XLALCreateEmptyStringVector(UINT4 length)
Create an empty string vector of the given length.
int XLALSortStringVector(LALStringVector *strings)
Sort string-vector alphabetically in place
INT4 XLALFindStringInVector(const char *needle, const LALStringVector *haystack)
Search for string 'needle' in string-vector 'haystack', return index to first matching vector element...
LALStringVector * XLALCopyStringVector(const LALStringVector *vect)
Create a copy of a string vector.
char * XLALConcatStringVector(const LALStringVector *strings, const char *sep)
Concatenate a string vector 'strings', separated by the string 'sep', into a single string.
#define XLAL_ERROR_NULL(...)
Macro to invoke a failure from a XLAL routine returning a pointer.
#define XLAL_ERROR(...)
Macro to invoke a failure from a XLAL routine returning an integer.
#define XLAL_CHECK_NULL(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns a pointe...
@ XLAL_ENOMEM
Memory allocation error.
@ XLAL_SUCCESS
Success return value (not an error number)
@ XLAL_EFAULT
Invalid pointer.
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
@ XLAL_EDOM
Input domain error.
@ XLAL_EINVAL
Invalid argument.
@ XLAL_EFAILED
Generic failure.
Vector of type CHAR*, ie 'strings', see DATATYPE-Vector types for more details.
UINT4 length
Number of elements in array.
CHAR ** data
Pointer to the data array.