projects
/
silc.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added SILC regular expression API. Added new regex error values.
[silc.git]
/
lib
/
silcutil
/
silcstrutil.c
diff --git
a/lib/silcutil/silcstrutil.c
b/lib/silcutil/silcstrutil.c
index 1655f213459470ab4a4765d0d55a12b9ba7c9440..914adc98f58659a7cc739afed2a19dbec508827e 100644
(file)
--- a/
lib/silcutil/silcstrutil.c
+++ b/
lib/silcutil/silcstrutil.c
@@
-121,7
+121,7
@@
int silc_string_compare(char *string1, char *string2)
char **silc_string_split(const char *string, char ch, int *ret_count)
{
char **silc_string_split(const char *string, char ch, int *ret_count)
{
- char **splitted = NULL, sep[
1
], *item, *cp;
+ char **splitted = NULL, sep[
2
], *item, *cp;
int i = 0, len;
if (!string || !ret_count) {
int i = 0, len;
if (!string || !ret_count) {
@@
-140,9
+140,13
@@
char **silc_string_split(const char *string, char ch, int *ret_count)
}
sep[0] = ch;
}
sep[0] = ch;
+ sep[1] = '\0';
cp = (char *)string;
cp = (char *)string;
- while(cp) {
+ while
(cp) {
len = strcspn(cp, sep);
len = strcspn(cp, sep);
+ if (!len)
+ break;
+
item = silc_memdup(cp, len);
if (!item) {
silc_free(splitted);
item = silc_memdup(cp, len);
if (!item) {
silc_free(splitted);
@@
-155,10
+159,13
@@
char **silc_string_split(const char *string, char ch, int *ret_count)
else
cp++;
else
cp++;
- splitted = silc_realloc(splitted, (i + 1) * sizeof(*splitted));
- if (!splitted)
- return NULL;
splitted[i++] = item;
splitted[i++] = item;
+
+ if (cp) {
+ splitted = silc_realloc(splitted, (i + 1) * sizeof(*splitted));
+ if (!splitted)
+ return NULL;
+ }
}
*ret_count = i;
}
*ret_count = i;
@@
-246,18
+253,15
@@
char *silc_string_regex_combine(const char *string1, const char *string2)
int silc_string_regex_match(const char *regex, const char *string)
{
int silc_string_regex_match(const char *regex, const char *string)
{
-
regex_
t preg;
-
int ret = FALSE
;
+
SilcRegexStruc
t preg;
+
SilcBool ret
;
- if (regcomp(&preg, regex, REG_NOSUB | REG_EXTENDED) != 0) {
- silc_set_errno(SILC_ERR_INVALID_ARGUMENT);
+ if (!silc_regex_compile(&preg, regex, 0))
return FALSE;
return FALSE;
- }
- if (regexec(&preg, string, 0, NULL, 0) == 0)
- ret = TRUE;
+ ret = silc_regex_match(&preg, string, 0, NULL, 0);
-
reg
free(&preg);
+
silc_regex_
free(&preg);
return ret;
}
return ret;
}