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-16 22:04:51 +0400
committerMiguel de Icaza <miguel@gnome.org>2006-10-16 22:04:51 +0400
commite1a5f1c90bef030574949e99aa82392df403ffd9 (patch)
tree7a2a04bb4f0e542b6e8bad544c49b32fe7662b5f /eglib
parent562125c3fcbf23d95e4b3130d27ed12528796153 (diff)
2006-10-16 Miguel de Icaza <miguel@novell.com>
* src/gerror.c (g_propagate_error): Implement. * src/gstr.c (g_strjoinv, g_ascii_strncasecmp): implement. * test/string-util.c (test_ascii_strncasecmp): test svn path=/trunk/mono/; revision=66728
Diffstat (limited to 'eglib')
-rw-r--r--eglib/ChangeLog8
-rw-r--r--eglib/TODO7
-rw-r--r--eglib/src/garray.c2
-rw-r--r--eglib/src/gerror.c11
-rw-r--r--eglib/src/glib.h10
-rw-r--r--eglib/src/gstr.c54
-rw-r--r--eglib/test/string-util.c24
7 files changed, 103 insertions, 13 deletions
diff --git a/eglib/ChangeLog b/eglib/ChangeLog
index df0fcccbc24..764183599b6 100644
--- a/eglib/ChangeLog
+++ b/eglib/ChangeLog
@@ -1,3 +1,11 @@
+2006-10-16 Miguel de Icaza <miguel@novell.com>
+
+ * src/gerror.c (g_propagate_error): Implement.
+
+ * src/gstr.c (g_strjoinv, g_ascii_strncasecmp): implement.
+
+ * test/string-util.c (test_ascii_strncasecmp): test
+
2006-10-15 Miguel de Icaza <miguel@novell.com>
* configure.in: Fix detection of platforms the [3456] stuff does
diff --git a/eglib/TODO b/eglib/TODO
index e7f94998a13..76ac0da7d53 100644
--- a/eglib/TODO
+++ b/eglib/TODO
@@ -4,13 +4,6 @@
3 g_shell_quote
1 g_shell_unquote
- * String
- g_ascii_strncasecmp
- g_strjoinv
-
- * Miscelaneous
- g_propagate_error
-
----------------------------------------------------------------------
* Should implement, for better performance:
diff --git a/eglib/src/garray.c b/eglib/src/garray.c
index 70b5bf0a54e..8844ee5db86 100644
--- a/eglib/src/garray.c
+++ b/eglib/src/garray.c
@@ -25,7 +25,7 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-
+
#define _GNU_SOURCE
#include <stdlib.h>
#include <glib.h>
diff --git a/eglib/src/gerror.c b/eglib/src/gerror.c
index 7f3a1f49ffa..28892525fe5 100644
--- a/eglib/src/gerror.c
+++ b/eglib/src/gerror.c
@@ -68,3 +68,14 @@ g_set_error (GError **err, gpointer domain, gint code, const gchar *format, ...)
va_end (args);
}
}
+
+void
+g_propagate_error (GError **dest, GError *src)
+{
+ if (dest == NULL){
+ if (src)
+ g_error_free (src);
+ } else {
+ *dest = src;
+ }
+}
diff --git a/eglib/src/glib.h b/eglib/src/glib.h
index aedf78923f4..1292e2d705c 100644
--- a/eglib/src/glib.h
+++ b/eglib/src/glib.h
@@ -212,11 +212,11 @@ gint g_snprintf (gchar *string, gulong n, gchar const *format, ..
gsize g_strlcpy (gchar *dest, const gchar *src, gsize dest_size);
#endif
-gchar *g_ascii_strdown (const gchar *str, gssize len);
-
-#define g_ascii_isspace(c) (isspace (c) != 0)
-#define g_ascii_isalpha(c) (isalpha (c) != 0)
-#define g_ascii_isprint(c) (isprint (c) != 0)
+gchar *g_ascii_strdown (const gchar *str, gssize len);
+gint g_ascii_strncasecmp (const gchar *s1, const gchar *s2, gsize n);
+#define g_ascii_isspace(c) (isspace (c) != 0)
+#define g_ascii_isalpha(c) (isalpha (c) != 0)
+#define g_ascii_isprint(c) (isprint (c) != 0)
#define g_ascii_isxdigit(c) (isxdigit (c) != 0)
#define g_ascii_xdigit_value(c) ((isxdigit (c) == 0) ? -1 : \
((c >= '0' && c <= '9') ? (c - '0') : \
diff --git a/eglib/src/gstr.c b/eglib/src/gstr.c
index 24d1e8eb590..e17af172c99 100644
--- a/eglib/src/gstr.c
+++ b/eglib/src/gstr.c
@@ -276,6 +276,37 @@ g_strjoin (const gchar *separator, ...)
}
gchar *
+g_strjoinv (const gchar *separator, gchar **str_array)
+{
+ char *res;
+ int slen, len, i;
+
+ if (separator != NULL)
+ slen = strlen (separator);
+ else
+ slen = 0;
+
+ len = 0;
+ for (i = 0; str_array [i] != NULL; i++){
+ len += strlen (str_array [i]);
+ len += slen;
+ }
+ if (len == 0)
+ return g_strdup ("");
+ if (slen > 0 && len > 0)
+ len -= slen;
+ len++;
+ res = g_malloc (len);
+ strcpy (res, str_array [0]);
+ for (i = 1; str_array [i] != NULL; i++){
+ if (separator != NULL)
+ strcat (res, separator);
+ strcat (res, str_array [i]);
+ }
+ return res;
+}
+
+gchar *
g_strchug (gchar *str)
{
gint len;
@@ -509,6 +540,29 @@ g_ascii_strdown (const gchar *str, gssize len)
return ret;
}
+gint
+g_ascii_strncasecmp (const gchar *s1, const gchar *s2, gsize n)
+{
+ int i;
+
+ g_return_val_if_fail (s1 != NULL, 0);
+ g_return_val_if_fail (s2 != NULL, 0);
+
+ for (i = 0; i < n; i++){
+ gchar c1 = *s1++;
+ gchar c2 = *s2++;
+
+ if (c1 == c2)
+ continue;
+
+ if (c1 == 0)
+ return -1;
+ if (c2 == 0)
+ return 1;
+ return c1-c2;
+ }
+ return 0;
+}
gchar *
g_strdelimit (gchar *string, const gchar *delimiters, gchar new_delimiter)
diff --git a/eglib/test/string-util.c b/eglib/test/string-util.c
index 6d27a0600cf..a720832e074 100644
--- a/eglib/test/string-util.c
+++ b/eglib/test/string-util.c
@@ -342,6 +342,29 @@ test_strescape ()
return OK;
}
+RESULT
+test_ascii_strncasecmp ()
+{
+ int n;
+
+ n = g_ascii_strncasecmp ("123", "123", 1);
+ if (n != 0)
+ return FAILED ("Should have been 0");
+
+ n = g_ascii_strncasecmp ("423", "123", 1);
+ if (n != 3)
+ return FAILED ("Should have been 3, got %d", n);
+
+ n = g_ascii_strncasecmp ("123", "423", 1);
+ if (n != -3)
+ return FAILED ("Should have been -3, got %d", n);
+
+ n = g_ascii_strncasecmp ("1", "1", 10);
+ if (n != 0)
+ return FAILED ("Should have been 0, got %d", n);
+ return OK;
+}
+
static Test strutil_tests [] = {
{"g_strfreev", test_strfreev},
{"g_strconcat", test_concat},
@@ -357,6 +380,7 @@ static Test strutil_tests [] = {
{"g_strdelimit", test_strdelimit},
{"g_strlcpy", test_strlcpy},
{"g_strescape", test_strescape},
+ {"g_ascii_strncasecmp", test_ascii_strncasecmp },
{NULL, NULL}
};