40 size_t len, fromlen, tolen;
43 fromlen = strlen(fromlist);
44 tolen = strlen(tolist);
46 for (i=j=0; i<
len; i++) {
47 for (k=0; k<fromlen; k++) {
48 if (str[i] == fromlist[k]) {
98 int j, rc, flags, global, nmatches;
106 if (strchr(options,
'i') !=
NULL)
108 global = (strchr(options,
'g') !=
NULL ? 1 : 0);
112 if ((rc =
regcomp(&re, pattern, flags)) != 0) {
114 *new_str = gk_cmalloc(len,
"gk_strstr_replace: new_str");
123 *new_str = gk_cmalloc(nlen+1,
"gk_strstr_replace: new_str");
127 rlen = strlen(replacement);
131 rc =
regexec(&re, str+offset, 10, matches, 0);
135 *new_str =
gk_strdup(
"regexec ran out of memory.");
140 if (nlen-noffset < len-offset) {
141 nlen += (len-
offset) - (nlen-noffset);
142 *new_str = (
char *)
gk_realloc(*new_str, (nlen+1)*
sizeof(char),
"gk_strstr_replace: new_str");
144 strcpy(*new_str+noffset, str+offset);
152 if (matches[0].rm_so > 0) {
153 if (nlen-noffset < matches[0].rm_so) {
154 nlen += matches[0].
rm_so - (nlen-noffset);
155 *new_str = (
char *)
gk_realloc(*new_str, (nlen+1)*
sizeof(char),
"gk_strstr_replace: new_str");
157 strncpy(*new_str+noffset, str+offset, matches[0].rm_so);
158 noffset += matches[0].
rm_so;
162 for (i=0; i<rlen; i++) {
163 switch (replacement[i]) {
166 if (nlen-noffset < 1) {
168 *new_str = (
char *)
gk_realloc(*new_str, (nlen+1)*
sizeof(char),
"gk_strstr_replace: new_str");
170 *new_str[noffset++] = replacement[++
i];
174 *new_str =
gk_strdup(
"Error in replacement string. Missing character following '\'.");
182 j = (
int)(replacement[++i] -
'0');
183 if (j < 0 || j > 9) {
185 *new_str =
gk_strdup(
"Error in captured subexpression specification.");
190 if (nlen-noffset < matches[j].rm_eo-matches[j].rm_so) {
192 *new_str = (
char *)
gk_realloc(*new_str, (nlen+1)*
sizeof(char),
"gk_strstr_replace: new_str");
195 strncpy(*new_str+noffset, str+offset+matches[j].rm_so, matches[j].rm_eo);
200 *new_str =
gk_strdup(
"Error in replacement string. Missing subexpression number folloing '$'.");
207 if (nlen-noffset < 1) {
209 *new_str = (
char *)
gk_realloc(*new_str, (nlen+1)*
sizeof(char),
"gk_strstr_replace: new_str");
211 (*new_str)[noffset++] = replacement[
i];
216 offset += matches[0].
rm_eo;
220 if (nlen-noffset < len-offset) {
221 nlen += (len-
offset) - (nlen-noffset);
222 *new_str = (
char *)
gk_realloc(*new_str, (nlen+1)*
sizeof(char),
"gk_strstr_replace: new_str");
224 strcpy(*new_str+noffset, str+offset);
230 (*new_str)[noffset] =
'\0';
259 len = strlen(rmlist);
261 for (i=strlen(str)-1; i>=0; i--) {
262 for (j=0; j<
len; j++) {
263 if (str[i] == rmlist[j])
296 len = strlen(rmlist);
298 for (i=0; str[
i]; i++) {
299 for (j=0; j<
len; j++) {
300 if (str[i] == rmlist[j])
308 for (j=0; str[
i]; i++, j++)
332 for (i=0; str[
i]!=
'\0'; str[
i]=toupper(str[i]), i++);
352 for (i=0; str[
i]!=
'\0'; str[
i]=tolower(str[i]), i++);
377 if (orgstr !=
NULL) {
378 len = strlen(orgstr)+1;
379 str =
gk_malloc(len*
sizeof(
char),
"gk_strdup: str");
409 if (strlen(s1) != strlen(s2))
412 while (s1[i] !=
'\0') {
413 if (tolower(s1[i]) != tolower(s2[i]))
435 int i1 = strlen(s1)-1;
436 int i2 = strlen(s2)-1;
438 while ((i1 >= 0) && (i2 >= 0)) {
439 if (s1[i1] != s2[i2])
440 return (s1[i1] - s2[i2]);
472 static char datestr[128];
475 tm = localtime(&time);
477 if (strftime(datestr, 128,
"%m/%d/%Y %H:%M:%S", tm) == 0)
485 #if !defined(WIN32) && !defined(__MINGW32__) 504 memset(&time,
'\0',
sizeof(time));
506 if (strptime(str,
"%m/%d/%Y %H:%M:%S", &time) ==
NULL)
509 rtime = mktime(&time);
510 return (rtime < 0 ? 0 : rtime);
523 for (i=0; strmap[
i].
name; i++) {
void regfree(regex_t *__preg)
const gtsam::Symbol key('X', 0)
int gk_strrcmp(char *s1, char *s2)
Compare two strings in revere order.
char * gk_strdup(char *orgstr)
Duplicates a string.
time_t gk_str2time(char *str)
Converts a date/time string into its equivalent time_t value.
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate offset
size_t regerror(int __errcode, const regex_t *__restrict __preg, char *__restrict __errbuf, size_t __errbuf_size)
char * gk_strhprune(char *str, char *rmlist)
Prunes characters from the beginning of the string.
char * gk_strchr_replace(char *str, char *fromlist, char *tolist)
Replaces certain characters in a string.
char * gk_strtoupper(char *str)
Converts a string to upper case.
char * gk_strtolower(char *str)
Converts a string to lower case.
void * gk_realloc(void *oldptr, size_t nbytes, char *msg)
int gk_strstr_replace(char *str, char *pattern, char *replacement, char *options, char **new_str)
Regex-based search-and-replace function.
int gk_strcasecmp(char *s1, char *s2)
Case insensitive string comparison.
int regexec(const regex_t *__restrict __preg, const char *__restrict __string, size_t __nmatch, regmatch_t __pmatch[__restrict_arr], int __eflags)
int regcomp(regex_t *__restrict __preg, const char *__restrict __pattern, int __cflags)
int gk_GetStringID(gk_StringMap_t *strmap, char *key)
void * gk_malloc(size_t nbytes, char *msg)
void gk_free(void **ptr1,...)
char * gk_strtprune(char *str, char *rmlist)
Prunes characters from the end of the string.
char * gk_time2str(time_t time)
Converts a time_t time into a string.
Annotation for function names.
size_t len(handle h)
Get the length of a Python object.