summaryrefslogtreecommitdiff
path: root/src/common/extstr.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2014-07-10 14:47:37 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2014-07-10 14:47:37 (GMT)
commitdb863244b804cbf4c06399f7c6f8241d91c9ee9b (patch)
treeda7cc911b0f10c5122536271235ab68f2202804a /src/common/extstr.c
parente8aa314462196cc9e8461ae23eb13f8bffcc983f (diff)
Fully rewritten the core configuration system.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@381 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/common/extstr.c')
-rw-r--r--src/common/extstr.c24
1 files changed, 7 insertions, 17 deletions
diff --git a/src/common/extstr.c b/src/common/extstr.c
index caffbcd..851401c 100644
--- a/src/common/extstr.c
+++ b/src/common/extstr.c
@@ -174,18 +174,15 @@ char *strrpl(char *haystack, const char *needle1, const char *needle2)
size_t inlen; /* Taille en entrée */
size_t len1; /* Taille de l'aiguille n°1 */
size_t len2; /* Taille de l'aiguille n°2 */
- regex_t preg; /* Expression régulière */
- size_t curpos; /* Point de recherche */
- regmatch_t pmatch; /* Résultats remontés */
+ char *found; /* Position d'une trouvaille */
inlen = strlen(haystack) + 1;
len1 = strlen(needle1);
len2 = strlen(needle2);
- /* On considère que la compilation est toujours bonne... */
- regcomp(&preg, needle1, REG_EXTENDED | REG_ICASE);
-
- for (curpos = 0; regexec(&preg, &haystack[curpos], 1, &pmatch, 0) != REG_NOMATCH; )
+ for (found = strstr(haystack, needle1);
+ found != NULL;
+ found = strstr(haystack, needle1))
{
if (len1 != len2)
{
@@ -198,23 +195,16 @@ char *strrpl(char *haystack, const char *needle1, const char *needle2)
haystack = (char *)realloc(haystack, inlen * sizeof(char *));
if (len2 > len1)
- memmove(&haystack[curpos + pmatch.rm_eo + len2 - len1], &haystack[curpos + pmatch.rm_eo],
- inlen - (len2 - len1) - curpos - pmatch.rm_eo);
-
+ memmove(found + len2, found + len1, inlen - len1 - (found - haystack));
else
- memmove(&haystack[curpos + pmatch.rm_eo + len1 - len2], &haystack[curpos + pmatch.rm_eo],
- inlen - (len1 - len2) - curpos - pmatch.rm_eo);
+ memmove(found + len1, found + len2, inlen - len1 - (found - haystack));
}
- memcpy(&haystack[curpos + pmatch.rm_so], needle2, len2);
-
- curpos += pmatch.rm_eo + len2;
+ memcpy(found, needle2, len2);
}
- regfree(&preg);
-
return haystack;
}