summaryrefslogtreecommitdiff
path: root/src/common/extstr.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2009-04-25 16:51:41 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2009-04-25 16:51:41 (GMT)
commitb9977e00ff9eb6e025e86a15c858183f3f314cf5 (patch)
treeeedacb236b90228d2b4c603fa9875ecaad05ee29 /src/common/extstr.c
parent216a3d0121fabd678e50ea6b4fa2447ae9b921f0 (diff)
Saved the current work on plugins.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@59 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/common/extstr.c')
-rw-r--r--src/common/extstr.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/common/extstr.c b/src/common/extstr.c
index aba9830..deffbd4 100644
--- a/src/common/extstr.c
+++ b/src/common/extstr.c
@@ -25,6 +25,7 @@
#include <malloc.h>
+#include <regex.h>
#include <string.h>
@@ -83,3 +84,57 @@ char *strprep(char *str1, const char *str2)
return result;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : input = chaîne de caractères à traiter. *
+* *
+* Description : S'assure qu'une chaîne de caractère tient sur une ligne. *
+* *
+* Retour : Adresse de la chaîne de caractères modifiée. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+char *escape_crlf(char *input)
+{
+ size_t inlen;
+ regex_t preg;
+ int ret;
+ size_t curpos;
+ regmatch_t pmatch[2];
+
+ inlen = strlen(input);
+
+ ret = regcomp(&preg, "(\t|\n|\r)", REG_EXTENDED | REG_ICASE);
+ /* TODO: ret */
+
+ for (curpos = 0; regexec(&preg, &input[curpos], 2, pmatch, 0) != REG_NOMATCH; )
+ {
+ inlen += 1 + 1;
+ input = (char *)realloc(input, inlen * sizeof(char *));
+
+ memmove(&input[curpos + pmatch[1].rm_eo + 1], &input[curpos + pmatch[1].rm_eo], inlen - 1 - curpos - pmatch[1].rm_eo);
+
+ switch (input[curpos + pmatch[1].rm_so])
+ {
+ case '\t':
+ memcpy(&input[curpos + pmatch[1].rm_so], "\\t", 2);
+ break;
+ case '\n':
+ memcpy(&input[curpos + pmatch[1].rm_so], "\\n", 2);
+ break;
+ case '\r':
+ memcpy(&input[curpos + pmatch[1].rm_so], "\\r", 2);
+ break;
+ }
+
+ curpos += pmatch[1].rm_eo + 1;
+
+ }
+
+ return input;
+
+}