Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/eglib
diff options
context:
space:
mode:
authorMiguel de Icaza <miguel@gnome.org>2006-10-22 01:13:42 +0400
committerMiguel de Icaza <miguel@gnome.org>2006-10-22 01:13:42 +0400
commit03be2afdc4ecc5d681ae2d73845f74c11196fdf2 (patch)
treee20068098650d4e65d3b5e28774914a338bf4fec /eglib
parent63ed6374457ff54aa15bc0b8306f8f04f31658e8 (diff)
2006-10-21 Miguel de Icaza <miguel@novell.com>
* src/gstr.c (g_strsplit): this routine has some non-expected behavior, if the string begins with the delimiter, it will return an empty first string, unlike strtok * src/gpath.c (g_path_get_dirname): Return "." as a dirname for paths that do not contain a directory. svn path=/trunk/mono/; revision=66859
Diffstat (limited to 'eglib')
-rw-r--r--eglib/ChangeLog9
-rw-r--r--eglib/src/gpath.c2
-rw-r--r--eglib/src/gstr.c51
-rw-r--r--eglib/test/path.c5
-rw-r--r--eglib/test/string-util.c6
5 files changed, 49 insertions, 24 deletions
diff --git a/eglib/ChangeLog b/eglib/ChangeLog
index 98888e85571..f3cce8fb37a 100644
--- a/eglib/ChangeLog
+++ b/eglib/ChangeLog
@@ -1,3 +1,12 @@
+2006-10-21 Miguel de Icaza <miguel@novell.com>
+
+ * src/gstr.c (g_strsplit): this routine has some non-expected
+ behavior, if the string begins with the delimiter, it will return
+ an empty first string, unlike strtok
+
+ * src/gpath.c (g_path_get_dirname): Return "." as a dirname for
+ paths that do not contain a directory.
+
2006-10-18 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* test/array.c: new test for insertion in the middle of other values.
diff --git a/eglib/src/gpath.c b/eglib/src/gpath.c
index 84f7cd3ab0f..572c975108c 100644
--- a/eglib/src/gpath.c
+++ b/eglib/src/gpath.c
@@ -82,7 +82,7 @@ g_path_get_dirname (const gchar *filename)
p = strrchr (filename, G_DIR_SEPARATOR);
if (p == NULL)
- return g_strdup ("");
+ return g_strdup (".");
count = p - filename;
r = g_malloc (count + 1);
strncpy (r, filename, count);
diff --git a/eglib/src/gstr.c b/eglib/src/gstr.c
index 68bc3c520c0..5947afd68a2 100644
--- a/eglib/src/gstr.c
+++ b/eglib/src/gstr.c
@@ -176,34 +176,41 @@ g_strsplit (const gchar *string, const gchar *delimiter, gint max_tokens)
string_c = (gchar *)g_malloc(token_length + 1);
memcpy(string_c, string, token_length);
string_c[token_length] = 0;
-
- vector = NULL;
- token = (gchar *)strtok_r(string_c, delimiter, &strtok_save);
-
- while(token != NULL) {
- token_length = strlen(token);
- token_c = (gchar *)g_malloc(token_length + 1);
- memcpy(token_c, token, token_length);
- token_c[token_length] = 0;
- vector = vector == NULL ?
- (gchar **)g_malloc(2 * sizeof(vector)) :
- (gchar **)g_realloc(vector, (size + 1) * sizeof(vector));
-
- vector[size - 1] = token_c;
+ if (strncmp (string_c, delimiter, strlen (delimiter)) == 0){
+ vector = (gchar **) g_malloc (2 * sizeof (vector));
+ vector [0] = g_strdup ("");
size++;
+ } else
+ vector = NULL;
+ token = (gchar *)strtok_r(string_c, delimiter, &strtok_save);
- if(max_tokens > 0 && size >= max_tokens) {
- if(size > max_tokens) {
- break;
+ if (!(max_tokens > 0 && size >= max_tokens)){
+ while(token != NULL) {
+ token_length = strlen(token);
+ token_c = (gchar *)g_malloc(token_length + 1);
+ memcpy(token_c, token, token_length);
+ token_c[token_length] = 0;
+
+ vector = vector == NULL ?
+ (gchar **)g_malloc(2 * sizeof(vector)) :
+ (gchar **)g_realloc(vector, (size + 1) * sizeof(vector));
+
+ vector[size - 1] = token_c;
+ size++;
+
+ if(max_tokens > 0 && size >= max_tokens) {
+ if(size > max_tokens) {
+ break;
+ }
+
+ token = strtok_save;
+ } else {
+ token = (gchar *)strtok_r(NULL, delimiter, &strtok_save);
}
-
- token = strtok_save;
- } else {
- token = (gchar *)strtok_r(NULL, delimiter, &strtok_save);
}
}
-
+
if (vector == NULL){
vector = (gchar **) g_malloc (2 * sizeof (vector));
vector [0] = NULL;
diff --git a/eglib/test/path.c b/eglib/test/path.c
index 58c889d0cbb..b9e360462e3 100644
--- a/eglib/test/path.c
+++ b/eglib/test/path.c
@@ -114,7 +114,10 @@ test_dirname ()
if (strcmp (s, "/home/dingus") != 0)
return FAILED ("Expected /home/dingus, got %s", s);
g_free (s);
-
+
+ s = g_path_get_dirname ("dir.c");
+ if (strcmp (s, ".") != 0)
+ return FAILED ("Expected `.', got %s", s);
return OK;
}
diff --git a/eglib/test/string-util.c b/eglib/test/string-util.c
index aa39a9c9042..4e55c60ad06 100644
--- a/eglib/test/string-util.c
+++ b/eglib/test/string-util.c
@@ -69,6 +69,12 @@ test_split ()
if (v == NULL)
return FAILED ("g_strsplit returned NULL");
g_strfreev (v);
+
+ v = g_strsplit ("/home/miguel/dingus", "/", 0);
+ if (v [0][0] != 0)
+ return FAILED ("Got a non-empty first element");
+ g_strfreev (v);
+
return OK;
}