diff options
author | Andy Wingo <wingo@pobox.com> | 2011-01-05 18:21:54 -0600 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2011-01-07 09:18:36 -0800 |
commit | d40e1ca893149e9781bad54ac1e39d03e7be988f (patch) | |
tree | 65d09a9a0a194ee7dad0275c11f93cf8836d9457 /libguile/stime.c | |
parent | 929ccf48fc4bada585b29b3887f295bfcc1dcdaa (diff) | |
download | guile-d40e1ca893149e9781bad54ac1e39d03e7be988f.tar.gz |
add scm_{to,from}_{utf8,latin1}_string{n,}
* libguile/strings.h:
* libguile/strings.c (scm_from_latin1_string, scm_to_latin1_string): New
functions, in terms of the latin1_stringn variants.
(scm_from_utf8_string, scm_from_utf8_stringn)
(scm_to_utf8_string, scm_to_utf8_stringn): New functions.
(scm_i_from_utf8_string, scm_i_to_utf8_string): Removed these internal
functions.
(scm_from_stringn): Handle -1 as a length. Unlike the previous
behavior of scm_from_locale_string (NULL), which returned the empty
string, we now raise an error. The null pointer is not the same as
the empty string.
* libguile/stime.c (scm_strftime, scm_strptime): Adapt to publishing of
utf8 functions.
Diffstat (limited to 'libguile/stime.c')
-rw-r--r-- | libguile/stime.c | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/libguile/stime.c b/libguile/stime.c index 07dedf3b3..78aa6731a 100644 --- a/libguile/stime.c +++ b/libguile/stime.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. +/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -625,11 +625,11 @@ SCM_DEFINE (scm_strftime, "strftime", 2, 0, 0, { struct tm t; - scm_t_uint8 *tbuf; + char *tbuf; int size = 50; - scm_t_uint8 *fmt; - scm_t_uint8 *myfmt; - int len; + char *fmt; + char *myfmt; + size_t len; SCM result; SCM_VALIDATE_STRING (1, format); @@ -637,8 +637,7 @@ SCM_DEFINE (scm_strftime, "strftime", 2, 0, 0, /* Convert string to UTF-8 so that non-ASCII characters in the format are passed through unchanged. */ - fmt = scm_i_to_utf8_string (format); - len = strlen ((const char *) fmt); + fmt = scm_to_utf8_stringn (format, &len); /* Ugly hack: strftime can return 0 if its buffer is too small, but some valid time strings (e.g. "%p") can sometimes produce @@ -647,7 +646,7 @@ SCM_DEFINE (scm_strftime, "strftime", 2, 0, 0, nonzero. */ myfmt = scm_malloc (len+2); *myfmt = (scm_t_uint8) 'x'; - strncpy ((char *) myfmt + 1, (const char *) fmt, len); + strncpy (myfmt + 1, fmt, len); myfmt[len + 1] = 0; scm_remember_upto_here_1 (format); free (fmt); @@ -685,8 +684,7 @@ SCM_DEFINE (scm_strftime, "strftime", 2, 0, 0, /* Use `nstrftime ()' from Gnulib, which supports all GNU extensions supported by glibc. */ - while ((len = nstrftime ((char *) tbuf, size, - (const char *) myfmt, &t, 0, 0)) == 0) + while ((len = nstrftime (tbuf, size, myfmt, &t, 0, 0)) == 0) { free (tbuf); size *= 2; @@ -702,7 +700,7 @@ SCM_DEFINE (scm_strftime, "strftime", 2, 0, 0, #endif } - result = scm_i_from_utf8_string ((const scm_t_uint8 *) tbuf + 1); + result = scm_from_utf8_string (tbuf + 1); free (tbuf); free (myfmt); #if HAVE_STRUCT_TM_TM_ZONE @@ -728,7 +726,7 @@ SCM_DEFINE (scm_strptime, "strptime", 2, 0, 0, #define FUNC_NAME s_scm_strptime { struct tm t; - scm_t_uint8 *fmt, *str, *rest; + char *fmt, *str, *rest; size_t used_len; long zoff; @@ -737,8 +735,8 @@ SCM_DEFINE (scm_strptime, "strptime", 2, 0, 0, /* Convert strings to UTF-8 so that non-ASCII characters are passed through unchanged. */ - fmt = scm_i_to_utf8_string (format); - str = scm_i_to_utf8_string (string); + fmt = scm_to_utf8_string (format); + str = scm_to_utf8_string (string); /* initialize the struct tm */ #define tm_init(field) t.field = 0 @@ -760,8 +758,7 @@ SCM_DEFINE (scm_strptime, "strptime", 2, 0, 0, fields, hence the use of SCM_CRITICAL_SECTION_START. */ t.tm_isdst = -1; SCM_CRITICAL_SECTION_START; - rest = (scm_t_uint8 *) strptime ((const char *) str, - (const char *) fmt, &t); + rest = strptime (str, fmt, &t); SCM_CRITICAL_SECTION_END; if (rest == NULL) { @@ -784,7 +781,7 @@ SCM_DEFINE (scm_strptime, "strptime", 2, 0, 0, #endif /* Compute the number of UTF-8 characters. */ - used_len = u8_strnlen (str, rest-str); + used_len = u8_strnlen ((scm_t_uint8*) str, rest-str); scm_remember_upto_here_2 (format, string); free (str); free (fmt); |