diff options
author | Tim Janik <timj@src.gnome.org> | 1997-12-23 02:09:34 +0000 |
---|---|---|
committer | Tim Janik <timj@src.gnome.org> | 1997-12-23 02:09:34 +0000 |
commit | e3956c289a602ddfed751ab781f436229462dd94 (patch) | |
tree | c849136dbdbc5e20bb30f329c92b486abe02cda4 /glib/gutils.c | |
parent | b44565f3e4730ada4d9d238707fc0d882d197092 (diff) | |
download | gtk+-e3956c289a602ddfed751ab781f436229462dd94.tar.gz |
new file for GScanner: Flexible lexical scanner for general purpose. added
* gscanner.c: new file for GScanner: Flexible lexical scanner for
general purpose.
* glib_pre2.h: added GScanner includes. added g_strconcat and g_strtod.
gutils.c (g_strconcat): new function for string concatenation of NULL
terminated parameter list.
(g_strtod): new function to perform best string to double conversion
with or without consideration of the current locale.
-timj
Diffstat (limited to 'glib/gutils.c')
-rw-r--r-- | glib/gutils.c | 85 |
1 files changed, 81 insertions, 4 deletions
diff --git a/glib/gutils.c b/glib/gutils.c index c153328176..b63a938969 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -8,7 +8,7 @@ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public @@ -17,7 +17,9 @@ */ #include <stdarg.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> +#include <locale.h> #include "glib.h" @@ -32,22 +34,97 @@ gchar* g_strdup (const gchar *str) { gchar *new_str; - + new_str = NULL; if (str) { new_str = g_new (char, strlen (str) + 1); strcpy (new_str, str); } - + return new_str; } gchar* +g_strconcat (const gchar *string1, ...) +{ + guint l; + va_list args; + gchar *s; + gchar *concat; + + g_return_val_if_fail (string1 != NULL, NULL); + + l = 1 + strlen (string1); + va_start (args, string1); + s = va_arg (args, gchar*); + while (s) + { + l += strlen (s); + s = va_arg (args, gchar*); + } + va_end (args); + + concat = g_new (gchar, l); + concat[0] = 0; + + strcat (concat, string1); + va_start (args, string1); + s = va_arg (args, gchar*); + while (s) + { + strcat (concat, s); + s = va_arg (args, gchar*); + } + va_end (args); + + return concat; +} + +gdouble +g_strtod (const gchar *nptr, + gchar **endptr) +{ + gchar *fail_pos_1; + gchar *fail_pos_2; + gdouble val_1; + gdouble val_2 = 0; + + g_return_val_if_fail (nptr != NULL, 0); + + fail_pos_1 = NULL; + fail_pos_2 = NULL; + + val_1 = strtod (nptr, &fail_pos_1); + + if (fail_pos_1 && fail_pos_1[0] != 0) + { + gchar *old_locale; + + old_locale = setlocale (LC_NUMERIC, "C"); + val_2 = strtod (nptr, &fail_pos_2); + setlocale (LC_NUMERIC, old_locale); + } + + if (!fail_pos_1 || fail_pos_1[0] == 0 || fail_pos_1 >= fail_pos_2) + { + if (endptr) + *endptr = fail_pos_1; + return val_1; + } + else + { + if (endptr) + *endptr = fail_pos_2; + return val_2; + } +} + +gchar* g_strerror (gint errnum) { static char msg[64]; - + #ifdef HAVE_STRERROR return strerror (errnum); #elif NO_SYS_ERRLIST |