24 #include <lal/LALStdlib.h>
25 #include <lal/LALString.h>
34 #pragma GCC diagnostic push
35 #pragma GCC diagnostic ignored "-Wpragmas"
37 #pragma GCC diagnostic ignored "-Wformat-truncation"
40 ret = vsnprintf(s, n, fmt, ap);
42 #pragma GCC diagnostic pop
56 curlen = s ? strlen(s) : 0;
57 newlen = curlen + strlen(append);
61 strcpy(s + curlen, append);
72 const size_t n = (s == NULL) ? 0 : strlen(s);
76 const int m = vsnprintf(tmp,
sizeof(tmp), fmt, ap);
79 const size_t l = (n +
m + 1) *
sizeof(*s);
109 srclen = strlen(
src);
110 if (!
dst || size < 1)
116 strncpy(
dst,
src, size - 1);
137 srclen = strlen(
src);
138 if (!
dst || size < 1)
144 dstlen = strlen(
dst);
145 strncat(
dst,
src, size - dstlen - 1);
146 return srclen + dstlen;
158 const char upper_chars[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
159 const char lower_chars[] =
"abcdefghijklmnopqrstuvwxyz";
161 for (
UINT4 i = 0; i < strlen(
string); i++) {
164 char *
p = strchr(upper_chars, c);
166 int offset =
p - upper_chars;
167 c = lower_chars[offset];
187 const char upper_chars[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
188 const char lower_chars[] =
"abcdefghijklmnopqrstuvwxyz";
190 for (
UINT4 i = 0; i < strlen(
string); i++) {
193 char *
p = strchr(lower_chars, c);
195 int offset =
p - lower_chars;
196 c = upper_chars[offset];
212 size_t n = ( (s1 == NULL) ? 0 : strlen(s1) ) + ( (s2 == NULL) ? 0 : strlen(s2) );
223 const char upper_chars[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
224 const char lower_chars[] =
"abcdefghijklmnopqrstuvwxyz";
231 c1 = (s1 == NULL) ? 0 : *s1++;
232 c2 = (s2 == NULL) ? 0 : *s2++;
236 char *
p = strchr(upper_chars,
c1);
238 int offset =
p - upper_chars;
239 c1 = lower_chars[offset];
245 char *
p = strchr(upper_chars,
c2);
247 int offset =
p - upper_chars;
248 c2 = lower_chars[offset];
253 if (
c1 ==
'\0' ||
c1 !=
c2) {
269 size_t haystack_length;
270 size_t needle_length = strlen(needle);
273 if (needle_length == 0)
274 return (
char *)(intptr_t)(haystack);
276 haystack_length = strlen(haystack);
277 while (needle_length <= haystack_length) {
279 return (
char *)(intptr_t)(haystack);
302 begin += strspn(begin, delim);
303 if (*begin ==
'\0') {
308 char *
end = strpbrk(begin, delim);
327 if (s == NULL ||
f == NULL) {
332 for (
char *
q = s; *
q !=
'\0'; ++
q) {
333 int r =
f( ((
int) *
q ), param );
347 int (*
f)(int) = (
int (*)(int)) param;
348 return f(c) ? -1 : c;
361 int (*
f)(int) = (
int (*)(int)) param;
362 return f(c) ? c : -1;
375 int *from_to = ((
int*) param);
376 return (c == from_to[0]) ? from_to[1] : c;
384 int from_to[2] = { from, to };
static int keep_chars(int c, void *param)
static int replace(int c, void *param)
static int strip_chars(int c, void *param)
char * XLALStringAppendFmt(char *s, const char *fmt,...)
Append the formatted string 'fmt' to the string 's', which is reallocated with XLALRealloc() to the r...
int XLALStringPrint(char *s, size_t n, const char *fmt,...)
Like snprintf but doesn't print format truncation warnings with GCC.
static double f(double theta, double y, double xi)
uint32_t UINT4
Four-byte unsigned integer.
#define XLALRealloc(p, n)
char * XLALStringStripChars(char *s, int(*f)(int))
Return the string 's' with all characters for which 'f()' is true removed.
int XLALStringToLowerCase(char *string)
Turn a string in-place into lowercase without using locale-dependent functions.
char * XLALStringReplaceChar(char *s, const int from, const int to)
Return the string 's' with all characters 'from' replaced with 'to'.
int XLALStringCaseCompare(const char *s1, const char *s2)
Compare two strings, ignoring case and without using locale-dependent functions.
char * XLALStringTranslate(char *s, int(*f)(int, void *), void *param)
Return the string 's' applying the function 'f(c, param)' to all characters 'c'.
size_t XLALStringCopy(char *dst, const char *src, size_t size)
Copy sources string src to destination string dst.
char * XLALStringDuplicate(const char *s)
Like strdup but uses LAL allocation routines (free with LALFree).
char * XLALStringCaseSubstring(const char *haystack, const char *needle)
Locates substring needle in string haystack, ignoring case and without using locale-dependent functio...
size_t XLALStringConcatenate(char *dst, const char *src, size_t size)
Concatenate sources string src to the end of destination string dst.
char * XLALStringKeepChars(char *s, int(*f)(int))
Return the string 's' with all characters for which 'f()' is false removed.
char * XLALStringAppend(char *s, const char *append)
Like strcat but dynamically reallocates string with LALRealloc.
int XLALStringNCaseCompare(const char *s1, const char *s2, size_t n)
Compare the first N characters of two strings, ignoring case and without using locale-dependent funct...
int XLALStringToUpperCase(char *string)
Turn a string in-place into uppercase without using locale-dependent functions.
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 ...
#define XLAL_ERROR_NULL(...)
Macro to invoke a failure from a XLAL routine returning a pointer.
#define XLAL_CHECK(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns an integ...
#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_EINVAL
Invalid argument.