summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Sadoine <chris@indefini.org>2013-06-25 12:26:20 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-06-25 12:29:37 +0900
commit2070ca420501b691d8420dbc5f5e705bda8cf498 (patch)
treed828f9ec8d024278438452588c89d4531b511296
parentd9e1b7d67cb278b5ad78128f15ba36f77b04756b (diff)
evil: add strsep function.
Signed-off-by: Cedric Bail <cedric.bail@samsung.com>
-rw-r--r--ChangeLog4
-rw-r--r--NEWS1
-rw-r--r--src/lib/evil/evil_string.c45
-rw-r--r--src/lib/evil/evil_string.h26
4 files changed, 73 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 9d02b31f83..38c2abe92f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,10 @@
6 6
7 * Edje: Move cursor to correct position when selection handlers are pressed. 7 * Edje: Move cursor to correct position when selection handlers are pressed.
8 8
92013-06-20 Christophe Sadoine
10
11 * Evil: Added strsep function.
12
92013-06-19 Cedric Bail 132013-06-19 Cedric Bail
10 14
11 * Evas: optimized path for when map use the same color for all corner. 15 * Evas: optimized path for when map use the same color for all corner.
diff --git a/NEWS b/NEWS
index be1b545a1a..228e5277e5 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ Additions:
10 * Evil: 10 * Evil:
11 - Add mkdtemp. 11 - Add mkdtemp.
12 - Add evil_rename() a wrapper for rename(). 12 - Add evil_rename() a wrapper for rename().
13 - Add strsep().
13 * eina: 14 * eina:
14 - Add DOCTYPE children parsing in eina_simple_xml 15 - Add DOCTYPE children parsing in eina_simple_xml
15 - Add eina_barrier thread API 16 - Add eina_barrier thread API
diff --git a/src/lib/evil/evil_string.c b/src/lib/evil/evil_string.c
index 491a880e1a..c6d017aa4f 100644
--- a/src/lib/evil/evil_string.c
+++ b/src/lib/evil/evil_string.c
@@ -127,3 +127,48 @@ char *strcasestr(const char *haystack, const char *needle)
127 127
128 return NULL; 128 return NULL;
129} 129}
130
131char *
132strsep (char **stringp, const char *delim)
133{
134 char *begin, *end;
135
136 begin = *stringp;
137 if (begin == NULL)
138 return NULL;
139
140 /* A frequent case is when the delimiter string contains only one
141 character. Here we don't need to call the expensive `strpbrk'
142 function and instead work using `strchr'. */
143 if (delim[0] == '\0' || delim[1] == '\0')
144 {
145 char ch = delim[0];
146
147 if (ch == '\0')
148 end = NULL;
149 else
150 {
151 if (*begin == ch)
152 end = begin;
153 else if (*begin == '\0')
154 end = NULL;
155 else
156 end = strchr (begin + 1, ch);
157 }
158 }
159 else
160 /* Find the end of the token. */
161 end = strpbrk (begin, delim);
162
163 if (end)
164 {
165 /* Terminate the token and set *STRINGP past NUL character. */
166 *end++ = '\0';
167 *stringp = end;
168 }
169 else
170 /* No more delimiters; this is the last token. */
171 *stringp = NULL;
172
173 return begin;
174}
diff --git a/src/lib/evil/evil_string.h b/src/lib/evil/evil_string.h
index 45c9de3638..14f49b1c94 100644
--- a/src/lib/evil/evil_string.h
+++ b/src/lib/evil/evil_string.h
@@ -144,10 +144,30 @@ EAPI int strcasecmp(const char *s1, const char *s2);
144 */ 144 */
145EAPI char *strcasestr(const char *haystack, const char *needle); 145EAPI char *strcasestr(const char *haystack, const char *needle);
146 146
147
148/** 147/**
149 * @} 148 * @brief Implements the strsep function which is used to separate strings.
150 */ 149 *
150 * @param stringp The pointer to the string to search in.
151 * @param delim The delimiter that contains characters used to find the next token.
152 * @return a pointer to the next token or NULL;
153 *
154 * The strsep() function locates, in the string referenced by *stringp, the
155 * first occurrence of any character in the string delim (or the terminating
156 * `\0' character) and replaces it with a `\0'. The location of the next
157 * character after the delimiter character (or NULL, if the end of the
158 * string was reached) is stored in *stringp. The original value of
159 * stringp is returned.
160 *
161 * An ``empty'' field (i.e., a character in the string delim occurs as the
162 * first character of *stringp) can be detected by comparing the location
163 * referenced by the returned pointer to `\0'.
151 164
165 * If *stringp is initially NULL, strsep() returns NULL.
166 *
167 * This function is from LibGW32C.
168 * @since 1.8
169 *
170 */
171EAPI char *strsep(char **stringp, const char *delim);
152 172
153#endif /* __EVIL_STRING_H__ */ 173#endif /* __EVIL_STRING_H__ */